Our DNA is written in Objective-C

Category Archive for ‘Q&A’ rss

Writing a Book

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

Undefined Symbols

OC asks:

“I’m doing some Objective-C exercises from a Big Nerd Ranch book, and I’m getting these errors. I’m still pretty lost in terms of how to handle unexpected errors and stuff, so I would appreciate the help.”

I’m going into go into much greater depth here answering this question, because of “teaching a man to fish”, ya’know.

Read more

DTCoreText: Centering an Image

Amy Worall asks:

How do I centre an image in DTCoreText? I’m working with attributed strings not HTML. Any sample code?

In this blog post will answer this.

Read more

Using Custom Fonts with DTCoreText

Friend of DTCoreText Holger was having problems getting DTCoreText to use the bold font face of his custom font.

I want to take this opportunity to explain what the root cause for Holger’s problem was and what you need to know if you’re using custom fonts with DTCoreText.

Read more

Today’s Hero: CHEN Xian’an

I was having a problem in DTCoreText where the multi-byte sequence making up an Emoji would not get properly encoded by DTHTMLWriter. A quick peeking into NSHTMLWriter didn’t bring relief either, Apple is not encoding these characters, but leaves them unencoded.

Read more

Zarra on Locking

In my previous article dealing with Multi-Context Core Data I introduced a 3-context scheme that Marcus Zarra hat shown us in a back room at the 2012 NSConference.

Several people inquired about Locking, take for example Wim Fikkert:

Thanks for the great article. However, like Tom, I was wondering if the main context will not be blocked whenever you perform a save to disk with the persistent store. I am using the last design pattern, and I keep running into my app locking up. I have done some more searching and came across this article. Perhaps you can comment?

I don’t pretend to come anywhere close to being the Core Data expert that Zarra is, so I went straight to the horses mouth and asked him.

Read more