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]

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...