views:

171

answers:

2

Hi everyone,

I have been working on a simple text editor in Cocoa/Objective-C for a practice project and I have come across an error that I would never have expected.

I have an NSString for my file's contents as well as an NSString for it's path. When I attempt 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've used this method many times without error yet today, I am getting an error:

"Expected expression before 'NSStringEncoding'"

If anyone can help me out with this it would be greatly appreciated. I can't figure out what could be causing the error. Thanks a lot!

+1  A: 

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

Chuck
+2  A: 

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

UTF-8 has many benefits, including that it is plain ASCII if you don't encounter any non-ASCII characters.

NilObject
Thanks! I just figured out my mistake as soon as I posted it. Note to self: Don't try to program on low levels of sleep =)
Jesse
If this is the right answer, don't forget to click the √ next to the left.
Alexsander Akers