Polymorphism in C ++ and Objective-C

I am new to Objective-C; I wanted to understand the concept more clearly protocol.

@protocol protocolName

@optional

@required

@end

Is it possible to map a part @optionalto a part of a virtual function and @requiredusing a pure virtual function in C ++?

Is @protocolObjective-C a way to create an interface and an abstract class ?

+4
source share
2 answers

Is @protocol an Objective-C way to create an interface and abstract class?

That's right.

@optional @required ++?

, , - classA OptionProtocolMethodB, [classA OptionalProtocolMethodB] . ++ .

, . :

if ([_delegate respondsToSelector:@selector(didUploadedTotalBytes: totalBytesExpectedToWrite:)]) {
    [_delegate didUploadedTotalBytes:_uploadedBytes totalBytesExpectedToWrite:_totalBytes];
}
+5

Objective-C ( ). .

, . , : "color" "setColor", , . , , - . , , - .

, , . , , BOOL, : " , , YES". , . , "responsesToSelector". (, , , requireComplexBehaviour YES, doComplexBehaviour1 doComplexThings2 , , , ).

. , , , , .

+5

Source: https://habr.com/ru/post/1536141/


All Articles