swift2

Localization in Swift 2

China☆狼群 提交于 2019-12-30 08:14:38
问题 I want to localize my application; I am using Swift 2. I followed this tutorial but I experience 2 issues. 1. Localized image disappears for both languages I localized multiple images the same way for German and English . One set of images (the en and de versions of an image) disappear for both languages. I added them, they are in the project's folder and I can not spot any difference to other images I localized. I tried cleaning and running the project ( no errors ) removed the images and

Localization in Swift 2

霸气de小男生 提交于 2019-12-30 08:14:09
问题 I want to localize my application; I am using Swift 2. I followed this tutorial but I experience 2 issues. 1. Localized image disappears for both languages I localized multiple images the same way for German and English . One set of images (the en and de versions of an image) disappear for both languages. I added them, they are in the project's folder and I can not spot any difference to other images I localized. I tried cleaning and running the project ( no errors ) removed the images and

How to convert CLLocation to string in Xcode

不想你离开。 提交于 2019-12-30 07:33:08
问题 I use SwiftLocation for get coordinates: try! SwiftLocation.shared.currentLocation(Accuracy.House, timeout: 20, onSuccess: { (location) -> Void in print(location?.description) }) { (error) -> Void in print("something went wrong") } In location?.description I get it: <+37.78583400,-122.40641700> +/- 5.00m (speed -1.00 mps / course -1.00) @ 2/22/16, 6:35:55 PM Indochina Time And I need to take just coordinates. So I make loop for it: while name.characters.last != ">" { // delete all after ">"

How to detect all touches in Swift 2

橙三吉。 提交于 2019-12-30 06:44:07
问题 I'm trying to create a timeout function for an app I'm develop using Swift 2 but in swift 2, you can put this code in the app delegate and it works but it does not detect any keyboard presses, button presses, textfield presses, and etc: override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { super.touchesBegan(touches, withEvent: event); let allTouches = event!.allTouches(); if(allTouches?.count > 0) { let phase = (allTouches!.first as UITouch!).phase; if(phase ==

Swift 2.0 Format 1000's into a friendly K's

血红的双手。 提交于 2019-12-30 05:59:26
问题 I'm trying to write a function to present thousands and millions into K's and M's For instance: 1000 = 1k 1100 = 1.1k 15000 = 15k 115000 = 115k 1000000 = 1m Here is where I got so far: func formatPoints(num: Int) -> String { let newNum = String(num / 1000) var newNumString = "\(num)" if num > 1000 && num < 1000000 { newNumString = "\(newNum)k" } else if num > 1000000 { newNumString = "\(newNum)m" } return newNumString } formatPoints(51100) // THIS RETURNS 51K instead of 51.1K How do I get

Swift 2.0 Format 1000's into a friendly K's

断了今生、忘了曾经 提交于 2019-12-30 05:58:02
问题 I'm trying to write a function to present thousands and millions into K's and M's For instance: 1000 = 1k 1100 = 1.1k 15000 = 15k 115000 = 115k 1000000 = 1m Here is where I got so far: func formatPoints(num: Int) -> String { let newNum = String(num / 1000) var newNumString = "\(num)" if num > 1000 && num < 1000000 { newNumString = "\(newNum)k" } else if num > 1000000 { newNumString = "\(newNum)m" } return newNumString } formatPoints(51100) // THIS RETURNS 51K instead of 51.1K How do I get

Xcode 8 and Swift 3 NSCalendar

徘徊边缘 提交于 2019-12-30 05:46:10
问题 I implemented my watch project in Swift and now I am migrating to Swift 3 because of Xcode 8. I let Xcode 8 change the source code to Swift 3. However, there are errors in the code and I can not figure it out. let unitFlags: Calendar = [.hour, .firstWeekday, .monthSymbols, .year, .minute, .firstWeekday] var calendar = NSCalendar.current calendar.timeZone = NSTimeZone(identifier: "UTC")! let components = (calendar as NSCalendar).components(unitFlags, from: reservationDate) Xcode gives error in

Convert String Array into Int Array Swift 2?

試著忘記壹切 提交于 2019-12-30 03:50:06
问题 [Xcode 7.1, iOS 9.1] I have an array: var array: [String] = ["11", "43", "26", "11", "45", "40"] I want to convert that (each index) into an Int so I can use it to countdown from a timer, respective of the index. How can I convert a String array into an Int Array in Swift 2? I've tried several links, none have worked and all of them have given me an error. Most of the code from the links is depreciated or hasn't been updated to swift 2, such as the toInt() method. 回答1: Use the map function

Select/deselect buttons swift xcode 7

我们两清 提交于 2019-12-30 02:28:12
问题 Part way done with learning swift but I hit a small wall and yet again, I'm sure I'm just a bit new at this and an easy solution is there but I'm having trouble figuring out how to select/deselect buttons below is what I have so far and it is a button turns into a checkmark when clicked on... I've gotten that far but I need that button to deselect when clicked on again and then obviously be able to be clicked again if need be. @IBAction func buttonPressed(sender: AnyObject) { sender.setImage

how to return value after the execution of the block? Swift

对着背影说爱祢 提交于 2019-12-29 09:14:10
问题 I want to get a value from function. There is a block in function. When block executes the function already returns the value. I tried many different methods but they didn't help me. I used NSOperation and Dispatch. The function always returns value until execution of block. var superPlace: MKPlacemark! func returnPlaceMarkInfo(coordinate: CLLocationCoordinate2D) -> MKPlacemark? { let location = CLLocation(latitude: coordinate.latitude, longitude: coordinate.longitude) geocoder