"hello".toUpperCase() -> "HELLO"
And you can do the same with ObjC strings !
[@"hello" uppercaseString]; -> "HELLO"I'm using that to create an empty file with
writeToFile. Looks quite nice :
[@"" writeToFile:logPath atomically:YES encoding:NSUTF8StringEncoding error:nil].
Alas I've never used Smalltalk !
As for numbers and nil …
// Create an NSNumber [@6.5 message]; // Create an NSNull [@nil message]; // Bools too ? [@YES message];
We could always lobby Apple for that :)
What's wrong with [[NSFileManager defaultManager] createFileAtPath:logPath contents:[NSData data] attributes:NULL];?
Nothing ! I used
writeToFile because it was the first thing I found in the help.
Not a Unicode expert, but I imagine the string
@"" with utf-8 encoding would write with a byte order mark at the beginning.
The file shows up as zero length in Terminal. According to Wikipedia, the BOM is used for UTF8 and UTF32 http://en.wikipedia.org/wiki/Byte%5FOrder%5FMark .
Apparently there is no way to mark the file with a particular encoding … maybe with metadata ?
writeToFile:atomically:encoding:error: ultimately call
open anyway, but you get a lot of additional overhead. Better to do it yourself:
man 2 open
Windows likes to use a BOM for UTF-8, but I don't we have that particular problem on OS X.
You like performance, I prefer convenience ;)
I've dabbled with
open/read/write while writing NSLogConsole and quickly came back to ObjC — functions like
open are unsearchable, and I've had trouble finding documentation for stuff like
ioctl. Even if
createFileAtPath is slower, it's much easier to use.
> You like performance, I prefer convenience ;)
> I've dabbled with open/read/write while writing NSLogConsole and quickly came back to ObjC
Keep in mind Objective-C is a superset of C.
> functions like open are unsearchable
Man pages contain example usage, possible pitfalls, existing bugs... Cmd-double click in Xcode to bring up the header file is also extremely useful. (I usually have more trouble with the framework references than with libc)
write work just fine, but how do you use stuff like
ioctl ? The man page is bare, the header file also, googling it yields differents results for Linux, BSD, …
The main problem I have with file descriptors is finding documentation on the concept. I know that everything is a file, but using it is practice made me pull my hair. In NSLogConsole, I redirected stderr output to a pipe, this worked just fine when launched from XCode or the Terminal, but blocked when launching from Finder. Seems like because XCode and Terminal open a TTY before launching the app and redirecting stderr to a pipe works fine here, but blocks from Finder.
I tried opening
dev/tty, tried to google some more info about pipes, async sockets, (and some exotic options to set with …
ioctl), file descriptor concepts and came up with nothing working — I tried the UNIX way and failed, I tried the Cocoa way and succeeded pretty quickly.