简体   繁体   中英

Can I get markdown file's contents in Objective-C?

I can get the contents of a .txt file in this way:

NSString *articlePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@".txt"];
return [NSString stringWithContentsOfFile:articlePath encoding:NSUTF8StringEncoding error:nil];

However,it is no use when the file is a markdown file:

NSString *articlePath = [[NSBundle mainBundle] pathForResource:@"test2" ofType:@".md"];
return [NSString stringWithContentsOfFile:articlePath encoding:NSUTF8StringEncoding error:nil];

The articlePath is "nil",but the file is exist actually.

I wonder if there any method I can use to get the contents of a .md file.

Thanks in advance.

Go to : Target -> "Build Phases" -> "copy bundle Resources" Then add that particular file here.

Make sure that test2 file is there 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM