Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
301 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 Answer

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]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...