bits about life, coding and stuff
I don’t know what’s my thing about logging, it’s just total handy, and look how my console looks since today!
I always printed out which function i am in (easy… just use __FUNCTION__ as macro…) but now it does that WITH ACTUAL PARAMETERS! How awesome is that? You still see some older comments that now “repeat” themselves, all I need to do now on functions is using my DDLogFunction() macro.
How? A blend of cocoalumberjack, my own formatter (see my blog), a modified HOLog, and a modification of LOG_MACRO
Disclaimer: Don’t use this in released code, it’s for debugging only! (You do let the preprocessor compile out your logs, do you?)
My latest contract work finally hit the AppStore! (nah, actually it’s in store some time now, but couldn’t find the time to create this report
It was a pretty rough ride, after two rejects and some modifications we finally were able to submit it to the store. We started around May, so this really took some time.
Knallgrau approached me in imminent need for an iPhone Developer, and after some talks we found an arrangement. They did most of the “early” design, but lacking sophisticated iOS design skills, I reworked most of the concept.
The app’s goal is of a promotional nature, so basically it’s facebook+twitter+various rss feeds+some fun stuff. Plus, you should be able to share everything, so twitter/facebook need to be bidirectional.
Mocking asynchronous http calls is always kinda tricky. And it doesn’t become any easier if you use blocks too. And since my fork of asi-http-request finally is about to merge (check out the blocks-test branch!), we have to work on this.
First, we need some basic block infrastructure. Add this to your project (or better, to your supporting-categories-subproject):
This helps us executing blocks after some delay. Async calls are most likely not to return instantly, so we want to simulate this.
Next, we look at OCMock. While mostly used with SenTestingKit, we use it for mocking the ASIHTTPRequest – helping test our actual software. (This can really replace unit testing, if you use it in combination with UIAutomation)
Note: Some if this (esp. the OCMock part) can also be applied if you work with plain ol’ NSURLConnection – but it’s only half the fun (and elegance)
Integrating OCMock is kinda tricky, be sure to use -all_load OR -force_load
And you probably don’t want that code in the AppStore-build, so either create a new target or remove the project prior compiling that.
So, now to the delicate stuff. I use preprocessor defines to enable/disable the mocking. The actual mocking part is between #ifdef MOCK_HANDSHAKE and #endif, but here’s a more complete example to get the idea…
See how we set the 3 seconds delay in RunAfterDelay, creating yet another block that calls our completionBlock, while playing nice with memory. The actual response is loaded from the textfile “mock_handshake.txt” that’s included in our main project.
Please drop me a line if you believe this was helpful.
spoiler: no, it isn’t
But – here’s some new awesome stuff for iOS devs…
You should follow me on GitHub to get all those classy gems in your daily stream.
Even after more than a year, CoreData still surprises frustrates enlightens me.
First of, seems I’m doing it all wrong, the whole time. Go get mogenerator + Xmo’d. This should be in the Apple Docs, so useful! mogenerator autocreates core data class files everytime you save the .xcdatamodel file. All you have to do is add a “xmod” comment on that file. (and don’t forget to add the auto-added files as a compile-target, or you end up with NSManagedObjects)
Base is an awesome sqlite browser, much better than that no longer maintained QT stuff i had before.
You can set default data values. Even “last Tuesday at dinner” works here! nah, you can’t, this translates at compile time.
Need more? check out “Core Data Tips & Tricks“