Kochan - Programming in Objective-C 2.0

Discussion in 'iOS Programming' started by Ja Di ksw, Jan 4, 2011.

  1. Ja Di ksw macrumors 65816

    Ja Di ksw

    Joined:
    Apr 9, 2003
    #1
    I just bought Kochan's book, but right away it doesn't match up with my Xcode and I can't figure out where to go. The very first project it has says to get a new project and go to "Command Line Utility," but that's nowhere in my Xcode. It only has Application, Framework & Library, Application Plug-in, and Other (under Mac OS X). Any ideas? I'm using v. 3.2.5
     
  2. Tonsko macrumors 6502

    Tonsko

    Joined:
    Aug 19, 2010
    #2
    Xcode has changed where it keeps some templates as versions have been updated. Make sure you went for 'New Project' rather than 'New File' and click on 'Application' and then on the right there's 'Command Line Tool' - described as 'This project builds a command line tool written in C'. I suspect that is what you're after.
     
  3. Ja Di ksw thread starter macrumors 65816

    Ja Di ksw

    Joined:
    Apr 9, 2003
    #3
    It seems like this book is worthless, then. I just did what you said and entered in it's first code, got over a thousand errors. Went back and took out where he has #import <Foundation/Foundation.h> and left it as #include <stdio.h> as Xcode had it already, and it still gave me 6 errors and one warning. Double checked the code he said to write and it's all exactly the same.
     
  4. Sykte macrumors regular

    Joined:
    Aug 26, 2010
    #4
    Do not dismiss the book yet, it has great content and very well layed out. Post your errors/warnings!
     
  5. Tonsko macrumors 6502

    Tonsko

    Joined:
    Aug 19, 2010
    #5
    Can you cut and paste the code that you tried to compile? Use the [ code ][ /code ] tags (w/out spaces).
     
  6. Ja Di ksw thread starter macrumors 65816

    Ja Di ksw

    Joined:
    Apr 9, 2003
    #7
    I'm a little wary of always having to come back here for every single code, but here's the code from the book:
    Code:
    #import <Foundation/Foundation.h>
    
    int main (int argc, const char * argv [])
    {
    	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc]
    								init];
    	NSLog (@"Programming is fun!");
    	[pool drain];
    	return 0;
    }
    
    And it had tons of errors. Over a thousand. I changed
    Code:
    #import <Foundation/Foundation.h>
    
    to
    Code:
    #include <stdio.h>
    
    and now it only has 6, and one warning.

    The warnings are:
    (first line after { )
    'NSAutoreleasePool' undeclared
    'pool' undeclared
    Expected expression before '[' token
    (next line)
    Expected ']' before 'init'
    (next line)
    Expected expression before '@' token
    warning: Implicit declaration of function 'NSLog'
    (next line)
    Expected expression before '[' token

    So, yeah, that's a crazy amount of errors for such a tiny script, makes me a little untrusting of this book right now. Or am I making some big type and not seeing it?
     
  7. ulbador macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #8
    I'm not sure which "template" you used to create the project. This code is EXACTLY what you get when you create a new XCode project using New Project + "Application/Command Line Tool" with the type set to "Foundation". So it definitely works.

    Your problem is that your project doesn't have some key framework or library linked in with it, so you are experiencing a ton of errors in the external libraries that you are trying to use. Start over with the project and make sure you set it up correctly initially:

    New Project
    Click Application under Max OS X
    Click Command Line Tool
    Make sure the Type dropdown is set to "Foundation"

    Create the project.
     
  8. ZacUSNYR macrumors regular

    Joined:
    Feb 1, 2008
    #9
    I don't have a problem following the book, things are in different places but the examples worked. Check out the book's forum for some of the changes.
     
  9. Tonsko macrumors 6502

    Tonsko

    Joined:
    Aug 19, 2010
    #10
    This is the exact answer. Without having access to the book, I didn't realise (i.e. didn't twig about <foundation.h>) that you would need to change the template type. I've just tried it and it works flawlessly. Remember to have the console open so that you can see your results (Shift-Cmd-R).
     
  10. Ja Di ksw thread starter macrumors 65816

    Ja Di ksw

    Joined:
    Apr 9, 2003
    #11
    Success....kind of. It was definitely not changing the type dropdown to Foundation that was the problem. It now says in the bottom right "Succeeded" when I try to Build and Run it. However, there's no output. Isn't a small window suppose to open up with the words I put in?
     
  11. ulbador macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #12
    See the first quote.. Since you just created a console application, you have to open the console output window to see the results.-
     
  12. Ja Di ksw thread starter macrumors 65816

    Ja Di ksw

    Joined:
    Apr 9, 2003
  13. WG.Dave macrumors newbie

    Joined:
    Jan 5, 2011
    #14
    Console Window?

    I lived the exact same confusion tonight with the Kochan book.

    My issue is that I can't find the console window for the output. I checked the debug folder under the project, but I got a static terminal output that doesn't appear to update with different runs of the code, (for example, I changed the text to, "Hello Cruel World").

    Is there not a "live" I/O console window? I feel like an absolute moron not being able to locate it.

    Thanks in advance,

    David
     
  14. WG.Dave macrumors newbie

    Joined:
    Jan 5, 2011
    #15
    Console Window Located!

    Nothing like finding the proper answer (cmd-shift-r) moments after posting - I'd been using the wrong key sequence. Time for bed, sigh. Sorry all.
     

Share This Page