My Blog List

Tuesday, December 7, 2010

Hey Buddy - Some Input Would be Nice Here!

Version:1.0 StartHTML:0000000187 EndHTML:0000040872 StartFragment:0000002853 EndFragment:0000040836 SourceURL:file://localhost/Users/Laurel/Apps%20Learning/JournalTravelToInput.doc
Though I won’t be scanning for input this way (I think it’s done with scripting), I really don’t like hard coding data values in. It just BUGS me. So I wanted to see how to accept user input. It wasn’t in my Holzner Quick Start Objective C book at all. That made me feel like I was working in some kind of closed system. Output yes – but never any input!

Several bugs later, all of which reinforced for me that abundant practice with basic syntax is always valuable, I am accepting and using user input in this console-like fashion.

The book that I found scanf in is Programming in Objective-C 2.0 by Stephen G. Kochan from my public library.



Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys001
Loading program into debugger…
Program loaded.
run
[Switching to process 1126]
Running…
2010-12-07 21:43:28.187 TTravINPUTYearsDraft1[1126:a0f] What year do you want to travel to?
1893
1893 is a great travel destination!
  .... 
 Consider purchasing travel INSURANCE for your trip to 1893
Please proceed to ticketing for your trip from the year 2010 to the year 1893
Thank you for selecting PORTAL PILOTS for your time travel needs!

Debugger stopped.
Program exited with status value:0.


// TTravINPUTYearsDraft1
//  Let's see if we can share .h and .m with another project
//  I opened that project up
//  NOPE need my own
// BASED ON TTravelToAndFrom
// Based on review of ideas page 92 Quick Start Objective C


#include "TTravINPUTDraft1.h"

#include <stdio.h>

#import <Foundation/Foundation.h>



//Main

int main (void) {
   
    // instantiate the objectPortal Time Travel Portal
   
    TravelPeriod *objectPortal = [TravelPeriod new];
   
    //int n, number, triangularNumber;
   
    int year1Input;
    NSLog(@"What year do you want to travel to?\n");
   
    scanf ("%i", &year1Input);
     printf("%i is a great travel destination!\n", year1Input);
           
    printf ("\f .... \f Consider purchasing travel INSURANCE for your trip to %i \n", year1Input);
   
    //[objectPortal setYears:2010 second:1893];
    [objectPortal setYears:2010 second:year1Input];

    printf("Please proceed to ticketing for your trip from the year %i ", [objectPortal yearValue1]);
    printf("to the year %i\n", [objectPortal yearValue2]);
    printf("Thank you for selecting PORTAL PILOTS for your time travel needs!\n");
    return 0;
}

Tuesday, November 16, 2010

Over the Edge of Time: Accessing Nil!

    
OR

Why you never want to complain about waiting in the airport 
while they do a
little maintenance

The Well-Behaved Version

There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys000
Loading program into debugger…
Program loaded.
run
[Switching to process 31280]
Portal Pilots Maintenance Flight. Scanning for UNIQUE Time Portals
portals[0] = bridge
portals[1] = creek
portals[2] = path
portals[3] = alley
Running…

Debugger stopped.
Program exited with status value:0.

But Wait!

HERE’S WHAT HAPPENS WHEN THE ARCH-ENEMY OF PORTAL PILOTS MANAGES TO GET HIRED ONTO THE DEVELOPMENT STAFF


(just tought I'd try to access nil and see where it took me!)

// If I ever want to totally gum up the works, I'll make sure to try to access past the end of the array!


Portal Pilots Maintenance Flight. Scanning for UNIQUE Time Portals
portals[0] = bridge
portals[1] = creek
portals[2] = path
portals[3] = alley
2010-11-16 12:14:54.431 encounterPortals[31239:a0f] *** __NSAutoreleaseNoPool(): Object 0x10010cce0 of class NSCFString autoreleased with no pool in place - just leaking
2010-11-16 12:14:54.433 encounterPortals[31239:a0f] *** __NSAutoreleaseNoPool(): Object 0x1001107d0 of class NSCFString autoreleased with no pool in place - just leaking
2010-11-16 12:14:54.433 encounterPortals[31239:a0f] *** __NSAutoreleaseNoPool(): Object 0x1001023b0 of class NSException autoreleased with no pool in place - just leaking
2010-11-16 12:14:54.434 encounterPortals[31239:a0f] *** __NSAutoreleaseNoPool(): Object 0x1001108e0 of class _NSCallStackArray autoreleased with no pool in place - just leaking
2010-11-16 12:14:54.434 encounterPortals[31239:a0f] *** __NSAutoreleaseNoPool(): Object 0x100110a90 of class _NSCallStackArray autoreleased with no pool in place - just leaking
2010-11-16 12:14:54.448 encounterPortals[31239:a0f] *** __NSAutoreleaseNoPool(): Object 0x100110e30 of class NSCFString autoreleased with no pool in place - just leaking
2010-11-16 12:14:54.495 encounterPortals[31239:a0f] *** __NSAutoreleaseNoPool(): Object 0x100111440 of class NSCFString autoreleased with no pool in place - just leaking
2010-11-16 12:14:54.496 encounterPortals[31239:a0f] *** __NSAutoreleaseNoPool(): Object 0x100111890 of class NSConcreteMutableData autoreleased with no pool in place - just leaking
2010-11-16 12:14:54.497 encounterPortals[31239:a0f] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (4) beyond bounds (4)'
*** Call stack at first throw:
(
       0   CoreFoundation                      0x00007fff884d8cc4 __exceptionPreprocess + 180
       1   libobjc.A.dylib                     0x00007fff86f250f3 objc_exception_throw + 45
       2   CoreFoundation                      0x00007fff884d8ae7 +[NSException raise:format:arguments:] + 103
       3   CoreFoundation                      0x00007fff884d8a74 +[NSException raise:format:] + 148
       4   Foundation                          0x00007fff801db084 _NSArrayRaiseBoundException + 122
       5   Foundation                          0x00007fff8013db59 -[NSCFArray objectAtIndex:] + 75
       6   encounterPortals                    0x0000000100000dfd main + 417
       7   encounterPortals                    0x0000000100000c54 start + 52
       8   ???                                 0x0000000000000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
Program received signal:  “SIGABRT”.
sharedlibrary apply-load-rules all
kill
quit


// encounterPortals
// PortalPilots encounter a variety of Time Portal Types
// based on accesselements page 166, Holzner

#import <Foundation/Foundation.h>

// IMPORTANT STUFF
//  1) End arrays with the nil object
//  2) Use @ to differentiat OBJECTIVE C strings from C-style strings

int main (int argc, const char * argv[]) {
    NSArray *portals = [[NSArray alloc] initWithObjects:@"bridge", @"creek",@"path", @"alley", nil];
    printf("Portal Pilots Maintenance Flight. Scanning for UNIQUE Time Portals \n");
    printf("portals[0] = %s \n", [[portals objectAtIndex: 0] cString]);
     printf("portals[1] = %s \n", [[portals objectAtIndex: 1] cString]);
    printf("portals[2] = %s \n", [[portals objectAtIndex: 2] cString]);
     printf("portals[3] = %s \n", [[portals objectAtIndex: 3] cString]);
   
    // Thought it would be interesting to try to access nil
    // Wow! Leaking - What IS leaking? And all kinds of neat errors
  
    //printf("portals[4] = %s \n", [[portals objectAtIndex: 4] cString]);

    return 0;
}

Time Travel Protocols


Loading program into debugger…
Program loaded.
run
[Switching to process 30368]
Running…
Encountered a Time Portal, type Creek
Encountered a Time Portal, type Alley

Debugger stopped.
Program exited with status value:0.

//
//  TimeTravelProtocol.m

//  Based on page 161 Holzner Quick Start Book

//  Created by xxxxx on 11/11/10.
//  Copyright 2010 __xxx__. All rights reserved.
//

// page 155 The Point of using Protocols
// Protocols let me specifiy a method or methods that can be used in multiple classes.
//   Protocols let me declare methods and to define the implementation in the class
//        Protocols let me make sure
//    that all my derived classes implement the same methods - though the implementation may be different

// In this project I create a 'printing' protocol, which I can include in the interface files of other classes
//     it ADDS 'print' to their interfaces
//  I can implement the print method a different way for each class


// NOTE IMPORTANT: IN PREVIOUS EXAMPLES I would have included the
//          (void) print;
//   in the .h files associated with each class alley.h and creek.h) - but now this is only in printing. h
//  So I can be sure that my derived classes will inherit this method from their base classes

// Apparently this is how Objective-C fakes out multiple inheritance too - but I don't know exactly how to make that
//   happen yet from multiple parents at the same level....


// Another way  this book does something like this, is with prototypes
//     that is BEFORE it moved onto object-oriented methods
//   and is back on page 63 'a function prototype is also called a function declaration,
//       as opposed to a definition, which includes the body of the function


#import <stdio.h>
#import "Creek.h";
#import "Alley.h";

int main(void) {
   
    Creek *c = [Creek new];
    [c print];
   
    Alley *c2 = [Alley new];
    [c2 print];
   
    return 0;
}

Thursday, November 11, 2010

Debugging: Hey bobcat, to catch a fish, you gotta think like a fish


 
There was a kid’s book I had, when I still was a kid, about a native American child. Her elders told her that to catch a fish, she had to think like a fish. Or maybe it was bear, or a mountain goat. I don’t actually remember. So Little Bobcat developed her analytical little wits and finally caught herself a fish.

There’s a lot I have yet to learn about the XCODE debugger. In fact, just about everything.  I haven’t even figured out where to go to learn about how the debugger works. I’m still just looking at error messages and going from there. Tonight I had ‘duplicate symbol _main’. I clicked on every highlighted place I could find. I looked at the thread displaying the hierarchy of file names. I looked through each of the five files I’d created, but I only found the word ‘main’ in one place. * Finally I just decided to think like a fish.

Somewhere, I must have more than one of those lines that looks like this

int main(void) {

but I sure didn’t see it in any of my ‘.m’ or ‘.h’ files.

So I started opening up gates. That’s what a fish would do, right? A fish like XCODE looks at all the files in the project. (One heck of a smart fish) and that fish recognizes the name of the project. So the fact that I was expecting my fish to only respond to the lines  (my fishing line that is) in a file called ‘main.m’, didn’t mean that she wasn’t going to look around for other files. Particularly a file with the same name as my project – ‘protocols.m’, a file created by default in a folder called ‘SOURCE’ when I created a new project. Sure enough, there was the culprit line. More than one ‘main’ makes trouble.

Cast your (main) lines upon the water, but only one at a time.

* After I resolved this error,  it occurred to me that ‘find in project’ would have been another good way to scout out this problem.

Tuesday, November 2, 2010

Demonstrating Polymorphism OR TRAPPED IN TIME?

Version:1.0 StartHTML:0000000201 EndHTML:0000074336 StartFragment:0000002867 EndFragment:0000074300 SourceURL:file://localhost/Users/Laurel/Apps%20Learning/Journal%20TrappedInPolymorphicTime.doc
// TrappedInTime

Loading program into debugger…
Program loaded.
run
[Switching to process 7629]
Running…
    PERIOD PILOTS Staff Members are currently performing maintenance on this portal
Your trip is being routed to another time portal.
 Thank you for your patience
 ....    PERIOD PILOTS Maintenance Log for Tuesday, November 2, 2010

 Performing Maintenance on Time Portal of type: Bridge

Performing Maintenance on Time Portal of type:  Canyon
Performing Maintenance on Time Portal of type:  Canyon
Performing Maintenance on Time Portal of type:  Canyon
Performing Maintenance on Time Portal of type:  Canyon
Performing Maintenance on Time Portal of type:  Canyon
Performing Maintenance on Time Portal of type:  Canyon
Performing Maintenance on Time Portal of type:  Canyon
Performing Maintenance on Time Portal of type:  Canyon
Performing Maintenance on Time Portal of type:  Canyon
Performing Maintenance on Time Portal of type:  Canyon
Performing Maintenance on Time Portal of type:  Canyon
Performing Maintenance on Time Portal of type:  Canyon
Performing Maintenance on Time Port

* * * TASK CANCELLED BY PORTAL PILOT SUPERVISOR * * *



//  Or why Time Portal Constructors need to wear the right GLASSES  @ the computer
// I was so enchanted with the bug I created using an = instead of a < to control my loop, that I was determined to return
//       AFTER ALL
//  As we learn from reading history, great scientific discoveries are often made by mistake
//         OR
//  It's a feature not a bug

for(loopIndex =0; loopIndex < 2; loopIndex++)
  // for(loopIndex =0; loopIndex = 2; loopIndex++)



WHAT WE EXPECTED

This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys000
Loading program into debugger…
Program loaded.
run
[Switching to process 7588]
Running…
    PERIOD PILOTS Staff Members are currently performing maintenance on this portal
Your trip is being routed to another time portal.
 Thank you for your patience
 .... 
  PERIOD PILOTS Maintenance Log for Tuesday, November 2, 2010

 Performing Maintenance on Time Portal of type: Bridge

Performing Maintenance on Time Portal of type:  Canyon

....
  Maintenance Cycle of all Time Portals in this zone,
  completed properly on Tuesday, November 2, 2010

Debugger stopped.
Program exited with status value:0.



//  GettingWorkDoneInATimelyManner

//  Demonstrating polymorphism: Using the same code with different objects
//      the object that is used is determined at runtime when I pass a message

//based on example in Quick Start Objective C , Holzner, page 139
//

#include <stdio.h>

#include <Foundation/Foundation.h>

@interface Bridge : NSObject
-(void)  print;
@end

@implementation Bridge

-(void) print
{
    printf("Performing Maintenance on Time Portal of type: Bridge\n");
}

@end
//
@interface Canyon : NSObject
-(void)  print;
@end

@implementation Canyon

-(void) print
{
    printf("Performing Maintenance on Time Portal of type:  Canyon\n");
}

@end

int main (void) {
    printf ("\t PERIOD PILOTS Staff Members are currently performing maintenance on this portal\n");
    printf("Your trip is being routed to another time portal.\n Thank you for your patience\n");

    printf("\f.... \f  PERIOD PILOTS Maintenance Log for Tuesday, November 2, 2010\n ");
   
    Bridge *c1 =  [Bridge new]  ;
    Canyon *c2 =  [Canyon new]  ;
    id pointerToObject;
    int loopIndex;
   
    pointerToObject = c1;
   
 for(loopIndex =0; loopIndex < 2; loopIndex++)
    //  for(loopIndex =0; loopIndex = 2; loopIndex++)
    {
        [pointerToObject print];
        pointerToObject = c2;
       
    }
   
   
    printf("\f.... \f  Maintenance Cycle of all Time Portals in this zone, \f  completed properly on Tuesday, November 2, 2010\n ");

    return 0;
}



Monday, November 1, 2010

Documentation: It's all Postfix Polish to me


 In the olden days, not long after the covered wagons crossed the praries committing genocide and spreading disease along the way, we had a special way of entering our data into our new modern calculators. Calculators were those devices that came after slide rulers and we needed them in order to survive physics and chemistry classes. The mathematical notation we needed to know to use these wonderful new machines was, and is, called 'Postfix Polish' (or P.F.P. as we incorrectly acronymed it). I invariably messed up P.F.P. This was the beginning of my foray into the world of looking-it-up-in-the-manual. From there I went on to fight with manuals in my first programming classes. Eventually the manual, or the online help systems that have not entirely superseeded it, become my closest friends. But in the beginning we are always a little wary of each other.


Herein lies some of my recent social encounters involving becoming friendly with documentation related to XCODE and Objective-C.


...

‘getCount’ is, I believe, a method that I’m using from a base or super class. Today I’m using it in the’constructor’ exercise on page 137 of the Quick Start book. I know what it does, it returns a count of the number of objects I’ve instantiated for a given class, but I want to know more about it.

Looking things up in this new environment, isn’t clear to me, yet. I usually start by looking for words in the index of the current book. Then I move on to trying the help menus in XCode. Today I also tried looking in the Bjarne Stroustrup book as well as The C++ Standard Library by Josuttis. I think maybe what I’m looking for today, getCount, is part of the Foundation Library (hope I’m using the right phrase). The Foundation documentation is all on line and probably within my resources right here, once I learn how to search for things properly. I tried using the HELP pulldown menu within XCode, but get no results on the string 'getCount'.  Next I put ‘NSObject’ into the ‘Q’ search box on the upper right hand corner of my current XCode window.
 



 That got me nowhere, but again choosing the HELP pulldown menu from the XCode tool bar (or maybe it’s the option bar) , this time with NSOBJECT as my search term,  took me a little further into the mysteries of documentation.

I chose ‘Search in Documentation Window’

I found it remarkably easy to get tangled up in the documentation, but by going back and forth and trying out different search terms, I finally found some information on getCount. One thing I've learned is that getCount is a function (which maybe I can translate to mean a method) related to another class I've not heard of yet. I assume that class is derived from NSObject and, somehow, methods are shared across some kind of wiring such that when I derive a class from NSObject, I can use methods associated with this (other) class.



...

Now, what was it I wanted to know about getCode?

Thursday, October 28, 2010

Time Standing Still: Scouting for Time Travel Methods




This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys000
Loading program into debugger…
Program loaded.
run
[Switching to process 60450]
Running…
Scouting out Time Travel methods
Encountered a Clock
Within a Building
Within a Time Portal

Debugger stopped.
Program exited with status value:0.


.....

#include <stdio.h>
#import <Foundation/Foundation.h>

//Based on, Using Multi-Level Inheritance QStart page 131

@interface Portal : NSObject

-(void) print;

@end

@implementation Portal
-(void) print
{
    printf("Within a Time Portal\n");   
}
@end

@interface Building : Portal

-(void) print2;

@end

@implementation Building
-(void) print2
{
    printf("Within a Building\n");   
}
@end

//
@interface Clock : Building

-(void) print3;

@end

@implementation Clock
-(void) print3
{
    printf("Encountered a Clock\n");   
}
@end






int main (void)
{
    Clock *c3 = [Clock new];
   
    printf("Scouting out Time Travel methods\n");
    [c3 print3];
    [c3 print2];
    [c3 print];
   

    return 0;
}

Tuesday, October 26, 2010

Reviewing Concepts: Portal Inheritance, Object Method

This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys000
Loading program into debugger…
Program loaded.
run
[Switching to process 45244]
Running…
Portal Pilots: Encountered a Time Portal
Portal Type is a Bridge

Debugger stopped.
Program exited with status value:0.

.....

#include <stdio.h>
#import <Foundation/Foundation.h>

// Portalinherit: Simple Portal Inheritance

//Based on: inheriting base-class methods QStart page 125

@interface Portal : NSObject

-(void) print;

@end

@implementation Portal
-(void) print
{
    printf("Portal Pilots: Encountered a Time Portal\n");  
}
@end

@interface Bridge : Portal

-(void) print2;

@end

@implementation Bridge
-(void) print2
{
    printf("Portal Type is a Bridge\n");  
}
@end

int main (void)
{
  
    // Instantiate the 'Bridge' class
    // create an object called 'bridge' that points to the Bridge instance
  
    Bridge *bridge = [Bridge new];
  
    // execute an object method (page 83)
    //  syntax is '[object object_method_name]'
  
    [bridge print];
    [bridge print2];
  
  
  
    return 0;
}

Reviewing Concepts:Portal Used Since - Back and Forth in the Book



One of the things that is helping me develop my skills with how oop works is the one-simple-concept-at-a-time, nature of the Quick Start book. Having taught math, I know that abundant practice is the key to problem solving and learning. Of course that's the reason that I  do a second pass on each book exercise (I don't put them all out here). That's a good start, because even simply renaming things to match my own stories gives me more ownership, and makes me think through the code more.

Also for each piece of code that I get to run, I try to work back though each of the lines of code and make sure I can explain to myself the reason for that line being there and what it does.

In the process of re-thinking each line of code from my working example based on page 123, I remembered that the author had me instantiating an object differently a chapter or so back. I found the difference on page 97. 

Why in one case, page 123 (when author happens to be talking about inheriting base-class data members) in the Quick Start book do we only instantiate an object with

Bridge *c2 = [Bridge new];
c2-> year = 1917;

But in another case we use ‘init’, and the author makes a big deal about using it on page 97, when he talks about “using constructors”

Container *object = [(Container new], init:2];

….
In the case of  the page 97 ‘Container’ example, the author wants to make the point that a constructor allows me to ‘initialize the data in an object when I (you) create the object.”

He also says, “the constructor returns a pointer to the object, and you get that pointer by calling the super class’s init method.” The pointer returned for the page 97 example would be ‘object'.

Thanks Mr. Holzner, for focusing on one thing at a time.

...... 

Loading program into debugger…
Program loaded.
run
[Switching to process 44577]
Running…
This particular BRIDGE portal has been in use since 1917

Debugger stopped.
Program exited with status value:0.

 ...
#include <stdio.h>
#import <Foundation/Foundation.h>

//inheriting base class data members QStart page 122

@interface Portal : NSObject

{
@public
    int year;
}

@end

@implementation Portal

@end

@interface Bridge : Portal

@end

@implementation Bridge


@end

int main (void)
{
    // *bridge is a pointer
    //        a pointer holds the address in memory of a data item
    // "Bridge *bridge" means that this pointer is a variable of type 'Bridge'
   
    // Instantiate the Bridge class
   
    Bridge *bridge = [Bridge new];
   
    // Next the pointer, bridge, picks up the address in memory for the ivar/class variable 'year'
    //    year is an ivar that the Bridge class inherits from the Portal class
    // At the same time I set the value of 'year' to be 1917
   
    bridge-> year = 1917;
   
    //Am really looking forward to the day when I'm not hard-coding in information like the type of portal but am able to pick it up
    // from a class variable!
   
    printf("This particular BRIDGE portal has been in use since %i\n", bridge->year );
   
   
    return 0;
}
 

 

Saturday, October 23, 2010

Reviewing Concepts: Our Kind of Portal?




This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys000
Loading program into debugger…
Program loaded.
run
[Switching to process 28127]

Running…
The SLO Portal is a TimePortal


Debugger stopped.
Program exited with status value:0.






#import <stdio.h>
#import <Foundation/NSObject.h>


// 
// Based on ideas from Page 116 of Virtual Quickstart Guide Objective-C (Holzner)
// Verify that an object belongs to a class
// TIME TRAVEL IMPLEMENTATION
//    Verify that an object is a Time Travel Portal
//     Note: Travellers are into Slow Travel these days and Period Pilots likes to stay abreast of trends
//            so portals in SLO are particularly interesting
// It looks like 'isKindOfClass is a METHOD inherited from the NSObject superclass/baseclass

// isKindOfClass tells me wether an object is
//     a) a member of a class (like isMemberOfClass does)
// AND b) is a a member of any class derivedfrom that class
//

@interface TimePortal:NSObject
-(void) print;
@end

//METHODS  for TimePortal

@implementation TimePortal
-(void) print
{
    printf("This is TimePortal.\n");
}

@end

@interface SLOPortal:TimePortal
-(void) print;
@end

//METHODS  for SLOPortal

@implementation SLOPortal
-(void) print
{
    printf("This is SLOPortal.\n");
}

@end

int main (void) {
    TimePortal *c1 = [TimePortal new];
   
    // Find syntax for this method
    //
   
    if ([c1 isKindOfClass: [TimePortal class]]  ==YES)
    {
        printf("The SLO Portal is a TimePortal\n");
    }
   
     return 0;
}

Friday, October 22, 2010

Reviewing Concepts: Identify Time Portals

Las Pilitas Time Portal
I’m finding it really useful to have worked my way down to this book, which lays out one simple concept after another. It helps me to focus on one thought at a time and how oop is different than being a structured programmer. I wonder what it will be like to go back to those other two books I used during the summer, with their much more complex examples, when I’m done with this one. It sure is tempting to jump ahead in time and find out! 

One thing I’ve found challenging learning Objective-C is knowing that I’m doing things that I’ll be unlearning later on. In this example, I know that naming each class as a particular Time Portal isn’t as cleanly object oriented as I’ll be later on. I wouldn’t setup a record in a database schema like this. Or even in an old-fashioned file-management system. These are really instances of the same class.

Now, when I say ‘instances of the same class’ am I thinking right? There’s where a background using database methodology sometimes trips me up. Like when I catch myself thinking than an object is a variable or a class is a record. They aren’t.

Come back to this later and see if I had this ‘instance’ business right or not.


……..
[Session started at 2010-10-20 09:27:32 -0700.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1469) (Wed May  5 04:36:56 UTC 2010)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys001
Loading program into debugger…
Program loaded.
run
[Switching to process 333]
Running…
Located Portal at LasPilitasSLO.
Located Portal at MillbraeBARTStation.

Debugger stopped.
Program exited with status value:0.
 ...

#import <stdio.h>
#import <Foundation/NSObject.h>

// GUI NOTE It's SHIFT Command/Apple F to do a find & replace in XCode
//       Been trying to find global find & replace for awhile now!
//       Regular appleF just highlights all the occurances in the piece of code

// Locate and Identify Time Portals for Portal Pilots Service

// Based on ideas from Page 112 of Virtual Quickstart Guide Objective-C (Holzner)
// Multiple Object Types and use of 'id'type
//
// Create objects of two different class types
//    Place them in the same variable of type id

// NOTE ORDER of *multiple* INTERFACE & METHOD sections
//        I write the interface for one class then it's methods
//      I repeat this structure for the other class
//  

@interface LasPilitasSLO:NSObject
-(void) print;
@end

//METHODS for LasPilitasSLO

@implementation LasPilitasSLO
-(void) print
{
    printf("Located Portal at LasPilitasSLO.\n");
}

@end


@interface MillbraeBARTStation:NSObject
-(void) print;
@end

//METHODS for MillbraeBARTStation
@implementation MillbraeBARTStation
-(void) print
{
    printf("Located Portal at MillbraeBARTStation.\n");
}

@end

int main (void) {
    LasPilitasSLO *c1 = [LasPilitasSLO new];
    MillbraeBARTStation *c2 = [MillbraeBARTStation new];
    // Remember
    // Here I am declaring 'container' to be of type id
    id container;
   
    container = c1;
    [container print];
   
    container = c2;
    [container print];
   
     return 0;
}