包含尖括号<>的奇数属性声明语法 [英] Odd property declaration syntax containing angular brackets <>
问题描述
我刚从2015 WWDC示例代码下载了FourInARow( https://developer.apple.com/sample- code / wwdc / 2015 / )并注意到文件中的奇怪属性声明 AAPLViewController.m
I just downloaded FourInARow from 2015 WWDC sample code (https://developer.apple.com/sample-code/wwdc/2015/) and noticed an odd property declaration in file AAPLViewController.m
@property NSArray<NSMutableArray<CAShapeLayer *> *> *chipLayers;
这是什么意思?
推荐答案
这是Objective-C的新增内容,名为 Lightweight Generics 。它是在iOS9 / OS X 10.11中引入的,目的是增强Swift和Objective-C之间的互操作性。正如文档所说:
It is a new addition to Objective-C, called Lightweight Generics. It was introduced in iOS9 / OS X 10.11 in order to enhance interoperability between Swift and Objective-C. As the documentation says:
使用轻量级通用参数化的NSArray,NSSet和NSDictionary类型
的Objective-C声明由Swift导入保存
有关其内容类型的信息。
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.
例如,请考虑以下Objective-C属性声明:
For example, consider the following Objective-C property declarations:
@property NSArray<NSDate *>* dates;
@property NSSet<NSString *>* words;
@property NSDictionary<KeyType: NSURL *, NSData *>* cachedData;
以下是Swift进口的方法:
Here’s how Swift imports them:
var dates: [NSDate]
var words: Set<String>
var cachedData: [NSURL: NSData]
这篇关于包含尖括号<>的奇数属性声明语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!