• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
$-prefixed archiving keys in 10.11?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

$-prefixed archiving keys in 10.11?


  • Subject: $-prefixed archiving keys in 10.11?
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Sat, 12 Mar 2016 14:49:40 +0700

In 10.10.5 using a $-prefixed archiving key does NOT work.

Does it work in 10.11?

If not, I will file a bug.

Gerriet.

This is my test code:

#import "AppDelegate.h"

static NSString *const kArchivingKey = @"$my archiving key";	//	no bug without leading '$'

@interface AppDelegate ()

@property (weak) IBOutlet NSWindow *window;
@property (strong) NSString *myName;

@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
	/*	Archives and Serializations Programming Guide →
		Encoding and Decoding Objects → Performance Considerations says:

		"Avoid using “$” as a prefix for your keys.
		The keyed archiver and unarchiver use keys prefixed with “$” for internal values.
		Although they test for and mangle user-defined keys that have a “$” prefix, this overhead makes
		archiving slower."

		Note: this cleary implies: using “$” as a prefix for keys is allowed, albeit slow.
		Fact: In 10.10.5 using “$” as a prefix for keys does NOT work.
	**/

	self.myName = @"สิงโต";	//	use anything ≠ nil; If "สิงโต" seems too scary, use "pussycat" instead.
	NSData *data = [ NSKeyedArchiver archivedDataWithRootObject: self ];
	AppDelegate *selfCopy = [ NSKeyedUnarchiver  unarchiveObjectWithData: data ];
	NSLog(@"%s selfCopy = %@",__FUNCTION__, selfCopy);
}



- (NSString *)description
{
	NSString *s = [ NSString stringWithFormat: @"[%@ name: %@]", [self class], self.myName ];
	return s;
}


- (void)encodeWithCoder:(NSCoder *)coder
{
	[ coder encodeObject: self.myName  forKey: kArchivingKey ];
}



- (id)initWithCoder:(NSCoder *)decoder
{
    self = [super init];
	if ( self == nil ) return nil;

	_myName = [ decoder decodeObjectForKey: kArchivingKey ];

	if ( _myName == nil )	//	error → try badKey instead
	{
		NSLog(@"%s Error: got nil for kArchivingKey = \"%@\"",__FUNCTION__, kArchivingKey);
		NSString *badKey = [ @"$$" stringByAppendingString: kArchivingKey ];
		_myName = [ decoder decodeObjectForKey: badKey ];

		if ( _myName == nil )	//	ok
		{
			NSLog(@"%s Ok got nil for badKey = \"$$\" + kArchivingKey",__FUNCTION__);
		}
		else					//	error
		{
			NSLog(@"%s Error: badKey = \"$$\" + kArchivingKey → %@",__FUNCTION__, _myName);
		};
	}
	else					//	ok
	{
		NSLog(@"%s Ok kArchivingKey = \"%@\" → %@",__FUNCTION__, kArchivingKey, _myName);
	};

	return self;
}

@end


_______________________________________________

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


  • Prev by Date: Re: Automatically restore last saved document on application launch
  • Next by Date: Re: Automatically restore last saved document on application launch
  • Previous by thread: Re: Variable type representations
  • Next by thread: creating an application on the Mac
  • Index(es):
    • Date
    • Thread