Compatible with Older XCode Versions? (3.2)


#1

Hi,

I’m trying to follow the Ch1 tutorial to make the Quiz app but I am encountering an error when running the app:

It builds but doesnt call the the initWithNibName method. From browsing some of the other topics here, I’ve deduced that this can be caused by the ‘use storyboards’ box being unchecked when creating the project.

My problem is, I am using XCode 3.2.6 on Snow Leopard, and when creating a new View project, it never goes to the screen with the ‘use storyboards’ checkbox. Instead it just asks where/what to name my project and then it jumps right to the main XCode screen, I never see any screen with ‘use storyboard’.

Has anyone else solved this or have any suggestions?


#2

You have to upgrade, there is no backwards support.


#3

It is doable, but you will need to make some slight modifications to the code in the book.

There are no storyboards, but in examples where you are not specifically using the storyboard feature (like just making one XIB file), you can start with a View Based Application.

I was able to get the Quiz app up and running without much problem, but initWithNibName:bundle: was not being called automatically so none of the question/answer values were be initialized.

A little searching led me to initWithCoder: which is apparently called by default when the view is loaded from the NIB.

I did not want to move everything from initWithNibName:bundle: so I overwrote initWithCoder: and had it call initWithNibName:bundle:

@implementation QuizViewController

- (id)initWithCoder:(NSCoder *)aDecoder
{
	return [self initWithNibName:@"QuizViewController" bundle:nil];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
	NSLog(@"initWithNibName called");
	
	self =[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
	if (self) {
		// Create two arrays and make pointers to them
		questions = [[NSMutableArray alloc] init];
		answers = [[NSMutableArray alloc] init];
		
		// add questions and answer to the arrays
		[questions addObject:@"What is 7 + 7?"];
		[answers addObject:@"14"];
		
		[questions addObject:@"What is the capital of Vermont?"];
		[answers addObject:@"Montpelier"];
		
		[questions addObject:@"From what is cognac made"];
		[answers addObject:@"Grapes"];
		
	}
	
	// return the address to the new object
	return self;
}

...

That seemed to get it working without any other changes.

Also note that there is no ARC in older versions of XCode, so you need to do your own deallocating