Reputation: 23
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?
Upvotes: 0
Views: 214
Reputation: 5543
You can't. instancetype
is not a valid block return type.
Use the instancetype keyword as the return type of methods that return an instance of the class they are called on (or a subclass of that class). These methods include alloc, init, and class factory methods.
An anonymous block does not fulfil these criteria.
Upvotes: 1