Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Member classes and "messaging?"

MurphyMurphy Posts: 60Registered Users
There is a class named AdventurePiece, I create a pointer to that class named failPiece, then I allocate memory for it and initializes it´s variables.

But these firstChoice, secondChoice & so on.. what are they? I know they are member classses declared and implemented in AdventurePiece (*.h and *.m) But what is this I am doing here exactly called? I create a pointer to object named failPiece and then I set the values of these member classes - what is this I am doing here called?

  AdventurePiece *failPiece = [[AdventurePiece alloc] initWithMessage:
@\"Cutting the blue wire begins a chain reaction - omg that is bad. Like really bad..Kaboom! What went wrong!?!\"
firstChoice:@\"Too Bad\" secondChoice:nil firstPiece:nil secondPiece:nil isEnd:YES];
Post edited by Murphy on

Replies

  • Duncan CDuncan C Posts: 8,021Tutorial Authors, Registered Users
    Murphy;439930 said:
    There is a class named AdventurePiece, I create a pointer to that class named failPiece, then I allocate memory for it and initializes it´s variables.

    But these firstChoice, secondChoice & so on.. what are they? I know they are member classses declared and implemented in AdventurePiece (*.h and *.m) But what is this I am doing here exactly called? I create a pointer to object named failPiece and then I set the values of these member classes - what is this I am doing here called?

      AdventurePiece *failPiece = [[AdventurePiece alloc] initWithMessage:
    @\"Cutting the blue wire begins a chain reaction - omg that is bad. Like really bad..Kaboom! What went wrong!?!\"
    firstChoice:@\"Too Bad\" secondChoice:nil firstPiece:nil secondPiece:nil isEnd:YES];
    You need to read up on basic Objective C. fistPiece, secondPiece, etc, are not "member classes." That term is not used in Objective C. It would be a bit like calling something a "foul strike" in baseball.

    I suggest this link as a starting point:

    https://developer.apple.com/library/ios/#referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/_index.html

    In a nutshell:

    Creating an objective C object is a 2 step process. You use alloc to create the storage for an object. You then send an init message to the newly allocated object to get it to set itself up for use. You must send an init method to every object before you can use it.

    Init methods come in different flavors. Some init methods don't take any parameters. Some take one or more.

    When you call an init method with multiple parameters, you are providing extra information that is used by the init method to set up the new object. How those parameters are used depends on the object and what the particular init method does.

    In your case, you are calling an init method initWithMessage:firstChoice:secondChoice:firstPice:secondPiece:isEnd:

    It looks like it takes a message string, 2 choice strings, 2 piece objects, and a BOOL value.

    The header for that class should include information about how the different parameters are used.
    Regards,

    Duncan C
    WareTo

    mug

    Animated GIF created with Face Dancer, available for free in the app store.
  • MurphyMurphy Posts: 60Registered Users
    In that document, what I refer to is in one place called member variable declaration.

    I find it a fitting name when declaring a data type or object inside a class - cause it becomes a member of that class. It´s just how my mind organizes these concepts wich are still a bit abstract to me. But getting there.

    So.. I understand that the firstChoice secondChoice etc... is a part of initWithMessage method, makes sense.
  • Duncan CDuncan C Posts: 8,021Tutorial Authors, Registered Users
    Murphy;439953 said:
    In that document, what I refer to is in one place called member variable declaration.

    I find it a fitting name when declaring a data type or object inside a class - cause it becomes a member of that class. It´s just how my mind organizes these concepts wich are still a bit abstract to me. But getting there.

    So.. I understand that the firstChoice secondChoice etc... is a part of initWithMessage method, makes sense.
    Member variables, or instance variables, as I prefer to call them, are variables that belong to an instance of a class.

    The variables do not become a "member of that class". The term member means something very specific in Object Oriented programming, and you are using it totally wrong.

    You are going to get very confused if you think of it that way. A member of a class is an INSTANCE of a class.

    Imagine a car class.

    You call the car factory and ask for a car. You ask for a blue convertible with a 6 cylinder engine. The settings you ask for are parameters to the init method. The car factory creates an instance of a car object (or a member of the car class) and passes it back to you. It installs the settings you provide into the instance variables of that car. Somebody else's car will have different options, so another car will have different values for it's instance variables.

    There might also be instance variables for the amount of gas in the tank, the setting on the radio, etc. The CD player might also have a CD object installed in it. (A "has a" relationship", where the car's CD player "has a" CD).
    Regards,

    Duncan C
    WareTo

    mug

    Animated GIF created with Face Dancer, available for free in the app store.
Sign In or Register to comment.