I’m using the code from this Gist to determine which iOS device (e.g. iPhone5,1
) my app is running on:
- (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 stringWithUTF8String:machine];
free(machine);
return platform;
}
The Swift documentation indicates that C data types are well-supported, but it doesn’t say anything about C functions. Is there a pure Swift way to retrieve the machine identifier, or will I have to bridge into Objective-C for this?