使用NSString类方法stringWithContentsOfFile:encoding:error我可以:
NSError *error;
NSString *fileContent = [NSString stringWithContentsOfFile:... encoding:... error:&error]
if (fileContent == nil) {
NSLog(@"%@", error);
}
我想做类似的事情:
NSString *message;
BOOL result = [self checkSomeRandomStuff:&message];
if (result == NO) {
NSLog(@"%@", message);
}
如何在checkSomeRandomStuff方法中分配消息变量?
答案 0 :(得分:4)
将另一个*添加到参数类型
-(BOOL)checkSomeRandomStuff:(NSString**)message {
// check some random stuff
if (something) {
*message = @"something";
return YES;
} else {
*message = @"some other thing";
return NO;
}
}