Help with Coding

Discussion in 'iOS Development' started by thund3r, Aug 15, 2009.

  1. thund3r

    thund3r Member

    Joined:
    Feb 8, 2009
    Messages:
    100
    Likes Received:
    0
    Device:
    iPad
    myFraction = [[Fraction alloc] init];

    I do not get anything that is being said on this. The book does explain that alloc means allocation and init means initial but i still do not get anything about what it exaclty does.

    And please explain in a easy way because I am not very good at English since im Japanese but I am trying my best to learn English.

    Thanks
  2. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    It allocates it a piece of memory in the iPhone OS.
  3. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Alloc means that you are allocating memory for the object. Init means that you are initializing the object (also intializes its ivars).
  4. thund3r

    thund3r Member

    Joined:
    Feb 8, 2009
    Messages:
    100
    Likes Received:
    0
    Device:
    iPad
    Whats the point of allocating it to the iPhone OS?
  5. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    I'm not sure if this is correct but try and think of it as if you're giving it a piece of RAM to use.
  6. thund3r

    thund3r Member

    Joined:
    Feb 8, 2009
    Messages:
    100
    Likes Received:
    0
    Device:
    iPad
    Ohh i got it after i put Skylars info with yours, Thanks.
  7. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Chicken is wrong. You're not giving it RAM to use, you're giving the object RAM to occupy. Basically, all our objects are is just a pointer to a block of RAM. That's why it's always SomeObject *variableName; instead of SomeObject variableName;.

    Initialization methods are equivalent to c++ constructors; while dealloc methods are equivalent to deconstructors. They are used to set up the object's variables etc.

    When you allocate an object, you are required to deallocate the object: release the memory.
  8. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S

Share This Page