Câu hỏi phỏng vấn Objective-C
Câu hỏi

Explain types of protocol in Objective-C

Câu trả lời

Types of Protocols 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:

1. Formal Protocols

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:

objc Copy
@protocol MyProtocol
- (void)doSomething;
@property (nonatomic, copy) NSString *name;
@end

2. Informal Protocols

Informal protocols, also known as "method categories," are defined using method categories in a class extension o...

junior

junior

Gợi ý câu hỏi phỏng vấn

junior

What is a protocol, and how do you define your own and when is it used?

expert

Which is the best of GCD, NSThread or NSOperationQueue ?

junior

What are Objective-C Categories?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào