MacKuba

🍎 Kuba Suder's blog on Mac & iOS development

Hello, iPhone!

Categories: Cocoa, iPhone Comments: 0 comments

For the last few months, I’ve been spending a lot of time learning how to create apps for the Mac. Since I’m slowly starting to run out of new tutorials to read, I’ve decided to find myself something new to learn ;) Well, not completely new, actually, as a lot of that knowledge about Cocoa is going to be very useful.

I’m talking about iPhone development, of course. I bought an ebook about iPhone SDK from Pragmatic Programmers some time ago, which looks very promising, but I didn’t really start learning, because I wanted to get the iPhone development certificate first, and that took some time. You see, Apple’s platform is so damn open that to install even a “Hello world” on your own phone, you have to have a set of certificates from Apple, which they give you only after you register for an “iPhone developer program” which costs 100$. Really, guys, this is not how you attract developers to a platform… :\

Anyway, I got the certificates now, so I was finally able to run the “Hello world” on my phone :) Here’s a proof:

Hello iPhone (screenshot of my first application)

Read more »

The Dark Side of Cocoa

Categories: Cocoa Comments: 6 comments

An empty cup of cocoa
Photo by Alexander Staubo (CC)

Some time ago I wrote about all the things that I loved in the Cocoa framework. This time, I’d like to write a bit about the worse side of Cocoa – the things that annoy me, confuse me, and make me wonder who the hell came up with such an idea…

So, the things that dislike in Cocoa are:

  • Long names. I know, some people say that explicit is better than implicit, also, there are no namespaces in ObjC, which may explain some of that. But I’ve seen names which really belong on The Daily WTF. The longest I’ve found so far is “NSManagedObjectContextObjectsDidChangeNotification” (51 characters), and I’m worried that this might not be the longest one yet… Are you telling me a name that takes half a line in my editor is more readable than a short one? Seriously?

Read more »

Interface Builder tips and tricks

Categories: Cocoa, Mac Comments: 1 comment

I read Apple’s tutorial about Interface Builder this week. Most parts of it told about rather basic things and were quite boring, but I’ve learned several useful tricks from it. IB, like most of Apple’s applications, has lots of hidden features which aren’t obvious at first, and can only be found by experimenting, by accident or by reading about them somewhere. Here’s a few things that I’ve learned from the tutorial – some of them are such hidden features, some are just things that weren’t mentioned in any source I’d read before.

Read more »

Generating scaffold interfaces in Cocoa

Categories: Cocoa, Mac Comments: 0 comments

I discovered an interesting feature in Interface Builder a few days ago. It seems that it can generate a scaffolding UI for you based on a CoreData model. It works like this: first you have to design a data model in XCode model editor (which you have to do anyway if you want to use Core Data; if you don’t, it won’t make sense to draw the model only to get the scaffold UI, it will be faster to make it yourself…). Let’s say you have a model like in this picture:

XCode data model editor

Read more »

Missing controls in IB 3.1

Categories: Cocoa, Mac Comments: 0 comments

I’ve upgraded XCode and Interface Builder to version 3.1 recently (the update doesn’t appear in the system update, you have to download it manually, and it’s deceitfully hidden – you have to register at Apple’s developer portal to get it…). Today I’ve noticed that after the update some advanced controls were missing in IB. I had a vague memory of having a lot of additional categories of controls below the standard ones (some image views and Quicktime controls, for example), and I couldn’t find them there. This screenshot confirmed that I wasn’t imagining it. Not that I need them right now, but I might need them one day…

I was able to figure this out after a bit of googling, so I’m posting a solution here so that maybe I’ll save someone a little time. The thing is, for some reason IB forgot about some of its plugins; I think it has something to do with the “known issues” entry here in the release notes. Plugin files are located inside system frameworks. Anyway, to get them back, you need to go to IB’s Preferences → Plugins, and using the plus below the list add several framework bundles from /System/Library/Frameworks. The list more or less matches the list from the release notes, but you’ll have to experiment a bit (e.g. ImageKit and Quicktime plugins were hidden inside Quartz, and DiscRecording inside DiscRecordingUI). And that’s it, all advanced controls are available again.

Addicted to Cocoa

Categories: Cocoa Comments: 0 comments

A cup of cocoa
Photo by Sharyn Morrow (CC)

For the last several weeks, I’ve been learning a lot about ObjectiveC and Cocoa programming. It’s really addictive… I just can’t stop myself sometimes :) I’m reading the “RubyCocoa” book from Pragmatic Programmers and “Cocoa Programming for Mac OS X” by Aaron Hillegass. I also read some online tutorials – on Apple’s site, on Cocoa Dev Central (I love the illustrations there!), or elsewhere (check out my Cocoa bookmarks on Delicious for more).

The more I learn about Cocoa, the more I like it. It does have its problems which annoy me sometimes, but in general, it seems to make programming GUI applications really easy once you learn it. You can do really amazing things by calling just a few methods, and even better – you can create simple applications while not writing ANY CODE at all. So much can be done by connecting things in the Interface Builder, that sometimes you don’t need much more…

Here is a list of some of the things that I like in Cocoa:

Read more »

Learn Objective C in 30 minutes

Categories: Cocoa Comments: 36 comments

Recently I started thinking about writing something simple in Objective C – you know, that weird Apple language used for Mac programming… Not that I’m planning to switch from Ruby to ObjC – I rather treat this as a kind of a challenge (“what, I can’t learn this thing? of course I can!” :), besides, there is no language good for everything, and there are some low-level things that you really shouldn’t write in Ruby, like plugins for Finder, Quicklook, etc. Also, I remember reading somewhere that it’s good for a programmer to learn a new language each year – so, two years ago Python, last year Ruby, this year Objective C? :)

I googled for some quick tutorials, read a couple of them, and I realised that this language is really very simple, it just looks complicated because of that syntax and symbols; but once you start translating everything in your head, it all starts looking very familiar. Of course, it’s a different thing to understand what’s going on in someone’s code and to be able to write your own (for that, you also need to know some libraries…); but in this case, it’s pretty easy to go from “OMG WTF dude what’s this??” to a state when you can look at ObjC code and understand it as if it was written in Java or something else.

I made some notes while I was reading the tutorials, and I’m publishing them here so that maybe someone can learn this faster than I did – it’s just a “diff”, so I didn’t describe in detail anything that is obvious for someone who knows C, Java, Ruby, etc. You can treat this as a kind of poor man’s tutorial… Although I’m warning you that I spent a total of about one day looking at ObjC code, so some of what I’ve written here may not be completely correct, or may even be completely wrong. This is all based on what I read, not on my own experiences (which I have almost none). This product is provided without any warranty :)

Read more »

To Cocoa or not to Cocoa, that is the question...

Categories: Cocoa, Python, Ruby/Rails Comments: 0 comments

It seems that starting a blog was not the only stupid idea I had recently. I’m having more of those… For example, now I’m thinking about learning some Cocoa and writing some applications for the Mac :) I’ve been planning for some time to write something in Qt when I used Linux, but now it seems that although Qt has the advantage of being multi-platform, so I could write something that could be used on Windows, Linux and Mac, the disadvantage is that only a subset of Cocoa widgets are available in Qt; I couldn’t use some of the things I saw in native Mac applications, and because of that, my applications would be less “macish”…

Read more »