I am following the OSX tutorial series on developer.apple.com and have run into a problem. When I paste or type text into the NSTextView and try to send it to the general pasteboard, the NSTextView returns a null string. I then tried to see if the NSTextStorage was null and it too is returned as null. Below is the relevant parts of the h and m files.
// Document.m
#import "Document.h"
@implementation Document
@synthesize the_view; //NSTextView
@synthesize showStuff; //NSScrollView
- (IBAction)copy2:(id)sender {
NSLog(@"copying");
NSTextStorage *ts = [the_view textStorage];
if( ts )
NSLog(@"not null");
NSString *text = [[the_view textStorage] string];
NSLog(@"%@",text);
//NSString *text = @"okay";
NSPasteboard *pb = [NSPasteboard generalPasteboard];
[pb declareTypes:[NSArray arrayWithObjects:NSStringPboardType, nil] owner:nil];
[pb setString:text forType:NSStringPboardType];
}
//Document.h
#import <Cocoa/Cocoa.h>
@interface Document : NSDocument
{
NSTextView *the_view;
}
@property (nonatomic, retain) IBOutlet NSTextView *the_view;
- (IBAction)copy2:(id)sender;
- (IBAction)paste2:(id)sender;
@property (weak) IBOutlet NSScrollView *showStuff;
@end
Above you'll notice I have a commented out version of the string "text" that is set to "okay". If I use that, the word "okay" is placed on the general pasteboard.
So my question is if you can spot any reason why NSTextStorage would be returning null when there is valid text in the NSTextView. Appreciate the help.