Results 1 to 3 of 3
  1. #1
    Objective-C .. I just don't get it

    Member Since
    May 15, 2009
    Posts
    1
    Objective-C .. I just don't get it
    I am having a really hard time moving to objective-c /cocoa in terms of the .h and .m files.

    I understand what they are, but I don't get what goes where.

    My biggest issues right now is

    how can I internalize variables for use inside a specific function
    PHP Code:
    -(void)afunctionImade{
    var1 1;

    var2 5;


    var3 var1 var2;
    return 
    var3;

    if i try to build and go on this i get the error

    "var1 undeclared (first use in this function)"
    and so on for each variable.

    I ONLY want to use those vars inside of that exact function, I don't want them to be accessed anywhere else. Why do I have to declare it somewhere? Or how do i declare it so that is it only used inside that function?

    Thanks in advance,
    Chris

  2. #2
    Objective-C .. I just don't get it
    Aptmunich's Avatar
    Member Since
    Mar 09, 2004
    Location
    Munich
    Posts
    9,073
    Specs:
    Aluminium Macbook 2.4 Ghz 4GB RAM, SSD 24" Samsung Display, iPhone 4, iPad 2
    It doesn't look as though you've defined an object type for your variables...
    You'd need to write:
    Code:
    int var1 = 1;
    (Unlike PHP, you can't use variables without types like that in Objective-C - or many other languages).

    Once declared, you can access the variable directly:

    Code:
    var1 = 5*12;

  3. #3
    Objective-C .. I just don't get it

    Member Since
    Mar 15, 2007
    Posts
    161
    Specs:
    17" MacBook Pro, 2.33GHz C2D, 2GB RAM
    To add to what Aptmunich said, your problem here seems to have been more of a lack of understanding of the C language rather than with Objective-C. You may want to take a step back and find some C language tutorials or books to dive into and gain an understanding of before you start adding Objective-C's extensions to the mix.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Objective-C help
    By bikka in forum OS X - Development and Darwin
    Replies: 22
    Last Post: 05-27-2014, 02:56 PM
  2. Objective-C
    By eddielee in forum OS X - Development and Darwin
    Replies: 2
    Last Post: 02-02-2011, 12:27 PM
  3. Objective C Books that don't need C knowledge
    By J-Mak in forum OS X - Development and Darwin
    Replies: 4
    Last Post: 10-27-2009, 12:31 AM
  4. Objective-C
    By AstralZenith in forum OS X - Development and Darwin
    Replies: 13
    Last Post: 03-09-2003, 10:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •