Explain types of protocol in Objective-C
Explain types of protocol in Objective-C
In Objective-C, protocols are used to define a contract between classes or structs, specifying a set of methods and properties that must be implemented by the adopting class or struct. There are two main types of protocols in Objective-C:
Formal protocols are the most commonly used type of protocols in Objective-C. They are defined using the @protocol keyword and can include method declarations, property declarations, and even optional methods and properties. Formal protocols are adopted by classes using the <> syntax, and the adopting class must implement all the required methods and properties defined in the protocol.
Example:
@protocol MyProtocol
- (void)doSomething;
@property (nonatomic, copy) NSString *name;
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.