Vijay
Vijay

Reputation: 1016

stringWithContentsOfFile Deprecated

I use the following code in my app, but it gives a warning that stringWithContentsOfFile is deprecated.

Can anyone tell me how to avoid this warning? Will this warning affect my app in the future?

NSString *myData= [NSString stringWithContentsOfFile:path];

Upvotes: 7

Views: 6562

Answers (2)

xci
xci

Reputation: 450

Thought I might expand on daveoncode's answer a bit, so if you are not interested in the errors, you can just simply write

NSString *myData= [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];

and it will work as you expected.

Upvotes: 15

daveoncode
daveoncode

Reputation: 19588

You have to use stringWithContentsOfFile:encoding:error: or stringWithContentsOfFile:usedEncoding:error:

Upvotes: 4

Related Questions