swift2

Code migration from Swift 2.x to Swift 4

只愿长相守 提交于 2019-12-20 09:50:53
问题 We have big enough project which is built up with Swift 2.x and now Apple has just released Swift 4 so to move forward for latest version of Swift which path we can choose... Do we need to migrate our code to Swift 3 first? Or we can directly migrate our code to Swift 4 using Xcode 9? 回答1: Yes, you must migrate your code in Swift 3 compatible version. Xcode 9 allows conversion/migration from swift 3.0 only. Swift 3.2 is supported by Xcode 9 & Xcode 8 both. Convert your source code from Swift

Nil is not compatible with expected argument type UIViewAnimationOptions

左心房为你撑大大i 提交于 2019-12-20 09:46:32
问题 I just started programming and following a tutorial online I was unable to create this animation. Can anyone tell me why it's saying: Nil is not compatible with expected argument type UIViewAnimationOptions and how to fix it? view.addSubview(myFirstLabel) UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.0, initialSpringVelocity: 0.0, options: nil, animations: { self.myFirstLabel.center = CGPoint(x: 100, y:40 + 200) }, completion: nil) 回答1: You may replace options: nil

Date/Time Natural Language Approximation in Swift

╄→гoц情女王★ 提交于 2019-12-20 09:04:12
问题 I am attempting to convert a UTC formatted date from an API to a human-readable approximation format using Swift. I'm looking for something like the following: 2015-07-14T13:51:05.423Z to About two weeks ago What is the best approach to this in Swift? While optimally this could format strings directly, I understand that this will probably require casting the string to a NSDate object. Any help would be greatly appreciated. EDIT: My question had been identified as a possible duplicate of

Unable to remove “Optional” from String

六眼飞鱼酱① 提交于 2019-12-20 07:43:07
问题 Below is my snippet // MARK: - Location Functions func getCurrentLocation() -> (String!, String!) { let location = LocationManager.sharedInstance.currentLocation?.coordinate return (String(location?.latitude), String(location?.longitude)) } func setCurrentLocation() { let (latitude, longitude) = getCurrentLocation() let location = "\(latitude!),\(longitude!)" print(location) } Though I unwrap optional using latitude! and longitude! , it prints me Optional(37.33233141),Optional(-122.0312186) I

Why does Swift 2 favor forced unwrap over optionals?

南笙酒味 提交于 2019-12-20 06:38:12
问题 I no longer see Xcode complaining that certain things need optionals (the "?"). Now it is always forced unwrapped (the bang "!"). Is there any reason to use optionals anymore when we now have forced unwrap? 回答1: I don't really know what you mean when you write that you no longer see Xcode complaining that "certain things need optionals. Now it is always forced unwrapped" . These two sentences contradict eachother: You may have non-optional variables as much as you wish, but optional can

Firebase/Swift 2 - How to get an authenticated users password and email

给你一囗甜甜゛ 提交于 2019-12-20 06:37:03
问题 I'm trying to setup a password reset within an app using swift 2 and Firebase. Following Firebases example: let ref = Firebase(url: "https://<YOUR-FIREBASE-APP>.firebaseio.com") ref.changePasswordForUser("bobtony@example.com", fromOld: "correcthorsebatterystaple", toNew: "batteryhorsestaplecorrect", withCompletionBlock: { error in if error != nil { // There was an error processing the request } else { // Password changed successfully } }) How can I access an authenticated users email &

Display data in two different TableView in the same View in Swift

半世苍凉 提交于 2019-12-20 06:32:50
问题 I'm creating an app for iPad, and because of their size decided to do something a little different. I'm creating something like this: I am using two UITableView in a UIView. I need to display data 'product categories' in the first TableView and 'products' in the second TableView. The problem is display data in two tables with direferentes contents. Another detail: When a category is selected, the table 'product' is recharged with other data of other products. My question is: How can I display

Swift 2 - Search in string and sum the numbers

霸气de小男生 提交于 2019-12-20 05:43:05
问题 My old code was: let comps = split(str, { $0 == "-" || $0 == " " }, maxSplit: Int.max, allowEmptySlices: false) after update of Swift 2 my XCode 7 fix it to: let comps = split(str.characters, { $0 == "-" || $0 == " " }, maxSplit: Int.max, allowEmptySlices: false).map { String($0) } but now I have an error: Cannot invoke 'map' with an argument list of type '((_) -> _)' How to fix it. Link to old answer on Swift 回答1: The order of arguments for split() function messed up for some reason. It

calling a function defined in assembly from swift

非 Y 不嫁゛ 提交于 2019-12-20 05:15:41
问题 I know in swift it is possible to interop with c using the @_silgen_name attr on a function in a swift module. Is there a way to do this with a symbol defined in an assembly file? I would like to make syscalls using Swift. This is why I'm asking. 回答1: Create the bridge header.h file and put the prototype of the function in that file. For example your assembly code: .globl _add // make it global so that others can find this symbol .... _add: // int add(int a, int b) movl %esi, %eax addl %edi,

unwind segue vs. popViewControllerAnimated

随声附和 提交于 2019-12-20 04:06:22
问题 I have a mapview that is connected to several viewControllers. I needed to implement an 'unwind' from another button (as opposed to just the back button), so I used: self.navigationController?.popViewControllerAnimated(true) My question is: as the above works, should I even bother trying to implement unwind in code using prepareForUnwind and canPerformUnwindSegueAction in the parent view controller + ctrl-drag from the viewController to exit in Storyboard? If so, why? 回答1: Basically if you