Skip to content

Instantly share code, notes, and snippets.

@StefanLage
Last active August 29, 2015 14:15
Show Gist options
  • Save StefanLage/febc88228b548689571d to your computer and use it in GitHub Desktop.
Save StefanLage/febc88228b548689571d to your computer and use it in GitHub Desktop.
Convert a NSString to a char pointer
#import <Foundation/Foundation.h>
@interface NSString (Char)
-(char *)toChar;
@end
#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