building an app

Discussion in 'iOS Programming' started by maya90, Feb 17, 2011.

  1. maya90 macrumors member

    Joined:
    Feb 16, 2011
    #1
    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.....
     
  2. ulbador macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #2
    That dealloc code goes in the .m file.

    If you are using XCode, the build and run is a menu option
     
  3. maya90 thread starter macrumors member

    Joined:
    Feb 16, 2011
    #3
    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...
     
  4. ulbador macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #4
    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
     
  5. maya90 thread starter macrumors member

    Joined:
    Feb 16, 2011
    #5
  6. maya90 thread starter macrumors member

    Joined:
    Feb 16, 2011
    #6
    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....
     
  7. ulbador macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #7
    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.
     
  8. maya90 thread starter macrumors member

    Joined:
    Feb 16, 2011
    #8
    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....
     
  9. ulbador macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #9
    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)
     
  10. maya90 thread starter macrumors member

    Joined:
    Feb 16, 2011
    #10
    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..
     
  11. dejo, Feb 18, 2011
    Last edited: Feb 18, 2011

    dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #11
    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.
     
  12. maya90, Feb 18, 2011
    Last edited by a moderator: Feb 18, 2011

    maya90 thread starter macrumors member

    Joined:
    Feb 16, 2011
    #12
    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...
     
  13. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #13
    Objective-C is case-sensitive. simpleCar is not the same thing as SimpleCar.
     
  14. maya90, Feb 18, 2011
    Last edited by a moderator: Feb 18, 2011

    maya90 thread starter macrumors member

    Joined:
    Feb 16, 2011
    #14
    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..
     
  15. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #15
    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.
     
  16. maya90 thread starter macrumors member

    Joined:
    Feb 16, 2011
    #16
    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..
     
  17. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #17
    Stephen Kochan's book is highly-regarded (and the author is a member of these very forums).
     
  18. balamw, Feb 18, 2011
    Last edited: Feb 18, 2011

    balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #18
  19. multinode, Feb 18, 2011
    Last edited: Feb 18, 2011

    multinode macrumors regular

    Joined:
    Feb 4, 2011
    #19
    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)
     
  20. maya90, Feb 27, 2011
    Last edited by a moderator: Feb 28, 2011

    maya90 thread starter macrumors member

    Joined:
    Feb 16, 2011
    #20
    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..


    GREAT!! very good to know.... thank you....
     

Share This Page