Hi; if someone couple help the newbie out in understanding how NSString works, I'd most appreciate it 
I built a simple app; it has a TextView and a Button, and a Listing object. The Listing object contains a NSString named test, an init method, and a displayText method.
displayText runs when I press the button I created in Interface Builder, and outputs text to the TextView, and then outputs the contents of the NSString to NSLog.
Listing.h:
Listing.m:
This application freezes and then crashes when I press the button. When I comment out the bolded text, it works fine. If I use @"testing text." instead of test, it works fine. So, clearly, I can't use a NSString object just like that.
What's the proper usage?
Thanks all!
I built a simple app; it has a TextView and a Button, and a Listing object. The Listing object contains a NSString named test, an init method, and a displayText method.
displayText runs when I press the button I created in Interface Builder, and outputs text to the TextView, and then outputs the contents of the NSString to NSLog.
Listing.h:
Code:
#import <Cocoa/Cocoa.h>
#import "Character.h"
@interface Listing : NSObject {
IBOutlet NSTextView *textView;
NSString *test;
}
- (IBAction)displayText:(id)sender;
@end
Listing.m:
Code:
#import "Listing.h"
@implementation Listing
- (id)init
{
[super init];
NSLog(@"Listing initialized.");
test = [NSString stringWithFormat:@"testing text."];
return self;
}
-(IBAction)displayText:(id)sender
{
[textView insertText:@"lol test\n"];
[b]NSLog(test);[/b]
return;
}
@end
This application freezes and then crashes when I press the button. When I comment out the bolded text, it works fine. If I use @"testing text." instead of test, it works fine. So, clearly, I can't use a NSString object just like that.
What's the proper usage?
Thanks all!