Amazon.com Widgets 17.4
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 25, 2014, 05:36:03 AM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Old Stuff
| |-+ Program Examples
| | |-+ Chapter 17
| | | |-+ 17.4
Pages: [1] Go Down
Print
Author Topic: 17.4 (Read 1267 times)
mdeh
Full Member
***
Posts: 166






on: February 21, 2009, 11:12:42 AM

Code: (Objective-C)
#import <Foundation/NSObject.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSString.h>

@interface ClassA: NSObject
{
NSString *str;
}

-(void) setStr: (NSString *) s;
-(NSString *) str;

@end

@implementation ClassA

-(void) setStr: (NSString *) s
{
str = s;
[str retain];
}

-(NSString *) str
{
return str;
}

@end



int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSMutableString *myStr = [NSMutableString stringWithString:@"A string"];
ClassA *myA = [[ ClassA alloc] init];
NSLog(@"myStr retain count %x", [myStr retainCount]);

[myA setStr: myStr];
NSLog(@"myStr retain count %x", [myStr retainCount]);

[myStr release];
NSLog(@"myStr retain count %x", [myStr retainCount]);

[myA release];
    [pool drain];
    return 0;
}
Logged
Pages: [1] Go Up
Print
Jump to:



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.