Sethu
Sethu

Reputation: 71

How to read .m file as NSString in iOS

I am trying to display an implementation file(Code inside the .m file) in UITextView. Below is the code snippet i used. But it returns nil.

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"TextCheck.m" ofType:@"m"];

Upvotes: 1

Views: 115

Answers (2)

Subbu
Subbu

Reputation: 2148

I really doubt you can do this. The source code is not a 'resource'..When you execute the app they are in binary form.. there is no code in there..

If you need to do display something that you know already - try storing the text/code you intend to display in a plain file and display..

Upvotes: 1

Kirit Modi
Kirit Modi

Reputation: 23407

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"TextCheck.m" ofType:@"m"];

Replace the code as below line :

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"TextCheck" ofType:@"m"];

Upvotes: 1

Related Questions