I'm creating a 'test' document based application to learn more about how they work. I want to load an array that I saved earlier.
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSArray *array = [string componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
documentTitle.stringValue = [array objectAtIndex:0];
// For testing
NSLog(@"%@", array);
}
I loaded the file and got the data. I converted the data into an NSString. The file has multiple lines and every line has its own value. The first line is the document title. So I created an NSArray that put every line separately in the array. Then I set the first line of the document to the documentTitle label. For testing purposes I created an NSLog function too. It has to log the array.
The problem is that when I run the code, it doesn't do anything at all. The documentTitle.stringValue doesn't change. But the strange thing is that it does log the array:
2015-09-22 16:57:40.098 DocBased Test[10765:277445]
(
"The awesome title!",
"This is a document!"
)
I declared the documentTitle in the Document.h like this:
#import <Cocoa/Cocoa.h>
@interface Document : NSDocument
{
IBOutlet NSTextField *documentTitle;
}
@end
If you need to view the project in Xcode here's a link: The link.
Does anyone know how to change the stringValue of the documentTitle (or any) label in the Document class?