I want write a property with objective-c that return block and linked call, but how to return instancetype?
@interface Person : NSObject
@property (nonatomic, weak, readonly) instancetype (^age)(int age);
@property (nonatomic, weak, readonly) instancetype (^name)(NSString *name);
@end
I Want Person.new.age(10).name(@"Tom"), but instancetype is error in compile time
So i have to change instancetype to Person *
here, but if I write a class subclass of Person, I have to write it again:
@interface GoodPerson : NSObject
@property (nonatomic, weak, readonly) GoodPerson * (^age)(int age);
@property (nonatomic, weak, readonly) GoodPerson * (^name)(NSString *name);
@end
So how to use instancetype here?
You can't.
instancetype
is not a valid block return type.From https://developer.apple.com/library/archive/releasenotes/ObjectiveC/ModernizationObjC/AdoptingModernObjective-C/AdoptingModernObjective-C.html
An anonymous block does not fulfil these criteria.