ios – 包含尖括号<>的奇数属性声明语法

我刚刚从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]

以上是来客网为你收集整理的ios – 包含尖括号<>的奇数属性声明语法全部内容,希望文章能够帮你解决ios – 包含尖括号<>的奇数属性声明语法所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。