0

I want to create an OS X app where users can edit items from something similar to a todo list - each item has text, status (done/todo), creation date and some other data. The items of the todo list have also relationship with other entities.

I created an iOS app for this which uses a core data data model... Now I want to make an OS X app and sync.

I'm new to OS X development and just stumbled upon NSDocument, and wondered if this could be usable. I just want that the user sees the list similar to an excel table and can edit it. I found some examples to store only a string e.g. https://developer.apple.com/library/mac/documentation/DataManagement/Conceptual/DocBasedAppProgrammingGuideForOSX/ManagingLifecycle/ManagingLifecycle.html or this tutorial http://www.raywenderlich.com/12779/icloud-and-uidocument-beyond-the-basics-part-1

There's also NSPersistentDocument to work with core data, which I think is what I would have to try out.

But generally speaking, does it have any benefit to use NSDocument for my todo list? One could be the undo functionality but I'm not sure if this is applicable. Any advices?

I'm also not sure if I have to use one document for each todo or rather load them all in one document, and if this works correctly with table view... Maybe in a todo app I will never get hundreds of entries, but principally I could. Would I be able to paginate, etc.? Thanks!

Edit: I just read Document-based application, or not? specially "The key question is one of independence. If all of the objects in your application's model are related then there's no need to manage independent documents." Not sure how to apply this to my model... It's relational. Some 1:1 and 1:n relationships. Does this mean that all my objects are related? Or can I still treat them as "independent" documents...?

Community
  • 1
  • 1
User
  • 31,811
  • 40
  • 131
  • 232

1 Answers1

1

If the app has just one todo list, there's no benefit to using NSDocument. Use Core Data, and you'll get undo support without having to use NSDocument.

NSDocument would help if your app lets people create multiple todo lists and save each list in its own file. NSDocument is designed for apps like word processors and spreadsheets where people can create multiple documents and have multiple documents open at once. If you were to use NSDocument for this app, each todo list would be its own document.

UPDATE

The main benefits of NSDocument involve the File menu. When you use NSDocument, choosing File > New creates a new document. Choosing File > Open opens an Open File dialog for you to load a document from disk. Choosing File > Save when you save a new document opens a Save File dialog for you to save the document as a file on disk.

When determining whether or not to use NSDocument, ask yourself the following questions: Do you want the user to create a new todo list by choosing File > New? Do you want the user to save the todo list as a separate file by choosing File > Save? Do you want the user to open todo lists by choosing File > Open? If the answer to these questions is YES, NSDocument will help you. If the answer to these questions is NO, NSDocument won't help you. Also, NSDocument will not help you when dealing with the "other documents" that reference the individual todos in the lists.

To answer your question about iOS syncing, are you using UIManagedDocument in your iOS app? If so, you can use NSPersistentDocument in your Mac app and share the same Core Data model. If not, you won't be able to use NSPersistentDocument. You'll have to use NSManagedObject in your Mac app to use the same Core Data model in both the iOS and Mac apps. It's possible to use NSDocument and Core Data together without using NSPersistentDocument, but I don't know how to use them together. But if you are not using UIManagedDocument in your iOS app, that is a sign that you should not use NSDocument in your Mac app.

Swift Dev Journal
  • 19,282
  • 4
  • 56
  • 66
  • I have multiple todo lists. And also some other "documents" that reference the individual todos which appear in these lists. I want users to be able to edit each list similar to a spreadsheet yes. The thing is, I need that everything is stored using core data because I want to sync with an iOS app, that uses only core data not documents, and want to use exactly the same (core) data model. Is still using documents beneficial? As far I understand it's possible to use core data as storage so it's at least possible. – User Jan 17 '15 at 13:57
  • That's a lot of useful information, thanks (+1)! It sounds like I don't need that since I don't want to make explicit to the user that my list are "documents" (open/save etc.). Thought it may be rather an internal concept, invisible to the user. also, I didn't add anything document related to the iOS app, because I didn't know about it at that time... maybe I would add it if it was convenient. But, still, I read, that UIManagedDocument is convenient to manage the core data stack even if not using document functionality and also helps with iCloud, in case I would support that in the future... – User Jan 17 '15 at 22:54
  • Well, I just read in another post stating that using UIManagedDocument as a helper for core data stack is outdated, as xCode comes with a template for core data. Maybe it doesn't provide additional value in this aspect. The autosave could be nice but I don't know if it's worth it, saving after each operation is trivial to implement and more controlable... and iCloud also seems to work with only core data. I'll stick to only core data for now. – User Jan 17 '15 at 23:02