How to migrate my swift 1.2 project into 2.0?
I have a project developed when swift was introduced but recently Apple has new version of swift 2.0 with xCode 7.0. So how can i migrate my project from swift 1.2 to 2.0?
- How to submit an app to the Apple App Store from Windows
- How can I move files & folders using git in Xcode 4?
- Create tap-able “links” in the NSAttributedString of a UILabel?
- Highlight active link in SWRevealViewController
- Xcode and optional frameworks
Solutions Collect From Internet About “How to migrate my swift 1.2 project into 2.0?”
In the new Xcode 7 beta go to the Edit menu -> Convert -> To Latest Swift Syntax
This will run the code converter for you and show you the changes it is going to make. These are automatic changes (like changing println to print and so on).
Then to refactor the code to make it more Swift-like here are some tips:
Ensure you are using the new error handling functionality wherever possible (the code conversion tool does this for the most part but sometimes it gets it wrong).
Use guard statements where appropriate. In general use it to reduce indentation and nested if statements. These are really nice when used properly.
Almost all your global functions can be refactored into protocol extensions. Move generic functions to extensions.
When converting to/from a type (for instance String -> NSData and vice versa) use failable initializers with the parameter as the type to convert from instead of having properties on the type. So instead of doing
someString.dataUsingEncoding(NSUTF8StringEncoding)do something like
NSData(someString, encoding: NSUTF8StringEncoding). Note this is not how the API is implemented but I used it as an example to show how things can be more “Swifty”.
Use availability checking where useful.
- Move clean up code to defer blocks as much as possible. This can help redundant duplicated clean up code like file closing, etc.
- Initialize Array of Objects using NSArray
- Remove or override the “Clear Button” on UISearchDisplayController in a UIPopoverController on iPad?
- Add NSUnderlineStyle.PatternDash to NSAttributedString in Swift?
- Unable to trust a self signed certificate on iphone
- Detect Silent mode in iOS5?
- Get position of UIView in respect to its superview's superview
- Are values stored in NSUserDefaults removed when the app that put them there is uninstalled?
- Tap Gesture with UIGestureRecognizerState not working
- How to insert a override function into a if else statement
- Saving array using NSUserDefaults crashes app
- Generating non-repeating random numbers
- Exporting customized UITableViewCells into UIImage
- Conditionally build app with different asset catalogs
- Detecting tapped character. UITextView characterRangeAtPoint always returns nil
- Open AppStore through button