Swift1.2 and Xcode6.3 beta, swift1.2xcode6.3
Both Xcode6.3 and Swift1.2 have been released. This release enhanced the Swift compiler and added some new features to Swift. For more information, see here. Here we mainly focus on important content.
Compiler Improvement
Swift1.2's compiler is more stable and performance has been improved in all aspects. These improvements make Swift development experience better. Some visible updates include:
- Incremental compilation-Files without modification will not be compiled by default. This greatly increases the Compilation Time. A wide range of code adjustments will still cause multi-file re-compilation.
- Faster executable files-The binary file generated in debug mode will significantly increase the running speed. The new optimization will also improve the performance of binary files generated in the release mode.
- Better compilation and Diagnosis-Better error and warning information and better "fix-it" prompts. These will help you write better Swift1.2 code.
- More stable-Common compiler crashes have been fixed. You will not often see the SourceKit warning.
New language features
Swift1.2 provides better security and foreseeable behavior. Swift and Objective-C interactions are also improved. The main improvements are as follows:
- As! Type conversion character-Type conversion may fail at runtime. Use as now! Operator, so that the reader or code maintainer can better understand the potential conversion failure during runtime.
Objective-C added a void flag-The new Objective-C mark allows you to mark the pointer or block in the header file as null. When you use both OC and Swift, you can write better OC Code integrated with Swift. For example:
-(void)registerNib:(nonnull UINib *)nib forCellReuseIdentifier:(nonnull NSString *)identifier;-(nullable UITableViewCell *)cellForRowAtIndexPath:(nonnull NSIndexPath)indexPath;@property (nonatomic, readwrite, retain, nullable) UIView *backgroundView;
In Swift, it will become:
func registerNib(nib: UINib, forCellReuseIdentifier identifier: String)func cellForRowAtIndexPath(indexPath: NSIndexPath) -> UITableViewCell?var backgroundView: UIView?
PreviouslyImplicitly-unwrapped optionals implicit parsing optional(For example, UINib !) Method To introduce Swift code. Now you have an empty tag,NonnullThe mark will no longer use the exclamation mark operator.NullableMarked as optional.UITableViewCellThe return value is introduced into Swift and then becomesUITableViewCell?.
- Swift enumeration can be exposed to Objective-C using the @ objc attribute-For example, the following code:
@objc enum Bear: Int { case Black, Grizzly, Polar}
After importing OC:
typedef NS_ENUM(NSInteger, Bear) { BearBlack, BearGrizzly, BearPolar};
- Let constants are more powerful and consistent.: Let constants do not require immediate initialization. The new rule is a let constant that must be initialized before use and can only be initialized. It cannot be copied or changed again. Therefore, let expressions can be written as follows:
let x: SomeThing if condition { x = foo() } else {x = bar() }use(x)
- More powerful options for if let Parsing-If let can Parse Multiple optionals at a time. It can also contain bool conditions. This effectively avoids invalid nesting. For example:
if let a = foo(), b = bar() where a < b, let c = baz() {}
- New local data structure Set-A disordered and unique dataset type Set corresponds to the NSSet of OC.
Conclusion
Swift1.2 has taken a big step in both language and related tools. Of course, these changes also contain some incompatible code content. Therefore, Xcode6.3 contains a migration tool to automatically complete code migration. You can choose Xcode> Edit> Converter> To Swift 1.2 To use the migration tool.
Reference: https://developer.apple.com/swift/blog? Id = 22