Tripping Through Xcode and iOS

I’ve been playing around with iOS and apps. As an experienced programmer with C/C++, Java, PHP, etc. Xcode and iOS is an “interesting” experience. I think there’s a certain level of discomfort when you are used to writing and seeing all your code vs. trusting the IDE to do a lot of the work for you. A great example is how Xcode handles “properties”.The IDE generates getters and setters at runtime? Yikes! Flip side is that it is simpler so I’m not necessarily saying this is bad, just different.

This post won’t be an eye opener or provide any “hidden gems” if you already are an iOS developer. I’m writing this post for myself to serve as a reference for the future – so that I can look up all the little things I forget about when I inevitably get drawn away from coding for a few weeks. I’ll forget what the “outline” view is or where the XYZ inspector is.I’m writing this post on a MacBook Pro – so the first thing to “remember” is “shift command 3” and “shift command 4”.

Xcode Menus and Buttons

It is kind of surprising that in the tutorials on the developer site there is no “cheat sheet” for what the heck all the little buttons and menus are, but there isn’t. Xcode has more little buttons and menus all over the place than you can possibly remember. Here’s a couple of screen shots of the two basic operating modes of Xcode – text editing and GUI editing:

In text mode the tree menu on the left is the “project navigator” and is the best way to find header files and code files. If you click once (not twice) on a .h or .m file it will be opened in the main editor. Click twice and it pops out into a separate editor. On the right hand side is the “utilities” menu. Use the buttons in the right top corner to fiddle with what shows up – or close the utilities stuff. In the utilities menu you can collapse the individual sections, but for some reason the last section for code snippets, objects and such will not auto-expand – dumb. You can make it bigger, but its hard to find and grab the handle.

Also over on the right you can open the “assistant” view – editor and versions. Versions is pretty cool in case you need to see what is changing over time.

To switch to “GUI” mode create or click on a storyboard. In this mode the “outline view” is located between the project navigator and the graphical mode. Clicking on objects in the outline view will change what is available in the utilities view on the right hand side. In particular it is handy to click on a view controller in the outline to see the connections in the utilities menu. The thing down below the view is called the “dock view” – you can also click on this to change what you see in the right hand utilities menu.

To make connections between GUI elements and code, you need to have the GUI view open, use the “assistant editor” to open a .m controller file, and then drag with CTRL click to the code file. Kind of goofy if you ask me to have to use the CTRL key. Why else would I drag a gui object to a code file?

Objective-C

My main programming language is C/C++ on Solaris, OS/2, Windows, and Linux. I’ve spent years with Java and would consider it my main programming language today. When I see a method like this:

(IBAction)changeGreeting:(id)sender {
    self.userName = self.textField.text;
    NSString *nameString = self.userName;
    if ([nameString length] == 0)
    {
        nameString = @ "World";
    }    
    NSString *greeting = [[NSString alloc] initWithFormat:@ "Hello, %@!", nameString];
    self.uiLabel.text = greeting;
}

I wonder why people think this is easy, understandable, or fun. The syntax just seems amazingly complex. Arrays inside brackets, the inconsistent “.” operator where the array length isn’t a method like array.length or array.length(), but is array length. Even just the assignment of the string greeting. In java it would be:

String greeting = new String ("Hello, " + nameString + "!");

I certainly can and will learn this, but really this isa major issue when looking at iOS vs. Android. No doubt iOS has the lead, but Java as a language is significantly easier to deal with. Xcode makes up for this in other places I think and in general as a platform its a bit more together as an ecosystem, but the ‘droid is catching up very quickly.

Control Option Command

Ok – I’m still IQ 10 on these buttons so remember:

  • Use command to cut/copy/paste
  • Control seems to be used like ALT on PCs – for application shortcuts – control click for the spelling corrector in Firefox for example.
  • option – this is a wildcard button from what I can tell. Not used much in Xcode.

Initialization – Accessor Methods and Synchronize
An initialization method is one of two places in which you should not use accessor methods to access properties (the other place is in a dealloc method). In the rest of your code, you should use accessor methods, such as self.name, to get or set an object’s properties.

Sounds Dreadful – By no Means

If you are ready to get an account and plaster me for my ignorance and silly thoughts, hold on a second. Xcode is cool – it works – and the docs are good. I’ll keep at it and like many of my posts keep updating this one as I go. One thing I do like about the whole iOS thing is that it works as advertised – so its just a matter of gaining experience and all should be good. I might even get used to this keyboard soon 🙂

1 Comment

  1. Beren (Post author)

    As I continue to learn:

    self is the same as this

    instead of a constructor – it is an initalizer (init)

    Use this to call methods (aka messages) on an object [myObject method];

    All this seems quite complex compared to Java or C#.

    Reply

Leave a Reply