无夜之星辰 无夜之星辰 - 2 months ago 13
iOS Question

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.

Answer Source

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

Make sure that test2 file is there enter image description here

 [![enter image description here][1]][1]