In the CryptoExercise iPhone example, they allocate a shared instance
like this:
=========================
static SecKeyWrapper * __sharedKeyWrapper = nil;
+ (SecKeyWrapper *)sharedWrapper {
@synchronized(self) {
if (__sharedKeyWrapper == nil) {
[[self alloc] init];
}
}
return __sharedKeyWrapper;
}
+ (id)allocWithZone:(NSZone *)zone {
@synchronized(self) {
if (__sharedKeyWrapper == nil) {
__sharedKeyWrapper = [super allocWithZone:zone];
return __sharedKeyWrapper;
}
}
return nil;
}
=========================
Is the above paradigm any better/worse than doing something simpler,
like the following (which is the paradigm I've been using):
+ (SecKeyWrapper *)sharedWrapper
{
static SecKeyWrapper * __sharedKeyWrapper = nil;
@synchronized(self) {
if (__sharedKeyWrapper == nil) {
__sharedKeyWrapper = [[self alloc] init];
}
}
return __sharedKeyWrapper;
}
Thank You,
Eric
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]