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

How to create an abstra...

Câu trả lời

In Objective-C, there is no direct equivalent to abstract classes as found in other object-oriented programming languages like Java or C#. However, you can achieve a similar concept by using protocols and class clusters.

Here's how you can create an abstract class-like structure in Objective-C:

Using Protocols

  1. Define a protocol that declares the methods and properties that the abstract class would have.
@protocol AbstractClass
- (void)abstractMethod;
@property (nonatomic, copy) NSString *abstractProperty;
@end
  1. Create a concrete subclass that conforms to the protocol and implements the required methods and properties.
@interface ConcreteClass : NSObject <AbstractClass>
@end

@implementation ConcreteClass
- (void)abstractMethod {
    // Implement the abstract method
}

@synthesize abstractProperty;
@end
  1. Other classes can then inherit from the concrete subclass and override or extend its functionality as needed.
@interface AnotherClass : ConcreteClass
- (v...
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?

expert

Explain the use case when ARC won't help you to release memory (but GC will)

senior

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

Bình luận

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

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