Results 1 to 3 of 3
  1. #1

    Member Since
    May 15, 2009
    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:
    var1 1;

    var2 5;

    var3 var1 var2;

    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,

  2. #2

    Aptmunich's Avatar
    Member Since
    Mar 09, 2004
    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:
    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:

    var1 = 5*12;

  3. #3

    Member Since
    Mar 15, 2007
    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. Hijack Safari Scammers: Don't pay them don't call restart your computer and more
    By johnodd4 in forum Internet, Networking, and Wireless
    Replies: 0
    Last Post: 04-15-2015, 08:16 AM
  2. Objective-C help
    By bikka in forum macOS - Development and Darwin
    Replies: 22
    Last Post: 05-27-2014, 02:56 PM
  3. Objective-C
    By eddielee in forum macOS - Development and Darwin
    Replies: 2
    Last Post: 02-02-2011, 12:27 PM
  4. Objective C Books that don't need C knowledge
    By J-Mak in forum macOS - Development and Darwin
    Replies: 4
    Last Post: 10-27-2009, 12:31 AM
  5. Objective-C
    By AstralZenith in forum macOS - 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