Problems with NSString writeToFile

I am working on a simple text editor in Cocoa / Objective-C for a practice project, and I ran into an error that I would never have expected.

I have an NSString for my file contents as well as an NSString for this path. When I try to write the contents to a file, I use the following method:

[FileContents writeToFile: CurrentFileName atomically: NO encoding: NSStringEncoding /* Error occurs on this line */ error: nil]; 

I have used this method many times without errors, but today I get an error message:

"Expected expression before 'NSStringEncoding'"

If anyone can help me with this, we will be very grateful. I can’t understand what might cause the error. Many thanks!

+4
source share
2 answers

NSStringEncoding is not a valid value. You need to decide what to use text encoding . If you do not know anything about text encodings, and these files are used only by your program, I would recommend using NSUTF8StringEncoding everywhere.

UTF-8 has many advantages, including that it is simple ASCII if you do not encounter characters other than ASCII.

+8
source

NSStringEncoding is a type, not a value. You need to specify which NSStringEncoding you want (e.g. NSUTF8StringEncoding, NSASCIIStringEncoding, etc.).

+3
source

Source: https://habr.com/ru/post/1310749/


All Articles