BuySellAds.com

If you like my tutorials, you will love my book . It is chockful of advanced programming techniques and the only comprehensive barcode reference for serious iOS developers.
Our DNA is written in Objective-C
Jump

Category Archive for ‘Recipes’ rss

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

Twitter.framework Tutorial

I have this idea for an app that I would totally use myself. You know I started XcodeJobs.com and the @XcodeJobs twitter feed to go with it to have a channel to retweet all the iOS-related job offerings that flow before my very eyes. For the site I’ve been talking to people to create a login for themselves and post their jobs self-servingly. For the twitter feed I’ve been using the Twitter search features with a variety of search terms to find tweets where company owners of the developers themselves are tweeting about job postings.

Now the reality of the matter is that most of all Tweets are from recruiters, agencies, job sites and other kinds of services that a self-respecting iOS developer does not want anything to do with. So right now I’m manually filtering tweets. There are a variety of criteria that I want to be able to combine to end up at the real good retweet-worthy tweets.

Read more

Resource Bundles

When shrink-wrapping your code for later reuse you inadvertenly will come into the situation that you have some resources (strings, XIBs, images et al) in your project that you also want to be reused. So what do you do?

If only we had frameworks on iOS … then we could bundle the resources together with the code in a framework. But Apple does not want us to compile frameworks in Xcode since these could potentially contain code downloaded after the app review process.

Popular projects like ShareKit or the Facebook iOS SDK have approached this dilemma by simply putting all resources into a folder, giving it the “.bundle” extension and instruct users of their SDK to also add this bundle to the “Copy Bundle Resources” step of their respective apps.

In this here blog post I will show you a smarter way.

Read more

Creating a CoreData Model in Code

I’m working on my own file and image cache that uses CoreData for storage. The same way that NSURLCache is doing it, but with some optimizations that I know and understand. So I created DTDownloadCache and got it all working, but there was one minor thing that I didn’t like: The usual method of creating a CoreData entity model is by the entity editor built into Xcode.

This meant that I had to include the .datamodeld file in apps using this. But I didn’t want to have to create a resource bundle just for this single file as you would have to do if you keep your reusable code in static libraries. Ugh!

Fortunately there is a way how you can create a static model entirely in code so that you can make use of CoreData without having to ship an XML description of the model.

Read more