setPropertyList forType / propertyListForType problem on 10.2.8
setPropertyList forType / propertyListForType problem on 10.2.8
- Subject: setPropertyList forType / propertyListForType problem on 10.2.8
- From: Ryuichi MIZUNO <email@hidden>
- Date: Sat, 18 Oct 2003 02:55:40 +0900
Hi All,
on 10.2.8, NSPasteboard's read/write method pair for propertyList has a
serious problem about NSDictionary
which has NSDecimalNumber type value.
NSDecimalNumber value cannot be retrieved correctly through pasteboard
using this method pair.
any DecimalNumber value will be
<CFNumber 0x13b8e90 [0xa01303fc]>{value = +0.00000000000000000000,
type = kCFNumberFloat64Type}
I hope that this kind of problem caused by 64bit porting of
corefoundation/foundation would not be left on Panther.
Regards,
Ryuichi MIZUNO (Cyber Laboratory Inc. Japan)
Ps.
Archive NSDictionary to data and Unarchive it from data works fine.
So we can work around this problem using set
Data:forType: /
dataForType:
instead of setPropertyList: forType: / propertyListForType: .
----
-(id)getPList
{
NSMutableDictionary* dict = [NSMutableDictionary dictionary];
id val = nil;
val = [NSNumber numberWithInt:1];
[dict setObject:val forKey:@"1-INT"];
val = [NSNumber numberWithFloat:2.1];
[dict setObject:val forKey:@"2-FLOAT"];
val = [NSNumber numberWithDouble:3.14e-4];
[dict setObject:val forKey:@"3-DOUBLE"];
val = [NSDecimalNumber decimalNumberWithString:@"4"];
[dict setObject:val forKey:@"4-DECIMAL-INT"];
val = [NSDecimalNumber decimalNumberWithString:@"5.1"];
[dict setObject:val forKey:@"5-DECIMAL-FLOAT"];
val = [NSDecimalNumber decimalNumberWithString:@"67890123456789"];
[dict setObject:val forKey:@"6-DECIMAL-LONGINT"];
return dict;
}
-(void)write:(id)sender
{
BOOL result = YES;
NSDictionary* pList = NULL;
NSPasteboard* pb = [NSPasteboard
pasteboardWithName:NSGeneralPboard];
[pb declareTypes:[NSArray
arrayWithObjects:NSFileContentsPboardType,nil] owner:nil];
pList = [self getPList];
NSLog(@"WRITE pList threw PList = %@",pList);
NSLog(@"--------------------------------");
result = [pb setPropertyList:pList
forType:NSFileContentsPboardType];
NSLog(@"result --> %@", result ? @"YES":@"NO");
}
-(void)read:(id)sender
{
NSPasteboard* pb = [NSPasteboard
pasteboardWithName:NSGeneralPboard];
NSArray* types = [pb types];
id pList = nil;
if (![types containsObject:NSFileContentsPboardType]) return; //
nil;
pList = [pb propertyListForType:NSFileContentsPboardType];
NSLog(@"READ pList threw PList = %@",pList);
NSLog(@"--------------------------------");
}
-(void)archive:(id)sender
{
id pList = [self getPList];
NSData* data = [NSArchiver archivedDataWithRootObject:pList];
id pList2 = [NSUnarchiver unarchiveObjectWith
Data:data];
NSLog(@"--------------------------------");
NSLog(@"pList = %@",pList);
NSLog(@"--------------------------------");
NSLog(@"pList2 = %@",pList2);
}
-(void)write2:(id)sender
{
BOOL result = YES;
NSData* data = NULL;
NSDictionary* pList = NULL;
NSPasteboard* pb = [NSPasteboard
pasteboardWithName:NSGeneralPboard];
[pb declareTypes:[NSArray
arrayWithObjects:NSFileContentsPboardType,nil] owner:nil];
pList = [self getPList];
data = [NSArchiver archivedDataWithRootObject:pList];
NSLog(@"WRITE pList threw Data = %@",pList);
NSLog(@"--------------------------------");
result = [pb set
Data:data forType:NSFileContentsPboardType];
NSLog(@"result --> %@", result ? @"YES":@"NO");
}
-(void)read2:(id)sender
{
NSData* data = NULL;
NSPasteboard* pb = [NSPasteboard
pasteboardWithName:NSGeneralPboard];
NSArray* types = [pb types];
id pList = nil;
if (![types containsObject:NSFileContentsPboardType]) return;
data = [pb dataForType:NSFileContentsPboardType];
pList = [NSUnarchiver unarchiveObjectWith
Data:data];
NSLog(@"READ pList threw Data = %@",pList);
NSLog(@"--------------------------------");
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.