创建一个接受字符串格式Cocoa的方法

Kev*_*tre 1 cocoa objective-c

如何在Objective-C中创建一个接受NSString格式的方法(使用逗号分隔的参数列表列表替换为格式).就像是:

// Hello Kevin
NSString *name = @"Kevin";
[NSString stringWithFormat:@"Hello %@", name];
Run Code Online (Sandbox Code Playgroud)

Gav*_*ler 6

您正在寻找的是一个Variadic函数,在Objective-C中您可以编写如下内容:

- (NSString *) stringWithFormat:(NSString ) format, ... { }
Run Code Online (Sandbox Code Playgroud)

您可以将这个优秀的示例用于Objective-C可变参数函数以获取更多详细信息.