My Blog List

Friday, October 8, 2010

Reviewing Concepts: Keeping our Time Travel Customers from getting Stranded

 Please CLICK ON THE PICTURE to enjoy the details 
of this Time Travel Portal 
and you probably thought it was just the Millbrae BART station


Sometimes I just skim through my review adding all kinds of useful features to my Time Traveler app. Other days, I have to start over a square 0.

I never did figure out what was hanging up my code. I just had to go back to the most basic working model and recreate it one element at at time.

There's days when it's just like that.

 .......
Version:1.0 StartHTML:0000000193 EndHTML:0000045221 StartFragment:0000002859 EndFragment:0000045185 SourceURL:file://localhost/Users/Laurel/Apps%20Learning/Journal%20Portal%20Counter.doc
  GDB was configured as "x86_64-apple-darwin".tty /dev/ttys001
Loading program into debugger…
Program loaded.
run
[Switching to process 3410]
Running…
We at PORTAL PILOTS, know that NOBODY wants to get trapped Before the Common Era!

                  We care about your safety.

Todays entrance count for this portal,  is 5

Debugger stopped.
Program exited with status value:0.

//  REbuilding TimeTravelSecurit Counter from a working model up
//   to find why it just hangs
//  classVariables.m page 109
//   used final choice in NewProject

//
// Time Travel Security Counter (bugs in version 1 I'm not finding)
// TTravSecurityCounter2

// Based on review of ideas page 108 Quick Start Objective C
// Every object in a class shares the same variable
//      AND if one object changes a class variable, that variable is changed for all objects
// I can create a class variable with the 'static' keyword
// 
// In this case, I'm using a class variable to keep track of the number of objects of a particular class my code creates
//     PORTAL PILOTS needs to keep track of the number of time travellers that ENTER their portals
//       to make sure that the proper number of travellers eventually EXIT those portals
//     so this seems like the perfect opportunity to practice using a class variable



// Class

#import <stdio.h>

#import <Foundation/Foundation.h>

@interface ThePortal: NSObject 

static int PortalEntranceCount;
+(int) getCount;

// Remember that when I use '+' for a method it's a 'class method'
//    class methods are methods I can execute using just the class name - no object is required
//       (page 84 of the Quick Start Book)

@end

// Methods

@implementation ThePortal
-(ThePortal*) init
// Here 'self' returns a pointer to the current object
//   on page 97 the book does this same thing
//  using a constructor to initialze the data in an object when you create an object

// Don't do what I did and confuse this with the OTHER class method (getCount)
// which we can execute using just the class name no object

{
    self = [super init];
    PortalEntranceCount++;
    return self;
   
}

+(int) getCount
{
    return PortalEntranceCount;
}

@end


int main(void)
{
    ThePortal *tc1 =[ThePortal new];

    ThePortal *tc2 =[ThePortal new];
    ThePortal *tc3 =[ThePortal new];
    ThePortal *tc4 =[ThePortal new];
    ThePortal *tc5 =[ThePortal new];

   
    printf("We at PORTAL PILOTS, know that NOBODY wants to get trapped Before the Common Era!\n \n");
    printf("\t \t We care about your safety. \n \n");
    //printf("\r \r We care about your safety. \n \n");
    //printf("\f \f We care about your safety. \n \n");

    printf("Todays entrance count for this portal,  is %i\n",[
                                                    ThePortal getCount]);
   
    return 0;
}

No comments:

Post a Comment