Write a va_list version of your variadic method;
+ (NSError *)executeUpdateQuery:(NSString *)query, ...
{
va_list argp;
va_start(argp, query);
NSError *error = [MyClassName executeUpdateQuery: query args:argp];
va_end(argp);
return error;
}
+ (NSError *)executeUpdateQuery:(NSString *)query args:(va_list)args
{
NSLogv(query,args);
return nil;
}
This can then be called from Swift
MyClassName.executeUpdateQuery("query %d, %d %d", args: getVaList([1,2,3,4]))
Add an extension to support native Swift variadic args:
protocol CFormatFunction {
class func executeUpdateQuery(format: String, _ args: CVarArg...) -> NSError?
}
extension MyClassName : CFormatFunction {
class func executeUpdateQuery(format: String, _ args: CVarArg...) -> NSError?
{
return MyClassName.executeUpdateQuery(format, args:getVaList(args))
}
}
MyClassName.executeUpdateQuery("query %d %@ %.2f", 99, "Hello", 3.145)
Be careful, Swift doesn't provide NS_FORMAT_FUNCTION warnings (-Wformat)
MyClassName.executeUpdateQuery("query %@", 99)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…