문제

How do you know if a NSDocument is new?

I'm currently using fileURL != nil but I couldn't find any place in the documentation that confirms this.

Also, fileURL returns nil in restored documents (after quitting the app without saving and then opening the app again). Is it possible to differentiate between a new document and a restored document?

도움이 되었습니까?

해결책 2

By trial-and-error:

- (BOOL) readFromURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError *__autoreleasing *)outError {
    self.isNew = NO; // New documents don't call this method

    BOOL success = [super readFromURL:url ofType:typeName error:outError];

    // This must go after calling super
    self.isSaved = self.fileURL != nil; // Saved documents set fileURL
    self.isUnsaved = self.fileURL == nil; // Unsaved/restored documents don't set fileURL. The url parameter points to a temporary folder.

    return success;
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top