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

前端之家收集整理的这篇文章主要介绍了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]
原文链接:https://www.f2er.com/iOS/334842.html

猜你在找的iOS相关文章