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

Category Archive for ‘Q&A’ rss

Keychain Management Revamped

For the past several years I have been using an ugly hacked together class AccountManager in several projects for saving and retrieving generic passwords on the keychain. A couple of months ago I finally got around to replacing this with a well-designed thought-through component, DTKeychain, which works equally well on iOS and OS X.

Read more

Square-Cropping Images

Christian asks:

How would you – most elegantly – crop out the center square of an image, preserving the aspect ratio and output the image with a given size?

That’s a good question. There is a “classic” and a “modern” method to achieving this.

Read more

Should I switch to Swift?

Angelina asks:

I was very surprised when I heard about Swift.  I was curious what your thoughts are about Swift and phasing out Objective-C specifically since you are in the process of writing the Barcodes book.  Are you going to update your book to use Swift instead of Objective-C?

Read more

Q&A: Seconds Since my Birthday

Julia asks:

How do I get Objective-C to display the number of seconds since my birth?

When you often gnaw on complex and frustrating questions – like I often do – it is rather refreshing to work out a good answer to such a simple question.

Read more

Updating CocoaPods

CocoaPods is being under constant development, and as the zero as major version number suggests, it is still in unstable status. So you should only be mildly surprised if calling the pod command outputs that a newer version is available. Here are some tricks for updating.

Read more

Writing a Book

Antique Typewriter

A couple of months ago a publisher contacted me about writing a book. I have written a lot in my lifetime, blogging in general on my German-language personal blog and later on my Cocoa development blog Cocoanetics. But of course I’ve never written something spanning more than a couple of pages.

Like everybody who likes to write I’ve toyed with the idea, but not knowing about what is involved in creating a technical book I shied away from it. I was assuming that all those book authors have to take time off their normal jobs for writing. I couldn’t imagine exclusively writing for 6 months and not having time for my regular development interests.

But then there was this contact who took the time to walk me through the initial steps toward my first book contract.

Read more

Don’t Cross The Streams

Like most people I could get buy blissfully without dealing too much with Auto Layout. But there are layout-heavy scenarios where you start having the feeling that they might be much easier to solve using auto layout than by setting autoresizing masks (aka “struts and springs”).

One such example is the layout of controls in an inspector panel where I laid out the controls distanced from each other with layout constraints in Interface Builder. Architecture-wise I am using such an “inspector palette” in a DMInspectorPalette which gives me several collapsible sections. These are contained in a NSTabView (using DMTabBar as header) to get multiple inspectors laid out like in Xcode. And these are the right-most view in an NSSplitView to allow resizing of the inspector panel.

I was having some issues with that beginning with 10.9 which I’d like to document here.

Read more

-fobj-arc is not supported on platforms using the legacy runtime

The Cocoanaut asked on Twitter:

“Does anybody know what this error means? (compiled on a white MacBook with 10.7.5 and Xcode 4.6.3)”

He attached this screenshot:

-fobjc-arc not supported

I’ve been seeing this error quite often lately and so I’d like to document my answer for posteriority.

Read more

TopLayoutGuide 97 Pixels?!

When implementing iOS 7 support for a client’s app I got a result that might stump even seasoned Cocoa programmers.

On iOS 7 views generally go behind translucent bars. To still get your views aligned correctly – when creating them in code – you have to get the responsible view controller’s top and bottom layout guides.

Those get set sometime before viewWillLayoutSubviews and I found it useful to add a viewInset property to the view controller’s base view. Setting this would setNeedsLayout and then you can rearrange the subviews according to the new insets in layoutSubviews.

Read more

Implicit IVAR Synthesis

Apple recently added the ability for Xcode to automatically create instance variables for you. This means you no longer need to add an @synthesize for each property you create.

But does it really do that always, or are there scenarios where no _ivar is needed? Are there situations wehre you do need an explicit synthesis? For example what about properties which are just passing through values to a sub-object?

I wanted to know, so I experimented a bit. I even filed a Radar with Apple for clarification which came back with a good explanation.

Read more