Last weekend I had my first Startup Weekend experience. I must admit I have always been skeptical about this kind of events and came with two goals in mind: try to change my mind about it and pitch some idea I had in the back of my head for a little while.
ActiveValidators 1.9.0 is out!
gem install activevalidators
Read on for the full - yet concise - changelog.
NSManagedObjectContext in each and every
needs CoreData can be done by different means, but some are frowned upon. In doubt, inject it.
While pair-reviewing some code with my colleague Vincent Tourraine,
we realized we wrote this kind of code into each
viewDidLoad: method of each
NSViewController subclasses we created:
Doing so is more or less the same as using a global variable, as calling
UIApplication returns the singleton
application instance. I kind of felt this was a code smell so I investigated.
After a couple of minute of browsing Apple’s documentation, here’s what we can read
A view controller typically **shouldn’t retrieve** the context from a global object
such as the application delegate. This tends to make the application
architecture rigid. […]
When you create a view controller, you pass it a context. […]
If you use the good old
nib|xibs (I’m acting as if I was confident with them) and
instantiate your controllers programmatically, this sounds dead easy, but what
if you use the brand new shiny
The only solution I came up with, that will comply with Apple’s recommendation, is to use
prepareForSegue, like this:
1 2 3 4 5 6 7 8 9 10
If your main controller doesn’t have any
NSManagedObjectContext, you might
want to inject it from within the method
application:didFinishLaunchingWithOptions: of your AppDelegate, as you can see if you create a new CoreData project from the templates.
So next time, no more abuse of the