Search code examples
objective-cformatcstringstringwithformat

How to customize a method like 'stringWithFormat'?


I want to customize a method with formated string input and (const char *) return,but the problem is like below... Can anyone tell me how to resolve it? Thanks. I want to customize a method with formated string input and (const char *) return,but the problem is like below... Can anyone tell me how to resolve it? Thanks.


Solution

  • -(const char *)stringWithFormat:(NSString *)format, ...
    {
        va_list args;
        va_start(args, format);
        NSString *lString = [[NSString alloc] initWithFormat:format arguments:args];
        [lString autorelease];
        va_end(args);
        return [lString cStringUsingEncoding:NSUTF8StringEncoding];
    
    }