Reputation: 1
Although I would like to preserve the contents in a TextView
, and the portion of reading not to iOS but to Mac O SX, I do not go well.
What should be done with the expression:
NSString *string = myTextView.text;
...used when treating the TextView
of the instance name of myTextView
in Mac OS X?
Since I received indication as explanation was lacking, I add a sentence. I would like to make this code into MacOSX. I treat NSTextView.
- (void)saveFile
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0]stringByAppendingPathComponent:@"memo.txt"];
NSString *string =myTextView.text;
[string writeToFile:path
atomically:YES
encoding:NSUTF8StringEncoding
error:NULL];
}
- (void)loadFile
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0]stringByAppendingPathComponent:@"memo.txt"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:path]) {
NSString *string = [NSString stringWithContentsOfFile:path
encoding:NSUTF8StringEncoding
error:NULL];
myTextView.text = string;
}
}
Upvotes: 0
Views: 2347
Reputation: 27157
I think I might actually know what your talking about.
I'm assuming you have an OSX app with an NSTextField
named myTextView
. You are trying do do the Mac equivalent of myTextView.text
. If so you want to do:
NSString *string = myTextView.stringValue;
Response to question edit:
As one might guess to set the value of the textfield you would do the inverse:
myTextView.stringValue = string;
Upvotes: 3