Why won't this code run? (Total beginner)

Discussion in 'Mac Programming' started by mrat93, Jul 14, 2010.

  1. mrat93 macrumors 65816

    mrat93

    Joined:
    Dec 30, 2006
    #1
    First of all, please keep in mind that I am a TOTAL beginner to programming, hence why I bought "iPhone and iPad Apps for Absolute Beginners."

    I'm trying to create the first "Hello World" app in the book.

    I copied the following code from the book which is in the ViewController.m class:

    Code:
    #import "hello_world_1ViewController.h"
    
    @implementation hello_world_1ViewController
    - (IBAction)hello:(id)sendr{
    	label.text = @“Hello World!”;
    }
    
    However, I'm getting seven errors when trying to run it.

    Sorry for sounding like a complete idiot, but can anybody help me out?
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    1. Always post the errors you see. Copy and paste them. Accuracy is important.

    2. When you post a .m file, always post its corresponding .h file. Showing the .m alone is only half the story. The other half is the .h.

    3. Copying and pasting from ebooks can be risky. You have "curly" quotes in your posted code. These won't compile.
    http://en.wikipedia.org/wiki/Quotation_mark_glyphs

    4. When a book has an accompanying download of source files, always use it. This avoids problems arising from copying and pasting curly quotes.
    http://apress.com/book/downloadfile/4588

    Examples of curly and "straight" quotes, enlarged and hilited in red to make it easier to see the difference:
    Code:
    [SIZE="5"]label.text = @[COLOR="Red"]“[/COLOR]Hello World![COLOR="Red"]”[/COLOR];[/SIZE]
    
    Code:
    [SIZE="5"]label.text = @[COLOR="Red"]"[/COLOR]Hello World![COLOR="Red"]"[/COLOR];[/SIZE]
     
  3. PatrickCocoa macrumors 6502a

    Joined:
    Dec 2, 2008
    #3
    Not that you asked, but I disagree with your #3 in certain cases. I find typing the code to be a useful method of helping me learn (or at least think about) each line of code.

    For instance in this case, the original poster has learned that there's a difference between various quotes, and that that difference is important.
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    Typing the code is not copying and pasting.

    In my experience, someone typing code from a book (or ebook) will type in the straight quotes, because that's what's on the keyboard. Same thing for straight single-quote (apostrophe).

    I even see this when the character is the accent grave, which has a distinctly different meaning in, say, shell scripts, than does the straight single-quote.
     
  5. wjlafrance macrumors 6502

    Joined:
    Dec 23, 2009
    Location:
    Madison, WI
    #5
    This won't give you a compile error, but you spelled sendr [sic] wrong. :)
     
  6. Jayomat macrumors 6502a

    Jayomat

    Joined:
    Jan 10, 2009
    #6
    first guess: it's sender not sendr... while this is not all, most errors come up because you have errors before that.. so always check the FIRST error in your code!

    post you complete code, otherwise we cannot help you..
     

Share This Page