What does creating an object with: id <class> instanceName mean?

I saw code on the Apple website that looks like this

id <NSFetchedResultsSectionInfo> sectionInfo = ... 

How is this different from the following?

 NSFetchedResultsSectionInfo *sectionInfo = ... 

I'm not interested in NSFetchedResultsSectionInfo itself, but in the way it is declared.

Thanks a bunch!
Tristan

+4
source share
2 answers

NSFetchedResultsSectionInfo is a protocol. id is a way to declare a shared object, and id <NSFetchedResultsSectionInfo> declares a shared object that must adhere to the NSFetchedResultsSectionInfo protocol.

+5
source

This syntax is used to indicate that the referencing object conforms to a particular protocol. See Apple's documentation on this aspect of Objective-C, specifically the Protocol Compliance section below.

+3
source

Source: https://habr.com/ru/post/1338369/


All Articles