How to add a custom object to Xcode? - xcode

I want to create an object and use it on my project. I able to do it, but under the objects panel of xib file there is a pop up list that shows these values:
Cocoa touch [Controls, Data Views, and ...]
Custom objects
The Custom objects list is empty! Is any way to add my objects to this list? What is this list exactly?

This list is indeed meant to save custom object templates. You could create those custom objects and then pull them into the list for later reuse.
However, it doesn't seem to work in the current stable version (4.5.2) of Xcode.
You should check if it works in the latest developer preview. If it doesn't you should probably file a bug.

Related

NSDocument for relational data / todo list?

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...?
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.

Cocoa how to handle multiple views?

I'm have done some development on iOS using Storyboards. Now I'm building on app for Mac OS X and it seems that an equivalent for Storyboards does not exists.
For instance, I'm need to build some kind of wizard, which contains four different windows or views (step 1 to 4).
Currently I've created one Window xib (the standard MainMenu.xib), containing a window with the first view, and three other custom views. Using this approach, I can create outlets and actions, making me able to change the contentView of my window, e.g. when clicking an button. This seems as a fair solution, and my views are all grouped cleanly inside a single xib. But this also cause that the logic for all the view should be handled by the same File's Owner, right? For instance saving the settings on each step and controlling the interaction between the different views.
How is the preferred way to handle a situation like this? Should I instead create four different windows, and maybe in four different xib-files? If you know an sample project somewhere from the internet showing how to handle multiple windows, please give me a hint.
You can make use of the NSViewController class for this purpose. Each view controller will be responsible of loading a xib associated with it and all logic associated with the views can go inside the controllers (Same as in iOS). The MainMenu.xib can now load appropriate views after initialising the required view controllers.
Here is a sample app for your reference.
https://developer.apple.com/library/mac/samplecode/ViewController/Introduction/Intro.html
In xcode, go to File->New->New File
Add an objective C class and set it to subclass of "NSViewController".
This will itself create yourController.h, yourController.m and yourController.xib.
Now you can keep your view and its controller class seperate.

MVC Structure?

I am having some difficulty getting my head around the MVC structure.
What I am still struggling with is, when creating the Control to accompany the supporting code, does one need to include the Object within IB?
Think of IB as a freeze-dried version of an object. It is the object itself in visual form. It's stored in the xib file and pulled out when referenced.
You don't NEED to use IB. You can create an object and add it to a view without ever opening the visual tool (some people prefer to work that way).
Storyboarding carries this to an even greater level where you can create the interaction between views in the form of segues.

How to use "Custom Objects" in IB in XCode 4

This is in Xcode 4 and it leads me to believe that I can create, and reuse, custom objects. However, I can not find any method of doing so.
How do you use this? Does anyone know?
Short answer: you currently can't use the Custom Objects section to create custom objects.
The Custom Objects section contains third-party Interface Builder elements. Older versions of Xcode and Interface Builder supported the creation of custom user interface elements. BWToolkit contains examples of custom elements. If you open an old Xcode project in Xcode 4 that contains custom elements, those elements appear in the Custom Objects section. Xcode 4 does not currently allow you to edit xib files that contain custom user interface elements, reducing the usefulness of the Custom Objects section.
If you would like to be able to create custom user interface elements in Xcode 4, file a bug report with Apple.

Can I inspect a Core Data model from Xcode?

Can I inspect a Core Data model from Xcode?
I want to see if the data are correctly stored into the database.
You can use this tool http://christian-kienle.de/CoreDataEditor
You can inspect all datas from your persistent store
There's no direct "show me some data stored at some path I specified somewhere in my code or at runtime that happens to use this model" feature.
If you want to view a file easily in Xcode, you'll need to add the file to your project (don't let it copy into project - just reference it in place) so you can select it in the navigator.
Caveat: This only works for text-based store types (like XML or some custom text-based store type you cooked up). If you use binary or SQLite store types, all you'll see is binary. There's no SQLite database browsing/editing functions in Xcode.
I have not come across a way to check the Core Data Modal directly from Xcode... right now I use "SQlite Database Browser" to check my database... its a good way to check your data in the database.. you can also execute queries on it...
P.S. If you do come across a way to check the Core Data Modal directly from Xcode, please do post it as an answer here...

Resources