How do I convert an NSMutableString to NSString when using Frameworks?

Posted by BWHazel on Stack Overflow See other posts from Stack Overflow or by BWHazel
Published on 2010-05-19T19:46:55Z Indexed on 2010/05/19 19:50 UTC
Read the original article Hit count: 666

I have written an Objective-C framework which builds some HTML code with NSMutableString which returns the value as an NSString.

I have declared an NSString and NSMutableString in the inteface .h file:

NSString *_outputLanguage;        // Tests language output
NSMutableString *outputBuilder;
NSString *output;

This is a sample from the framework implementation .m code (I cannot print the actual code as it is proprietary):

-(NSString*)doThis:(NSString*)aString num:(int)aNumber {
if ([outputBuilder length] != 0) {
    [outputBuilder setString:@""];
}
if ([_outputLanguage isEqualToString:@"html"]) {
    [outputBuilder appendString:@"Some Text..."];
    [outputBuilder appendString:aString];
    [outputBuilder appendString:[NSString stringWithFormat:@"%d", aNumber]];
}
else if ([_outputLanguage isEqualToString:@"xml"]) {
    [outputBuilder appendString:@"Etc..."];
}
else {
    [outputBuilder appendString:@""];
}
output = outputBuilder;
return output;
}

When I wrote a text program, NSLog simply printed out "(null)". The code I wrote there was:

TheClass *instance = [[TheClass alloc] init];
NSString *testString = [instance doThis:@"This String" num:20];
NSLog(@"%@", testString);
[instance release];

I hope this is enough information!

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about nsstring