Skip to main content

Posts

Showing posts from March, 2012

Spot the difference: instance methods and class methods in Xcode for iOS

In preparation for a forthcoming blogpost on self, super, polymorphism and inheritance in Xcode and iOS5, which has been inspired and informed by Matt Neuburg's book Programming iOS 5, I'm posting some sample code to illustrate the points that will be made. If you wish to experiment, then copy and paste this into your Xcode project.

Previous posts have mainly focused on instance methods, which we've used to manipulate objects. These are after all the most common type of methods we'll be calling. The other kind of method is the class method. The most common of which is the one used in the creation of instances: alloc.

We've also used yellowColor and blueColor they are class methods because they are called against UIColor.

An instance method is identified by the dash '-' that it begins with. Like so:


-(void)backgroundColorChange {     [selfsetBackgroundColor:[UIColorblueColor]]; }

Whereas a class method has a plus '+' sign at the beginning. Like this:


+…

A teacher's guide to Matt Neuburg's Programming iOS 5 (Part 3)

For part three of this guide on Matt Neuburg's book I'm going to advise you to ask your students to take a massive leap forwards to Chapter 10, which is called 'Cocoa Classes', and this connects very nicely with the last chapter your students read on 'Objective-C Classes'.

This is the point in the book where Neuburg launches us into some short examples, and it would be tempting and less work to reproduce his examples for your class. However, there is immediately a problem. Neuburg asks us to follow blindly his first example and that it will be explained in Chapter 15.

This is fine for a reader but too many unconnected wires are going to be left dangling for this to be the first example in a class. We need something that can easily be explained. I therefore suggest you use Chapter 10 as a loose framework but you simplify your examples even further so that your students, particularly in the first few examples know exactly what is happening in the code.

I personal…

Perspectives on the self in Xcode for iOS

In preparation for a forthcoming blogpost on self, super, polymorphism and inheritance in Xcode and iOS5, which has been inspired and informed by Matt Neuburg's book Programming iOS 5, I'm posting some sample code to illustrate the points that will be made. If you wish to experiment, then copy and paste this into your Xcode project.


When you are experimenting with methods and code in Xcode you will find yourself inside the ViewController.m file sending messages to self as a way of running your code from viewDidLoad, for example, and this can lead to confusion about what self really is and you can find yourself slipping into thinking of self as the file within which you are writing the code when in actual fact it is the instance of the object.

To explain this let's take a look at the viewDidLoad method of our ViewController.m file:


- (void)viewDidLoad {     [superviewDidLoad]; // Do any additional setup after loading the view, typically from a nib. SquareView *squareViewOne = …

A teacher's guide to Matt Neuburg's Programming iOS 5 (Part 2)

In the first part of this teacher's guide series to Matt Neuburg's book, I advised you to send your students away over the break to read chapters 2, 4 and 5. Now they have returned eager, if slightly overwhelmed, and wanting to learn more, gain clarity in their new knowledge and to begin making apps.


Convenient for us we've arrived at Chapter 6, 'Anatomy of an Xcode Project', which is all about using Xcode to create apps. However, the last thing that I would advise is a single lesson learning the Xcode program.


These students of yours are unlikely to have ever needed to consult a manual before for a GUI, and so it will come as a shock that they should be sat down and taught as if they had walked into a lesson on using Microsoft Office. So don't do it!


This doesn't mean that they won't need to be taught the ins and outs of the program, since it has greater complexity than even high end GUI programs like Adobe's range of Creative Suite tools. But you…

What's so great about Windows 8?

What's so great about Windows 8?

Ant: Metro.
Tony: What? I thought you were a committed Mac user.
Ant: I am.
Tony: So you think that Windows 8 will be the downfall of Microsoft?
Ant: No. Don't be ridiculous.
Tony: So if Metro is so great why wouldn't you want to use it?
Ant: I'm thinking as a developer not a user.
Tony: Huh?
Ant: Metro encourages and enables publishers to create the type of mobile apps that everyone loves on iOS and Android without expectations that legacy support is built in for XP, Vista or even Windows 7
Tony: The Gordian Knot is cut!
Ant: Slightly dramatic but yes.
Tony: But hasn't every tablet apart from the iPad failed?
Ant: Microsoft doesn't need to gain iPad size market share of the tablet market for Windows 8 to be relevant. Apps built for Windows 8 will work on the desktop and this is one way that people without tablets can access your publications - whatever electronic shape or form they take.
Tony: A bit like people being able to b…

How not to confuse super(class) and superview in Xcode for iOS

In preparation for a forthcoming blogpost on self, super, polymorphism and inheritance in Xcode and iOS5, which has been inspired and informed by Matt Neuburg's book Programming iOS 5, I'm posting some sample (commented) code to illustrate the points that will be made. If you wish to experiment, then copy and paste this into your Xcode project.


The thing that I wish to illustrate here is that the use of super and superview have two entirely different uses. Something that I had confused for quite a while, and which I've no doubt others will confuse too. This is because while the self keyword references the instance of an object, super is a reference to its superclass never its superview (as one might expect). The best piece of advice that I can give therefore is to always think of super as super(class) in your mind when you type it. In fact if you place the following line of code in you appName-prefix.pch file:


    #define superclass super

then you'll actually be able t…

Inheritance in Xcode for iOS (sample code)

In preparation for a forthcoming blogpost on self, super, polymorphism and inheritance in Xcode and iOS5, which has been inspired and informed by Matt Neuburg's book Programming iOS 5, I'm posting some sample (commented) code to illustrate the points that will be made. If you wish to experiment, then copy and paste this into your Xcode project.

For our inheritance example, this is the code contained within our initial view controller:
#import "ViewController.h"
#import "SquareView.h"
@interface ViewController ()
@end
@implementation ViewController : UIViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
SquareView *squareViewNew = [[SquareView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)]; // Creates a pointer to an instance of a SquareView object - note initWithFrame is inherited from UIView
[self.view addSubview:squareViewNew]; // Adds squareViewNew as subview to the view …

Thinking in Javascript but writing Objective-C (Xcode/iOS): From function to method

As a teaching exercise let's pretend we want to change a Javascript function into an Xcode method. Here's a simple Javascript function that takes whatever number we send it and returns that number +1: function addOne(number) { return number + 1; } Now what that would look like in Xcode (Objective-C): -(int)addOne:(int)number { return number + 1; } The internal statement is the same, and the name of the function/method (addOne) remains the same, as does the instance variable (number), but the punctuation has changed, 'function' has gone and those two (int) things are new. The first two things shouldn't worry you at this stage.

The (int)s, however, should worry you. They exist because with Xcode we have to tell it explicitly what a method is going to receive and what it is going to send back, whereas in Javascript we can send anything to a function and receive anything back. (Whether or not the Javascript will run successfully with what we send it is a diffe…

A teacher's guide to Matt Neuburg's Programming iOS 5 (Part 1)

In my previous post, I advised potential readers of Matt Neuburg's book to begin elsewhere, and to use this book as the second or third stage in their learning. In this post I place myself in the position of someone (perhaps a teacher) advising how to make the most out of this book on a first reading.


First, I would strongly advise anyone using this book as their initial inroad into Xcode and iOS 5 to start at Chapter 2, ignoring everything that precedes this. The first chapter for a newbie is a baptism of fire and the range of terms and promises of future explanations leaves one's head spinning to such an extent that many will be quickly turned off.
All one really needs to know on their first pass at this book, in order to skip the first chapter, is that the abbreviation K&R refers to a book about the C programming language, which is the precursor to Objective-C, the language used by Xcode.

The prefatory material meanwhile should also be set aside because the newbie is likel…

Programming languages with interactive online tutorials

Javascript
http://www.codecademy.com/

Python
http://www.trypython.org/

Ruby
http://www.tryruby.org

---------------------------------------------------------
Coffee Script
http://coffeescript.org/

JSON
http://braincast.nl/samples/jsoneditor/
http://jsoneditor.net/
http://www.jquery4u.com/json/10-online-json-tools/

JSON Select
http://jsonselect.org/#tryit

XML and XSLT
http://www.ladimolnar.com/JavaScriptTools/XSLTransform.aspx

HTML & CSS, XML, Browser Scripting, Server Scripting, Multimedia
http://www.w3schools.com/sitemap/default.asp#examples

With the exception of those sites below the dashed line these examples have tutorials placed alongside, and interact with, the user input. The Coffee Script site places examples and user input on separate pages, and the other examples have a similar level of separation.


I'll add others to this list as I discover them, but please feel free to add your own in the comments below.

Programming iOS 5 (Matt Neuburg) - an initial response the second time around

Programming iOS 5is the perfect guide to learning Xcode for developing iOS apps. Unfortunately for those starting from scratch or with only a knowledge of web languages to assist them the book is virtually impenetrable.

Hello world examples hold no currency for Neuburg, and so he belittles them. He also refuses to turn his programming guide into a cookbook for others to blindly follow. He insists on integrity and rigour instead.

While I agree entirely with Neuburg now I have reached the stage of understanding clearly his text - almost a year after beginning to experiment with Xcode, and attempting without success to make sense of Programming iOS 4 - this creates a gap that readers must cross before they are ready to understand this text. And reading the in-depth guide to C, as suggested by Neuburg, offers no solace.

How then do we ford this gap? One way is to watch Paul Hegarty's Stanford lectures on iTunes U. He gives examples and works through them clearly, but even these become…

Big but not scary: #pragma marks in Xcode (iOS)

I've been putting off finding out what #pragma marks are ever since noticing them. I presumed they were another complex area of the Xcode program. However, having now watched Paul Hegarty's lecture on UIVTableViews I know that they are a simple way of adding headings to your code.

You can change the text that follows the dash to whatever you like and also add your own using the same syntax:

    #pragma mark - This is a heading

The results of which divide up your list of methods with headings as shown in this screenshot: