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

maya90

macrumors member
Original poster
Feb 16, 2011
58
3
I have just completed this tutorial... wrote all the code...
http://mobile.tutsplus.com/tutorials/iphone/learn-objective-c-day-4/

(only confusing thing: he doesn't say where this code goes:

Code:
-(void) dealloc {
    [vin release];
    [make release];
    [model release];
    [super dealloc];
}

(and in his src download it's nowhere to be found, either in SimpleCar.h, or SimpleCar.m..)

then at the end he says: "If you open up the console (Run > Console) and then build and run your app, you should see output similar to this:" etc

"then build and run"??? he doesn't say what the command is to build the app.. what did I miss here??????

I'm just assuming compiling one .m file is not the same as building an entire app, right?

this app consists of various files (SimpleCar.h, SimpleCar.m, & CarApp.m.. what is the command to build this app? (would it be something like

gcc SimpleCar.h SimpleCar.m CarApp.m??)​

I don't even know how many output files (compiled files) this is supposed to generate..)

thank you very much.....
 
That dealloc code goes in the .m file.

If you are using XCode, the build and run is a menu option
 
thank you.. it goes in SimpleCar.m, I assume? (b/c there's also CarApp.m..)

when go to "build" menu every item is disabled.. what do I have to have open (or closed) for it to work?

I can't believe he didn't explain any of this..

(one weird thing about Xcode IDE: if I close file(s) everything disappears, I no longer have any window open; if I open a .m or .h file again then only that file shows, the left sidebar is gone, as is the thingie on top with the list of files...)

thank you...
 
I think the part that you are missing is where you actually create a "project". Your SimpleCar.h and .m files need to be in a project, along with a bunch of support files which allow your project to be compiled and ran
 
here,
http://www.macresearch.org/tutorial_building_configure_make_projects_in_xcode

screenshots under 7) & 8) I don't have that top menu bar anymore, or that left sidebar where it says "Groups & Files", or that other thing on the right with the list of files for a project/app...

if I click on SimpleCar.h or SimpleCar.m in Finder Xcode opens it, but it's just the bare-bones text-editor window, it looks like TextWrangler or something... none of the other elements are showing....
 
here,
http://www.macresearch.org/tutorial_building_configure_make_projects_in_xcode

screenshots under 7) & 8) I don't have that top menu bar anymore, or that left sidebar where it says "Groups & Files", or that other thing on the right with the list of files for a project/app...

if I click on SimpleCar.h or SimpleCar.m in Finder Xcode opens it, but it's just the bare-bones text-editor window, it looks like TextWrangler or something... none of the other elements are showing....

Basically, at some point you closed your project and instead of reopening the project, you reopened one of the individual files of your project. You want to track down the XCode project file.

If you can't find it on your drive, with XCode open, pop open the File menu and click on "Open Recent Project". In that list should be your CarApp with the SimpleCar.h and SimpleCar.m files already included.
 
ok, I got it.. I have to open a PROJECT with Xcode to see all the stuff I was missing..

now I can do command 'build and run' however: am getting an error

expected ';' before '{' token​

( ';' before '{' ??? )

screenshot:
http://mayacove.com/xcode/ss_xcode_error.gif


(how do I clear errors so I know when I'm compiling errors are from latest build and not previous one??)

well, slowly getting there.... slowly but (hopefully) surely....;-)

thank you very much....
 
(how do I clear errors so I know when I'm compiling errors are from latest build and not previous one??)

well, slowly getting there.... slowly but (hopefully) surely....;-)

thank you very much....

I don't see anything immediately wrong with that. Click "Clean" under the Build menu and then "Build and Run". That should give you the current errors.

Also, you really don't need those get/set methods that you have set up there. You can just synthesize the variables, and XCode will automatically create them for you (though this might be a bit beyond where you are now, so maybe you should just leave it there)
 
ulbador,

once again, thank you very much for your help..

yes, I think I should leave those getter and setter methods for now....;-)
("synthesize" variables?? not sure what you mean by this... I guess I'll know soon enough.. am coming from Java, not familiar with C-languages, pointers, etc.. syntax very different...)

ok, corrected one obvious syntax error, built again, here's error I get now:
http://mayacove.com/xcode/ss_xcode_error.gif
not sure what this means.. I copied and pasted the code from the tutorial
(http://mobile.tutsplus.com/tutorials/iphone/learn-objective-c-day-4/)

thanks again..
 
Show us the code for your SimpleCar.h.

EDIT:
P.S. Also make sure that SimpleCar is part of your project and has been added to your target.
 
Last edited:
I hope it's ok to post it here:

Code:
#import <Cocoa/Cocoa.h>

@interface simpleCar : NSObject {
	NSString* make;
	NSString* model;
	NSNumber* vin;
}

// set methods
- (void) setVin:   (NSNumber*)newVin;
- (void) setMake:  (NSString*)newMake;
- (void) setModel: (NSString*)setModel;

// convenience method
- (void) setMake: (NSString*)newMake
        andModel: (NSString*)newModel;

//	get methods
- (NSString*) make;
- (NSString*) model;
- (NSNumber*) vin;
-----------

and, just in case, SimpleCar.m:

--------------

Code:
@implementation simpleCar

//	set methods
- (void) setVin: (NSNumber*)newVin {	
    [vin release];
    vin = [[NSNumber alloc] init];
    vin = newVin;
	}


- (void) setMake: (NSString*)newMake { 
	[make release];
	make = [[NSString alloc] initWithString:newMake];
}


- (void) setModel: (NSString*)newModel { 
	[model release];
	model = [[NSString alloc] initWithString:newModel];
}


//	convenience method
- (void) setMake: (NSString*)newMake 
		andModel: (NSString*)newModel { 
	
//	reuse our methods from earlier
	[self setMake:newMake];
	[self setModel:newModel];
} 

//	get methods
- (NSString*) make {
	return make;
}

- (NSString*) model {
	return model;
}


- (NSNumber*) vin {
	return vin;
}


-(void) dealloc {
    [vin release];
    [make release];
    [model release];
    [super dealloc];
}

@end
---------------

thank you dejo...
 
Last edited by a moderator:
I'm totally confused now.. towards the end of the page (after the 'debug' screenshot, under "Property and Synthesize" again, this is here,
http://mobile.tutsplus.com/tutorials/iphone/learn-objective-c-day-4/) he changes the code completely, for SimpleCar.h and for SimpleCar.m.. (and this relates to what ulbador was saying before re synthesizing variables..)

but I don't know what code goes where... this code,

Code:
#import "SimpleCar.h"  
  
@implementation SimpleCar  
  
@synthesize make, model, vin;  
  
- (void) setMake: (NSString*)newMake  
        andModel: (NSString*)newModel {  
  
    [self setMake:newMake];  
    [self setModel:newModel];  
  
}  

  
@end
(since it has "#import "SimpleCar.h" I assume it goes in SimpleCar.m?? but in SimpleCar.m before he had:

@interface SimpleCar : NSObject {

on top, and not

@implementation SimpleCar


and what is this? #import <cocoa cocoa.h="">??? he doesn't explain why he changed #import <Cocoa/Cocoa.h> to this....

so now am simply totally confused.. I don't think this tutorial is very good.. often he doesn't say in what file (.m or .h) his code goes...

thank you..

EDIT:

ok, I think I sorted it out..

however, I get even more errors now when I compile:

http://mayacove.com/xcode/ss_xcode_error.gif

thank you..
 
Last edited by a moderator:
and what is this? #import <cocoa cocoa.h="">??? he doesn't explain why he changed #import <Cocoa/Cocoa.h> to this....
He didn't need to. It makes no sense. Ignore that change.

so now am simply totally confused.. I don't think this tutorial is very good.. often he doesn't say in what file (.m or .h) his code goes...
Sounds like a good reason to abandon those tutorials to me. You should be able to find other, better-quality ones out there.
 
He didn't need to. It makes no sense. Ignore that change.


Sounds like a good reason to abandon those tutorials to me. You should be able to find other, better-quality ones out there.

yes of course.. I've never been a fan of online tutorials, I have always found them incomplete.. trying to decide what book(s) to purchase at amazon.. some possibilities:

http://www.amazon.com/Programming-O...=sr_1_2?s=books&ie=UTF8&qid=1298054704&sr=1-2

http://www.amazon.com/Objective-C-A...=sr_1_5?s=books&ie=UTF8&qid=1298054606&sr=1-5

http://www.amazon.com/Learn-Objecti...UTF8&coliid=I1QPSJQ4Z7T6TZ&colid=INL3I00WSKM5

http://www.amazon.com/Learn-Objecti...UTF8&coliid=I28IPL83QUD43D&colid=INL3I00WSKM5

(I hope all these links work.. I hate long links like this.. I don't think there's ever a programmatic need to make links this long..)

thank you..
 
As an Amazon Associate, MacRumors earns a commission from qualifying purchases made through links in this post.
Last edited:
As an Amazon Associate, MacRumors earns a commission from qualifying purchases made through links in this post.
Hi Maya90

I've taken a tutorial from Dan Walker (maybe at the DevCon conference last year). He's a good tutorial guy.

Patience my man ... I've climbed the Obj C hill myself. Got it now, but I got tangled up a few times. :)

If you hit the DOWNLOAD button in the first site that you linked to, you get the full project from Dan. I built and ran it out of the box ... worked perfectly.

I think you made the following errors that caused you grief:

1. The class is SimpleCar ... not simpleCar (case sensitive)

2. You worked directly from the sources first ... would have been better to launch his XCode project from the download. If that built and ran ok then you could have looked at the sources in the project and dissected them for understanding. I like to do one thing at a time (scientific method). Start with a project that works and try to replicate that project, i.e. create a new project, add sources, etc.

3. @synthesize xx, yy, zz is just a substitute for writing out the getter and setter functions yourself. @synthesize goes at the top of the class implementation file (.m) ... right after @implementation. In order to use @synthesize, you must declare variables with their properties in the class interface file (.h).

4. The dealloc method goes into the class implementation file (.m) somewhere below @implementation and before @end. I don't think it matters where in that file you put it.

Please let me know if you need any other help as you're climbing the obj c hill.

Books: Anything from the Big Nerd Ranch is good ... "IPhone Programming ... the Big Nerd Ranch Guide
also "Advanced iOS4 Programming" Maher Ali (read this one first)
 
Last edited:
ok.... I just did the same thing... build succeeded w/no problems.. however, I don't understand this, since there was no CarApp.m file (in article, http://mobile.tutsplus.com/tutorials/iphone/learn-objective-c-day-4/ he specif. mentions this file, under headline "Testing the Class"....)

thank you..

NOTE: everything after the ISBN/UPC/ASIN number is for tracking purposes. You can safely remove. e.g.

http://www.amazon.com/Programming-Objective-C-2-0-Stephen-Kochan/dp/0321566157

EDIT: Or even get rid of the title.

http://www.amazon.com/gp/product/0321566157

B


GREAT!! very good to know.... thank you....
 
Last edited by a moderator:
As an Amazon Associate, MacRumors earns a commission from qualifying purchases made through links in this post.
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.