i'm trying to convert const char* to NSString * and then convert it back. It works, but i get:
__NSAutoreleaseNoPool(): Object 0x100550a40 of class NSCFArray autoreleased with no pool in place - just leaking
__NSAutoreleaseNoPool(): Object 0x100551730 of class NSCFString autoreleased with no pool in place - just leaking
__NSAutoreleaseNoPool(): Object 0x100551f10 of class NSCFData autoreleased with no pool in place - just leaking
The code is:
const char* convert = "hello remove this: *";
NSString *input = [[NSString alloc] initWithUTF8String:convert];// convert
//remove * FROM THE STRING
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"*"];
// REPLACE * WITH NOTHING
input = [[input componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""];
// CONVERT BACK
const char *converted_back = [input UTF8String];
I'm lost, please help me out.
If you are doing it in a background thread, add an NSAutoReleasePool.
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
const char* convert = "hello remove this: *";
NSString *input = [[[NSString alloc] initWithUTF8String:convert] autorelease];// convert
//remove * FROM THE STRING
NSCharacterSet *doNotWant = [NSCharacterSet characterSetWithCharactersInString:@"*"];
// REPLACE * WITH NOTHING
input = [[input componentsSeparatedByCharactersInSet: doNotWant] componentsJoinedByString: @""];
// CONVERT BACK
const char *converted_back = [input UTF8String];
[pool drain];
Also, you need to release input
after you're done with it, or make it autoreleased.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With