Search code examples
iosobjective-ccore-datansset

NSSet with what looks like a protocol (NSSet<NSObject *> *name)


I have generated NSManagedObject subclasses (Photographer and Photo) using the data model editor - they have a Photographer ->To-Many-> Photo relationship.

Photographer (CoreDataProperties) category came with a property:

@interface Photographer (CoreDataProperties)

...
@property (nullable, nonatomic, retain) NSSet<Photo *>  *photos;

@end

What does NSSet<Photo*> mean? Can you specify what type of objects should be in an NSSet using protocol-like notation? Can't find any info about it in the documentation or anywhere else.


Solution

  • In Xcode 7, Apple has added 'Lightweight Generics' to Objective C.

    They will generate compiler warnings if there is a type mismatch.

    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.

    https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-CAPIs.html#//apple_ref/doc/uid/TP40014216-CH4-ID35