Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
315 views
in Technique[技术] by (71.8m points)

ios - Odd property declaration syntax containing angular brackets <>

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;

What does it mean?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

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]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...