- (IBAction)sendMessage:(id)sender
{
NSString* conversationFile = [@"~/" stringByAppendingPathComponent:@"conversation.txt"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:conversationFile];
if (fileExists == FALSE)
{
[self doShellScript:@"do shell script \"cd ~/; touch conversation.txt\""];
}
NSString *conversationContent = [[NSString alloc] stringWithContentsOfFile:@"~/conversation.txt" encoding:NSUTF8StringEncoding error:NULL];
NSString *myMessage = [[messageBox stringValue]copy];
NSString *combinedContent = [NSString stringWithFormat:@"%@ \r\n %@", conversationContent, myMessage];
[[[myConversationBox textStorage] mutableString] setString: combinedContent];
[combinedContent writeToFile:@"~/conversation.txt" atomically:YES encoding:NSUTF8StringEncoding error:NULL];
}
The above code presents the following error
2011-07-07 21:38:08.703
iMessages[86493:903]
-[NSPlaceholderString stringWithContentsOfFile:encoding:error:]:
unrecognized selector sent to instance
0x1001116902011-07-07 21:38:08.704
iMessages[86493:903]
-[NSPlaceholderString stringWithContentsOfFile:encoding:error:]:
unrecognized selector sent to instance
0x100111690
stringWithContentsOfFile:encoding:error:is a class method ofNSString, not an instance method, so you don’t need to (shouldn’t) alloc it first.