Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Rossco

macrumors newbie
Original poster
Jun 15, 2009
2
0
Hi folks,

I'm not new to programming but I am new to programming in Objective-c (I come from a Java background).

I'm currently trying to wade my way through the iPhone development course that Stanford are running. I have managed to finish Assignment 3, and I'm looking to try and do the extra credit, however I'm having problems saving the state.

Looking online I could see recommendations for using 'applicationWillTerminate' in the app delegate. In order to save the state of the polygon I thought that the best thing to do would be to create an IBOutlet to the controller, so that the delegate can see the polygon object.

Code:
//  HelloPolyAppDelegate.h

#import <UIKit/UIKit.h>

@interface HelloPolyAppDelegate : NSObject <UIApplicationDelegate> {
	
    UIWindow *window;		
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

implementation file

Code:
//  HelloPolyAppDelegate.m

#import "HelloPolyAppDelegate.h"

@implementation HelloPolyAppDelegate

@synthesize window;

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    // Override point for customization after application launch
    [window makeKeyAndVisible];
}

- (void)dealloc {
    [window release];
    [super dealloc];
}


@end

The code above compiles and runs fine with no errors or warnings, but when I add add the following line in bold:

Code:
//  HelloPolyAppDelegate.h

#import <UIKit/UIKit.h>

@interface HelloPolyAppDelegate : NSObject <UIApplicationDelegate> {
	
    UIWindow *window;	
    [B]IBOutlet Controller *controller;[/B]
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

I get an error message under the import statement in the .m file:

error: syntax error before 'Controller'.

According to most sites that I have looked at to try and fix this problem, most have advised that there is something wrong with the header file, such as a bracket or semi-colon missing, but I just can't see it.

Xcode automatically recognizes and autocompletes when I begin to type 'Controller', so I don't think that it's a case that it can't see the Controller class.

Can anyone advise as to how this is happening?

Many thanks
 
It is because Controller is not a class. Check out the documentation, but it needs to be a UIViewController, UITabBarController, etc. I've found the auto-completion in XCode to be only marginally related to correctness :)
 
It is because Controller is not a class. Check out the documentation, but it needs to be a UIViewController, UITabBarController, etc. I've found the auto-completion in XCode to be only marginally related to correctness :)

Sorry I should have mentioned that I do have a class called 'Controller'. I'm not using a UIViewController, I have developed my own controller class to manipulate the polygon shape and the polygon view.

EDIT: Erm... I feel stupid now. I just imported my Controller class into the delegate and it's working fine now :S
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.