我刚刚从2015 WWDC示例代码(
https://developer.apple.com/sample-code/wwdc/2015/)下载了FourInARow,并注意到文件AAPLViewController.m中有一个奇怪的属性声明
@property NSArray<NSMutableArray<CAShapeLayer *> *> *chipLayers;
这是什么意思?
解决方法
它是Objective-C的新成员,名为
Lightweight Generics.它是在iOS9 / OS X 10.11中引入的,目的是增强Swift和Objective-C之间的互操作性.正如文件所说:
Objective-C declarations of NSArray,NSSet and NSDictionary types
using lightweight generic parameterization are imported by Swift with
information about the type of their contents preserved.For example,consider the following Objective-C property declarations:
@property NSArray<NSDate *>* dates; @property NSSet<NSString *>* words; @property NSDictionary<KeyType: NSURL *,NSData *>* cachedData;
Here’s how Swift imports them:
var dates: [NSDate] var words: Set<String> var cachedData: [NSURL: NSData]