What is the syntax/signature of a Objective-C method that returns a block
without typedef?
I defined a block that takes an NSString and returns a NSURL for that string:
id (^)(id obj)
I've used typedef to make it a block with a name:
typedef id (^URLTransformer)(id);
And the following method does not work:
+ (URLTransformer)transformerToUrlWithString:(NSString *)urlStr
{
return Block_copy(^(id obj){
if ([obj isKindOfClass:NSString.class])
{
NSString *urlStr = obj;
return [NSURL URLWithString:[urlStr
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
}
return nil; // **THIS LINE FAILS**
});
}
Error:
Return type 'void *' must match previous return type 'id' when block
literal has unspecified explicit return type
My question is: 1. how to correctly implement the method 2. how to
implement the method without typedef URLTransformer?
Thanks
No comments:
Post a Comment