Здравствуйте!
Делаю простое приложение To-Do list (задание из книги Objective-C Programming: The Big Nerd Ranch Guide) и возникла проблема с сохранением документа. Все остальное работает вполне корректно.
При попытке сохранить появляется ошибка (сохранение должно происходить на диск, без использования iCloud)
2017-08-10 02:41:22.683721+0300 tahDoodle[4195:396897] [default] [ERROR] Failed getting container for URL: file:///Users/dsh/Documents/, error: Error Domain=BRCloudDocsErrorDomain Code=2 "Logged out - iCloud Drive is not configured" UserInfo={NSDescription=Logged out - iCloud Drive is not configured}
2017-08-10 02:41:22.684289+0300 tahDoodle[4195:396897] [default] [ERROR] Failed getting container for URL: file:///Users/dsh/Documents/, error: Error Domain=BRCloudDocsErrorDomain Code=2 "Logged out - iCloud Drive is not configured" UserInfo={NSDescription=Logged out - iCloud Drive is not configured}
2017-08-10 02:41:22.696616+0300 tahDoodle[4195:396897] [default] [ERROR] Failed getting container for URL: file:///Users/dsh/Documents/, error: Error Domain=BRCloudDocsErrorDomain Code=2 "Logged out - iCloud Drive is not configured" UserInfo={NSDescription=Logged out - iCloud Drive is not configured}
Собственно код:
Document.h
#import <Cocoa/Cocoa.h>
@interface Document : NSDocument <NSTableViewDataSource>
@property (nonatomic) NSMutableArray *tasks;
@property (nonatomic) IBOutlet NSTableView *taskTable;
- (IBAction) addTask:(id)sender;
@end
Document.m
#import "Document.h"
@interface Document ()
@end
@implementation Document
#pragma mark - Data Source Methods
- (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView
{
// This table view displays the tasks array, so the number of entries in the table view will be the same as number of objects in the array
return [self.tasks count];
}
- (id) tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
// Return the item from tasks that corresponds to the cell that the table view wants to display
return [self.tasks objectAtIndex: row];
}
- (void) tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
// When the user changes a task on the table view, update the tasks array
[self.tasks replaceObjectAtIndex: row withObject: object];
// And then flag the document as having unsaved changes
[self updateChangeCount: NSChangeDone];
}
#pragma mark - NSDocument overrides
- (instancetype)init {
self = [super init];
if (self) {
// Add your subclass-specific initialization here.
}
return self;
}
+ (BOOL)autosavesInPlace {
return YES;
}
- (void)makeWindowControllers {
// Override to return the Storyboard file name of the document.
[self addWindowController:[[NSStoryboard storyboardWithName:@"Main" bundle:nil] instantiateControllerWithIdentifier:@"Document Window Controller"]];
}
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError {
// This method is called when our document is being saved. You are expected to hand the caller an NSData object wrapping our data, so that it can be written to disk. If there is no array, write out an empty array
if (!self.tasks)
{
self.tasks = [NSMutableArray array];
}
// Pack the tasks array into an NSData object
NSData *data = [NSPropertyListSerialization dataWithPropertyList: self.tasks
format: NSPropertyListXMLFormat_v1_0
options: 0
error: outError];
// Return the newly-packed NSData object
return data;
}
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError {
// This method is called when a document is being loaded. You are handed an NSData object and expected to pull our data out of it
// Extract the tasks
self.tasks = [NSPropertyListSerialization propertyListWithData: data
options: NSPropertyListMutableContainers
format: NULL
error: outError];
// Return success or failure depending on success of the above call
return (self.tasks != nil);
}
#pragma mark - Actions
- (void) addTask:(id)sender
{
// If there is no array yet, create one
if (!self.tasks)
{
self.tasks = [NSMutableArray array];
}
[self.tasks addObject: @"New Item"];
// -reloadData tells the table view to refresh and ask its dataSource (which happens to be this Document object in this case) for new data to display
[self.taskTable reloadData];
// -updateChangeCount: tells the application whether or not the document has unsaved changes, NSChangeDone flags the document as unsaved
[self updateChangeCount: NSChangeDone];
}
@end
К сожалению нагуглить ничего не удалось, штудирование документации так же ничего не дало, буду благодарна за любой совет.
Заранее спасибо!