What does id<…> mean in Objective-C?

后端 未结 5 1589
太阳男子
太阳男子 2021-01-03 22:48

I\'m trying to use Google Analytics in an iOS application, and I saw this portion of code :

id tracker = [[GAI sharedInstance] defaultTrack         


        
5条回答
  •  清酒与你
    2021-01-03 23:42

    The <> means that the object conforms to the protocol (pr protocols) inside the square brackets.

    On your example, the object tracker can be any type of object but it conforms to the GAITracker protocol.

    Therefore, although it doesn't have a specific class you can still call methods and properties on it that are declared by that protocol.

提交回复
热议问题