I know how to handle this when changing stringWithCString in SQLite… you just stringWithUTF8String instead. Is this the same with a char * when it is returned by sysctlbyname? (see code below)
- (NSString *) platform{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithCString:machine];
free(machine);
return platform;
}
Thanks in advance!
If the C string you’re using is UTF-8-encoded, then use
stringWithUTF8String:. If it’s plain ASCII, then usestringWithCString:encoding:with an encoding ofNSASCIIStringEncoding. Otherwise, it’s probably encoded using Latin-1, in which case you should usestringWithCString:encoding:with an encoding ofNSISOLatin1StringEncoding.In this case,
sysctlbynameis almost certainly going to give you back an ASCII string, so you should do this:Though using either of the other two methods will do you no harm.