Last active
August 29, 2015 14:15
-
-
Save StefanLage/febc88228b548689571d to your computer and use it in GitHub Desktop.
Convert a NSString to a char pointer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface NSString (Char) | |
-(char *)toChar; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "NSString+Char.h" | |
@implementation NSString (Char) | |
/* | |
* Convert a NSString to a char pointer | |
*/ | |
-(char *)toChar{ | |
const char* strUtf8 = [self UTF8String]; | |
size_t len = strlen(strUtf8) + 1; | |
char *toChar = malloc(len); | |
memcpy(toChar, strUtf8, len); | |
return toChar; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment