10.6 NSPasteboard API mixes up types?
10.6 NSPasteboard API mixes up types?
- Subject: 10.6 NSPasteboard API mixes up types?
- From: Peter <email@hidden>
- Date: Sun, 19 Feb 2012 21:24:40 +0100
I am using the following code:
NSPasteboard *pb = [NSPasteboard generalPasteboard];
if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_5) {
//linesArray contains file paths as NSStrings
//namesArray contains file names as NSStrings
[pb declareTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, NSStringPboardType, nil] owner:nil];
[pb setPropertyList:linesArray forType:NSFilenamesPboardType];
[pb setString:[namesArray componentsJoinedByString:@"\n"] forType:NSStringPboardType];
}
else { // >= 10.6
//linesArray contains NSURLs
//namesArray contains file names as NSStrings
[pb clearContents];
[pb setString:[namesArray componentsJoinedByString:@"\n"] forType:NSPasteboardTypeString];
//[pb writeObjects:namesArray];
[pb writeObjects:linesArray]; // write the URLs
}
The 10.5 code results in distinct entities for both of the pasteboard types as I expected.
type: 'public.utf8-plain-text'
'aaa.bbb.ccc'
The 10.6 code results in the following:
type: 'public.utf8-plain-text'
'aaa.bbb.ccc.file'
'://localhost/Use'
'rs/peterjhartman'
'n/Desktop/aaa.fl'
'v.file://localho'
'st/Users/peterjh'
'artmann/Desktop/'
'bbb.flv.file://l'
'ocalhost/Users/p'
'eterjhartmann/De'
'sktop/ccc.flv'
For reasons beyond my comprehension the NSURLs are converted to string data behind my back and added to the existing string data, no matter wether I use writeObjects or setString.
NSFilenamesPboardType contains identical property list of three file paths for this example in both code branches.
'<?xml version="1'
'.0" encoding="UT'
'F-8"?>.<!DOCTYPE'
' plist PUBLIC "-'
'//Apple//DTD PLI'
'ST 1.0//EN" "htt'
'p://www.apple.co'
'm/DTDs/PropertyL'
'ist-1.0.dtd">.<p'
'list version="1.'
'0">.<array>..<st'
'ring>/Users/pete'
'rjhartmann/Deskt'
'op/aaa.flv</stri'
'ng>..<string>/Us'
'ers/peterjhartma'
'nn/Desktop/bbb.f'
'lv</string>..<st'
'ring>/Users/pete'
'rjhartmann/Deskt'
'op/ccc.flv</stri'
'ng>..<string></s'
'tring>..<string>'
'</string>.</arra'
'y>.</plist>.'
Interestingly, I see file paths where I would expect file urls on 10.6.
What am I possibly doing wrong?
How could I avoid this?
Thank you for any pointers!
Peter
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden