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

What are the differences between implementin...

Câu trả lời

Here are the key differences between implementing an Objective-C property with @dynamic vs @synthesize:

@synthesize

  • Automatically generates the instance variable and accessor methods (getter and setter) for the property
  • The instance variable name is the same as the property name by default, unless you specify a different name using @synthesize property=ivar_name
  • If you don't provide a custom implementation of the getter/setter, the compiler will generate the default implementations for you
  • Example:
objc Copy
@property (nonatomic, copy) NSString *name;
@synthesize name;

@dynamic

  • Tells the compiler that you will provide the implementation of the accessor methods yourself, either in the @implementation block or in a category
  • No instance variable is generated by the compiler
    -...
senior

senior

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

expert

What's the difference between marking a method as @objc vs dynamic , when would you do one vs the
other?

senior

Explain the difference between interfaces, delegates, and protocols in Objective-C

senior

What is the difference between NSMapTable vs NSDictionary ?

Bình luận

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

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