BuySellAds.com

Until Dec 3rd, 44% off all Manning books, including Barcodes with iOS! Promo code: mobicftw
Our DNA is written in Objective-C
Jump

Category Archive for ‘Recipes’ rss

Smart App Banners

How often do you get annoyed by the following? You look up something on Google on your iPhone and you find an answer in a forum. When you click-through the search result the forum does not just show you what you were looking for, but it pops up a large annoying alert informing you that with their native app the reading experience would be so much nicer. And it does so even if you gave in some time earlier and had already installed the app.

Fortunately it has been announced that Apple will include a smart solution to this problem in iOS 6. Safari will gain the ability of automatically displaying such banners.

Read more

Cubed CoreAnimation Conundrum

Closed Box

One of the big mysteries of CoreAnimations are 3D transforms. You might have seen them used in popular apps like Flipboard (page turn) but there are hardly any good tutorials in how they actually work. In fact, you find only one from 2008 what was written when OS X Leopard was still around.

I blame that there are several things that are counterintuitive about using 3D transforms and perspective with CoreAnimation why not more people play with it … and then write up what they learned in some useful guide.

Session 421 Core Animation Essentials  from WWDC 2011 had an example of 6 squares that would animate into a three-dimensional box that the presenter could even rotate around. That inspired me to figure out how to do this as well, and with the help from several people on twitter I was successful.

Read more

Unit Tests Don’t Bite

You might have heard about the term “Test Driven Development”. The idea is – as I understand it – that for every problem you find in a component of your apps you create a Unit Test that fails. Then you fix the bug. The Test now passes. This can be carried further by writing your test cases even before you write any implementation code.

Especially when encapsulating your frequently-used code in static libraries or frameworks those unit tests can help save you a lot of grief. Imagine adding some nifty new feature to inadvertenly  introducing a bug that would break some other existing functionality. If you run the unit tests they would show you immediately that your change broke something.

In this blog post I’m summarizing a couple of things to help you get your own unit tests started.

Read more

A Taller iPhone is a Giraffe

Blogger Mark Gurman from 9to5Mac caused quite a stir when he showed screen shots showing that Apple had secretly updated the iOS Simulator to be able to deal with the rumored higher resolution of the next iPhone. His hack involved some nasty code injection that had previously been used to demo iPad on Retina resolution long before the iOS Simulator supported that.

The point of his article was that the main visible difference between the 5.x and 6.0 springboards when having more screen space available. On iOS 5 you always get 4 evenly spaced rows of icons there while on iOS 6 you will get an extra row of icons with no increase in spacing.

Because Mark did not give detailed instructions as he achieved the result (to “protect his sources”) developers all around started to investigate and Cédric Luthi beat everybody to the punch, revealing a method that is so simple, even I was able to follow it.

Read more

Multi-Context CoreData

When you start using CoreData for persisting your app data you start out with a single managed object context (MOC). This is how the templates in Xcode are set up if you put a checkmark next to “Use Core Data”.

Using CoreData in conjunction with NSFetchedResultsController greatly simplifies dealing with any sort of list of items which you would display in a table view.

There are two scenarios where you would want to branch out, that is, use multiple managed object contexts: 1) to simplify adding/editing new items and 2) to avoid blocking the UI. In this post I want to review the ways to set up your contexts to get you what you want.

Note: I am wrapping my head around this myself for the very first time. Please notify me via e-mail about errors that I might have made or where I am explaining something incorrectly.

Read more

You Don’t Need The Xcode “Command Line Tools”

When Apple made Xcode into its own app bundle it greatly simplified our lives as developers. This enabled incremental updates for the stable version can get from the app store. Also you get updates the same way as updates for other apps.

To cut down on file size Apple made several items optional downloads, like the documentation, older versions of Simulator or Command Line Tools. The latter you need if you are building stuff outside of Xcode, like Open Source projects. You know, bare knuckles, command line geekery.

However those tools are not needed if you want to say use svn or git. This article explains why.

Read more

Block-Based Action Sheet

I am extremely confident that Apple will introduce the ability to set blocks as actions for UIActionSheet (and UIAlertView) in iOS 6. Still, for exercise and because I want to support iOS 5 until iOS 6 is actually released, I set out to implement that.

When I tweeted about it, several people pointed me to existing implementations:

So I could have used one of these. BUT I like to understand the code I’m using and also I’m still learning, so better to solve the problem myself and talk about it. Also there are some implementation choices that I don’t agree with on these projects.

Read more

Associated Objects

There’s a neat feature in the Objective-C runtime that very few people know about and even less dare to use them. Undeservingly so, because they are very useful. I’m referring to Associated Objects.

In this recipe I’ll show you how to use them and have a great example of where I used them myself … for the first time.

Read more

Mine is Longer than Yours

Everybody is shortening URLs these days. While this saves spaces in Tweets it has several disadvantages for the user: you don’t see the domain that this link refers to. And you know that for certain clicks on the short URL are recorded and data-mined. Just have a look at my public bit.ly timeline. I check there often … pure vanity.

You might remember my hobby project Tweet Curator which allows the filtering of tweets that have certain domains. Now the next extension of this concept would be to also expand those pesky short URLs and use the referred domains for blocking too. There is NO hiding any more!

Read more

Let’s Bounce!

You probably have seen it hundreds of times, it’s become so natural to you that you probably don’t consciously notice it any more. I’m speaking of the bouncing of icons on the dock in OS X. The method how those pesky little critters (aka “Icons”) try to win your attention. Me! Me! ME!

This animation is probably the one you see the most in your day-to-day business working on code on a Mac. Yet I have never seen anybody using it in an iOS app. Why? It’s not that this animation is the sort of Clippy that everybody hopes to forget about some day. It’s something that well established and we know what it means.

When I asked around (on Twitter) and looked around (on Google) was only found a couple of “spring loaded” formulas, but nothing concrete that would enable me to get this animation added to my app. So I researched it and now I’m happy to present to you … 3 Methods of bouncing.

Read more