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

junior

What are blocks and how are they used?

senior

What is the difference between ARC (automatic reference counting) and GC (garbage collection)?

senior

Why delegate is never retained?

Bình luận

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

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