Skip to content

Instantly share code, notes, and snippets.

@nishabe
Last active August 12, 2018 18:23
Show Gist options
  • Save nishabe/1e8531f8ee580b089aef1145369aa5c1 to your computer and use it in GitHub Desktop.
Save nishabe/1e8531f8ee580b089aef1145369aa5c1 to your computer and use it in GitHub Desktop.
OBJC: Read text from File
- (NSString*)readString{
NSURL *filePath = [[NSBundle mainBundle] URLForResource:@"info" withExtension:@"txt"];
NSString *path = [filePath path];
NSString *content = @"";
if([[NSFileManager defaultManager] fileExistsAtPath:path]) {
// Do something here
content = [NSString stringWithContentsOfFile:path
encoding:NSUTF8StringEncoding
error:NULL];
}
else {
NSLog(@"File not exits");
}
return content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment