开发者

Use return value as argument to method

开发者 https://www.devze.com 2023-03-16 03:09 出处:网络
Is it possible to use the return value of a开发者_StackOverflow中文版 method as the argument for a different method invocation?I\'m using Objective-C.

Is it possible to use the return value of a开发者_StackOverflow中文版 method as the argument for a different method invocation? I'm using Objective-C.

What I'm going for is something like this:

stringOutput = [object1 method1:[object2 method2:[object3 method3]]];

where method 3 returns a string that goes into method 2, which returns a string that goes into method 1, which returns a string that goes into stringOutput.


Do you mean sending the result from one method as the parameter for another?

NSString *string = [self myMethod:[self myMethod2]];

Where the methods are

- (NSString *)myMethod2 {
    return @"A String";
}

- (NSString *)myMethod:(NSString *)string {
    // Do something with string

    // Return another string
    return @"Something else";
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号