Reprint: swift3.0 and objective-c interactions need to be noted for these
Chapter, Author: zeroj (Gitbub)
Swift3.0 out, you can see the change is great, and cocoa, Foundation ... Interactions have also become more convenient, and Swift is writing apps that fit into iOS 7, so we can be confident that the use of swift in the future will gradually increase, and will involve the coexistence of OC and Swift in the project, where I reread the official ' using Swift with Cocoa and Objective-c (swift3) ' documents, recorded some personal feel more commonly used notes, please read (the code is from the document)
The OC initialization method is cited in Swift as
|
Init (...)---if initialization does not fail init? (...) ---If initialization may fail init! (...) ---otherwise |
The property in OC (getter==, setter==) will be ignored by Swift
ID corresponds to Anyobject but all anyobject are optional in swift, and if the previous value is an optional value, it is a multiple selectable value after it is set to Anyobject.
The attributes in OC are marked as
|
Nullable in Swift? Nonnull-in Swift equals the non-optional attribute, not labeled, in Swift! |
The lightweight generics in OC are also corresponding to the generics in Swift
|
@property Nsarray *dates corresponds to var dates: [Date] |
Closures in swift capture variables by default in the same way that a block in OC captures a variable marked as __block, that is, a pointer to a variable that is captured by a closure
In Swift, as long as it is not in multi-threading, it is recommended to use [unowned self] to avoid circular references, in multi-threading, it is recommended to use [weak self]
The = = operator is equivalent to isequal in OC:---that is, comparing content is equal; = = = equivalent to a pointer comparison in OC
Subclasses inheriting from NSObject if you override the Isequals: method, you should provide the hash property
Cannot inherit Swift's class in OC