ios - How call a function objective c with args in swift -
i have next function in objective c
+ (nsstring *)getnslog:(nsstring *)pstring, ...{ va_list args; va_start(args, pstring); nslogv(pstring, args); va_end(args); return [[nsstring alloc] initwithformat:pstring arguments:args]; }
how can call function swift or convert code swift such when call function can be:
getnslog("my value1 = %@ value2 = %@","hello","world")
note second param not have alias how this.
getnslog("my value1 = %@ value2 = %@", args:"hello","world")
i solved follow:
in objective c change code this:
+(nsstring*)getnslog:(nsstring*)pstring args:(va_list)args{ nslogv(pstring, args); va_end(args); return [[nsstring alloc] initwithformat:pstring arguments:args]; }
in swift app delegate add
extension myclass { class func getnslog(format: string, _ args: cvarargtype...) -> nsstring? { return myclass.getnslog(format, args:getvalist(args)) } }
now can call function
nslog("%@", myclass.getnslog("%@,%@", "hello","world")!)
i based in post duplicated how call objective-c variadic method swift?
thanks.
Comments
Post a Comment