How to annotate Objective-C APIs for use in Swift (e.g. return types) -


According to the Xcode release notes, Apple has "auditioning" its existing API so that they can choose alternatives without interval. This means that T! Instead of , do their APIs T or T? Where appropriate, will come back.

Where do they do this? How can I annotate / wrap my current purpose-c code (especially libraries) to use cleaner from swift?

Xcode 6.3 / swift 1.2

Xcode 6.3 Objective- Added official support to

Emptiness of value

Price zero for the keyword __Table , __elected and __not_translated ( With the default) type can be declared by interpreting the type. The properties and methods include the keyword faucet , nonnull and null_unspecified .

Examples from Xcode release notes

  - (empty) registerNib: (nonnull UINib *) cell resuentifier: (non-existent NSString *) identifier; - (nullable UITableViewCell *) cellForRowAtIndexPath: (nonnull NSIndexPath) index; @protecti (nanatomic, redrawite, raten, blank) uivuvee * background view; Change   

default

null_unspecified (which is translated in T! ) is the default for all existing codes . A useful feature is the ability to change the default for sections of your API.

  NS_ASSUME_NONNULL_BEGIN // here is no default NS_ASSUME_NONNULL_END   

This makes it very far because of noise, which accept the methods and handle the needle There are usually exceptions, not rules. Personally, I will use it for all Audit APIs.

null_resettable

null_resettable is an extraordinary annotation that is used for unusual conditions, where you can set To zero the property, but it be zero will never happen (because it resets a default value).

  @property (nonatomic, retain, Null_resettable) UIColor * tintcolor;   

Personally, I have to avoid this behavior for the new code. The hybrid nature of such properties is not suitable for swift.

Exode 7 / Swift 2 (beta)

Exode 7 adds support for general-type comments in Objective-C

Generic type annotation for the archive

NSArray , NSSet and NSDictionary (which are automatically switched to the array of swift , set and dictionaries can be annotated with their content type.

  @property NSArray & lt; NSString * & Gt; * string array; @propert NSSet & lt; NSString *> * stringSet; @ Property NSDictionary & lt; NSString *, NSString * & gt; * stringDict;   

__ type The keyword which allows less-strict and downcasting to the objective-compiler, but does not affect the swift side.

Common type annotation for custom class
  @ Interface Mayor 1 & lt; __Corporate T & gt ;: NSOJject - (zero) addObject: Object (T); @ and @ IntraMire2Lt; __Coverian TT: NSObject * & gt; : NSObject - (zero) addObject: Object (T); @ And @ interface Marayere 3 & lt; __ Saharanak T: ID & lt; Encycloping & gt; & Gt; : NSObject - (zero) addObject: Object (T); @end   

@implementation is not known about T and id / Uses NSOBE * * / id As always happens.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -