Tutorial/example of a minimal document-based app - cocoa

I'm trying to understand how the things in Cocoa works but I'm struggling with one thing. I saw http://cocoawithlove.com/2010/09/minimalist-cocoa-programming.html and http://casperbhansen.wordpress.com/2010/08/15/dev-tip-nibless-development/ and I think I somewhat understood.
Now, I would like to do the same but for a "Document-based application". Please, does anyone know of a tutorial or example akin to the ones above? Alternatively, what do I need to do to make it work? I think I need to create NSDocumentController - but how does it relate to NSApplication? And I create NSDocument from there? Frankly, I'm bit lost...

That was me six months ago! I did not find a decent tutorial either but started with a new project using the default Xcode project template:
I started out with the setup Xcode generates for you when you start a new project and implemented piece by piece as I went along. There's some good reading here on Stackoverflow about the use of the various controller classes but here's what I did:
The document class, generated by Xcode, is my top level controller. I do not use NSDocumentController.
Each use case of my app has a number of NSViewControllers which manage the various views of the use case. These controllers are dynamically swapped in and out. The top level controllers are managed by the NSDocument class (NSPersistentDocument in my case as I use Core Data).
I am by no means an expert, so I stand corrected for better approaches but so far this setup has been easy to work with, easy to maintain and easy to extend.
Note: Using Core Data is optional but over time I've come to love it and think it's very powerful and a huge time saver. When you decide not to use Core Data, the above setup will still work but you will have to manage your own data.
EDIT: This post explains the relevance of NSDocumentController.
EDIT2: This one from Apple is an interesting read as well.
EDIT3: You do need NIBs (or XIBs as they're now called) as they contain the UI of your app. You pull them in via a view controller (subclass NSViewController):
NSString *aControllerName = [anIdentifier stringByAppendingString: #"ViewController"];
NSString *aNibName = [anIdentifier stringByAppendingString: #"View"];
Class aControllerClass = NSClassFromString(aControllerName);
[self setCurrentController: [[aControllerClass alloc] initWithNibName: aNibName bundle: [NSBundle mainBundle]]];
In the above anIdentifier could be Department, which would instantiate the DepartmentViewController and load the XIB name DeparmentView.
You can use plists to store your data but that's not a requirement. There are many ways to store your apps data. You'll have to read about the various architectures Apple has in place and make your own choices.

Related

Ability to programme a playground application inside same project in swift

The situation is as follows:
I am trying to define a path in which a certain character travels in a game. This can be done by typing all coordinates for such path. However, this requires a lot of testing, recompiling, as you try to view such path in the product and see if it is what you wanted. This is very tedious
Clearly there is no Graphical Interface built in for every purpose, and obviously also for this case. Then, I proceed to built another application/ another few files that serve as a custom graphical interface for my path class: for editing paths by coordinates and change it interactively.
This does not really cause a problem. However, such an application does not fit in the app, nor make sense to be an application just for programming a specific class. Additionally, if I want to have an application for each of my more complicated data structures, it becomes very messy and hard to manage.
I recall that there is a playground feature in swift. This is perfect for me as it is interactive. And I am thinking:
Is there a way to programme an playground-similar application inside the same project?
(Since I demand programming to be pretty) Can this be done without switching to different projects just for this purpose? Is there such a feature?
Equivalently, is there a way to programme something that helps programming within swift, such as an extension for swift?
Again, I emphasis that, this is needed only for saving troubles and making an application more self-contained.
Turns out to be a stupid question. There is obviously an option in adding a new playground file to existing project.

Storyboard or Xib in a multiple developer project

I am working in a multiple developer native iOS app project.
Both developers need to access and modify UI elements so which one do you think is better to use; Storyboards or Xibs? I read some documents and some of them put Xibs over Storyboards as Storyboards can have lots of conflicts on merging the UI components but xibs have more independent structure.
Do you know any tools or appropriate ways to do that?
Our approach for now is to use 'multiple storyboards' and cut them clean so that the developers wouldn't need to modify each others storyboards. What do you think about this approach?
Thanks,
E.
I won't go too deep into it, but both are fine. Especially if you do it in Xcode 5 and above, the format of xib/Storyboard file is much more version control friendly.
Use Storyboard if the interaction in your applications are quite simple and linear. Use xib files if many elements are reusable. Check out this answer for more in depth explanation.

Completely customized UI in iOS 7

Assume you have to develop an app, which needs a completely customized user interface so that you can not use any standard UI objects in Xcode.
How would you proceed to create such an user interface? Would you use the interface builder? Would you create something like a master parent UIView? What are the best practices to achieve this?
What would be the most elegant solution with less code duplication?
If by "complete customization" you mean the look and feel of the app,
then I suggest to design the IB objects you require using some design IDE's such as photoshop and then use those slices for your project.
This is the best option I find so far to get a complete customized look with minimal code, and by minimal, I mean you don't actually require any coding. You can do this complete customization within your Interface builder.
However, I don't think you can completely ignore standard UI objects as you require them to add basic functionality.
If customized controls are what you are looking for, then I suggest you to create separate custom control classes so that they can be reused anywhere in your project, or in other projects too.
Here are two wonderful tutorials on custom controls:
http://www.raywenderlich.com/36288/how-to-make-a-custom-control
http://www.raywenderlich.com/56885/custom-control-for-ios-tutorial-a-reusable-knob
Hope this helps!

Missing boilerplate method implementations with Xcode 4.5

I'm following some xcode lessons that are using xcode 4.2 while I'm using xcode 4.5.2.
In those lessons when a new project is created i can see that there are a lot of built in methods in the ViewController.m like ViewDidAppear etc'. In my ViewController.m there's online - viewDidLoad and didReceiveMemoryWarning
Is there a way to get that behavior back or there's something I'm missing in 4.5.2 ?
You aren't missing anything.
Xcode't templates tend to evolve with releases so things come and go. One of those things was all the boilerplate that you used to get with view controllers.
The good news is that you are aware that they are missing so you know which ones to put back if you need to implement them.

A good place to find frameworks with Interface Builder plug-ins…

Someone on here recently recommended BWToolkit, and it really impressed me, so I started googling for more IB plug-ins. I've found a couple on random blogs, but haven't been able to find any kind of repository/aggregator for them. Anyone know where I can find more of these?
Thanks.
I just created a page on CocoaDev to list them [edit: question originally just said “Interface Builder plug-ins”, did not mention Cocoa frameworks], with the two I know of listed.
Well that's a good start. I guess that wiki page is the de-facto repository, for now. Seems like there's not much out there.
You are not looking for Interface Builder plug-ins. You think you are, but you aren't. BWToolkit, the example you use in your question, is not an Inteface Builder plug-in. Brandon bills it as an Interface Builder plug-in but it is actually a framework and a plug-in. The framework contains the actual controls. The plug-in contains the integration with Interface Builder.
So really, what you are looking for are frameworks that contain or provide Interface Builder plug-ins. I have changed your question to reflect that, so it is more likely to be found by people using Google to search for similar things in the future.
I know what I am looking for. Not all frameworks contain IB plugins. I am looking for a specific subset of frameworks, those which contain IB plugins. An IB-plugin without a framework is useless, therefore the framework part is assumed. I am NOT looking for regular old frameworks, so stop trying to change my question to that. Your additions only seem to be confusing people.
I have reported your post, hopefully moderators will be able to stop your obnoxious behavior.
"Without a framework, what would you have to plug in to IB?"
Your words, not mine. Anyways, I'm done arguing this with you. Just remember that I can roll back for every time that you edit.
It's clear you have a lot of experience in this field, but instead of offering answers you decided to nitpick where there are no nits to pick.
Additionally, you have not "changed the question to refelct that," you have changed the question to a completely different question. I would have though that after four rollbacks you would relaize that you're doing more harm than good. Just stop, okay?
Of course, Chris Hanson is absolutely correct when he says that an Interface Builder plugin is useless without an accompanying framework. Interface Builder merely provides a graphical way to manage objects in a framework; without the framework itself, Interface Builder has nothing to manage.
However, I do think that there is a completely valid sort of Interface Builder plugin that wouldn't necessitate the installation of an accompanying framework, and that would be one that provides Interface Builder integration features for objects in Cocoa/Cocoa Touch which would otherwise appear as just generic objects.
For those of you who come to this page Google, please recognise the difference between Interface Builder plugins and frameworks: even the examples mentioned above work on frameworks (they could be Foundation, AppKit, UIKIt, etc.)

Resources