Rixstep
 About | ACP | Buy | Industry Watch | Learning Curve | News | Products | Search | Substack
Home » Learning Curve » Developers Workshop

Clearly Legal

Putting any object on a pasteboard is fully legal. Even if it's an empty string. Now someone has to get someone else in Cupertino to understand this.


Get It

Try It

Starting with OS X 10.5 Leopard it's illegal to put empty strings on certain pasteboards. Actually only one pasteboard and actually it's not illegal at all. Of course it isn't. It's just that someone in Cupertino took the arbitrary step to make it appear so.

The actual pasteboard operation itself succeeds - because it's not the pasteboard's (or anyone else's) business to poke inside objects, pretend to be a deity, or thwart system operations based on some night school course in Object Pascal for former sanitation engineers, personal assistants, and baristas.

The following code proves this. It's also available as a ready to go Xcode project at the following URL so you can test yourself.

ftp://rixstep.com/pb.zip (2499 bytes) ← click here

Here's the code. The output from its first and only run is commented out at the top.

#import <Cocoa/Cocoa.h>
#import <stdio.h>

#if 0
[Session started at 2007-12-07 00:46:14 -1000.]
   NSDragPboard: 1.
   NSFindPboard: 1.
NSGeneralPboard: 1.

The Debugger has exited with status 0.
#endif

int main(int argc, const char *argv[]) {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSPasteboard *pb;

    pb = [NSPasteboard pasteboardWithName:NSDragPboard];
    printf("   NSDragPboard: %d.\n",
            ([pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil] &&
             [pb setString:@"" forType:NSStringPboardType])
        );
    pb = [NSPasteboard pasteboardWithName:NSFindPboard];
    printf("   NSFindPboard: %d.\n",
            ([pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil] &&
             [pb setString:@"" forType:NSStringPboardType])
        );
    pb = [NSPasteboard pasteboardWithName:NSGeneralPboard];
    printf("NSGeneralPboard: %d.\n",
            ([pb declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil] &&
             [pb setString:@"" forType:NSStringPboardType])
        );

    [pool release]; return 0;
}

See Also
The Technological: Contact the Vendor for an Updated Version

About | ACP | Buy | Industry Watch | Learning Curve | News | Products | Search | Substack
Copyright © Rixstep. All rights reserved.