gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 03:06:53 25 4
gpt4 key购买 nike

我刚刚从 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 - 包含尖括号 <> 的奇数属性声明语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30729976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com