StringWithContentsOfFile Deprecated

I am using the following code in my application, but it warns that stringWithContentsOfFile out of date.

Can someone tell me how to avoid this warning? Will this warning affect my application in the future?

 NSString *myData= [NSString stringWithContentsOfFile:path]; 
+7
source share
2 answers

I think I can expand the answer to daveoncode a bit, so if you are not interested in errors, you can simply write

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

and it will work as you expected.

+15
source

You should use stringWithContentsOfFile:encoding:error: or stringWithContentsOfFile:usedEncoding:error:

+4
source

All Articles