Category in Static Library
Category in Static Library
- Subject: Category in Static Library
- From: Thomas Wetmore <email@hidden>
- Date: Mon, 17 Aug 2009 02:51:01 -0400
I am not sure what group to post this to, so I apologize if this is
the wrong place.
I have a category on NSString that adds one class method,
stringWithUniqueId, that generates a custom form of a UUID.
When I put the category directly in the project it works.
When I move the category into a static library it doesn't work, and
when I call stringWithUniqueId I get the console message:
NewGedcom [11198:10b] *** +[NSString stringWithUniqueId]: unrecognized
selector sent to class 0xa0372f40
The static library was built from the Cocoa Static Library project
template. It includes many other classes and one other category (but
that one defined on one of the classes defined in the library) that
works fine.
The stringWithUniqueId method contains the code:
...
CFUUIDRef uuid = CFUUIDCreate(NULL);
CFUUIDBytes b = CFUUIDGetUUIDBytes(uuid);
CFRelease(uuid);
...
I'm trying to imagine how this code could cause the error I'm seeing,
but I can't make it make sense, as the error indicates the selector
can't be found, not that after the selector is called something goes
south.
Workaround one is just to keep the category in the project, which I'm
now doing, but I would like to understand this behavior. Any ideas? I
appreciate that the first comment one might think of sending is "don't
use a static library," so please consider that comment already made.
Thanks,
Tom W.
ps. The full implementation of the category is:
#import "TWUUId.h"
static unichar x (unsigned int);
// This category uses Apple's core foundation to generate a 128-bit
universal id and then encodes the bits into a 22
// character string. The conventional string form of a universal id is
36 characters long, so this saves 14 characters.
//----------------------------------------------------------------------------------------------------------------------
@implementation NSString (TWUUID)
+ (NSString*) stringWithUniqueId
{
CFUUIDRef uuid = CFUUIDCreate(NULL);
CFUUIDBytes b = CFUUIDGetUUIDBytes(uuid);
CFRelease(uuid);
unichar unichars[22];
unichar* c = unichars;
*c++ = x(b.byte0 >> 2);
*c++ = x((b.byte0 & 3 << 4) + (b.byte1 >> 4));
*c++ = x((b.byte1 & 15 << 2) + (b.byte2 >> 6));
*c++ = x(b.byte2 & 63);
*c++ = x(b.byte3 >> 2);
*c++ = x((b.byte3 & 3 << 4) + (b.byte4 >> 4));
*c++ = x((b.byte4 & 15 << 2) + (b.byte5 >> 6));
*c++ = x(b.byte5 & 63);
*c++ = x(b.byte6 >> 2);
*c++ = x((b.byte6 & 3 << 4) + (b.byte7 >> 4));
*c++ = x((b.byte7 & 15 << 2) + (b.byte8 >> 6));
*c++ = x(b.byte8 & 63);
*c++ = x(b.byte9 >> 2);
*c++ = x((b.byte9 & 3 << 4) + (b.byte10 >> 4));
*c++ = x((b.byte10 & 15 << 2) + (b.byte11 >> 6));
*c++ = x(b.byte11 & 63);
*c++ = x(b.byte12 >> 2);
*c++ = x((b.byte12 & 3 << 4) + (b.byte13 >> 4));
*c++ = x((b.byte13 & 15 << 2) + (b.byte14 >> 6));
*c++ = x(b.byte14 & 63);
*c++ = x(b.byte15 >> 2);
*c = x(b.byte15 & 3);
return [NSString stringWithCharacters: unichars length: 22];
}
@end
// Convert six-bit values into letters, numbers or @ or $ (64
characters in that set).
//----------------------------------------------------------------------------------------------------------------------
unichar x (unsigned int c)
{
if (c < 26) return 'a' + c;
if (c < 52) return 'A' + c - 26;
if (c < 62) return '0' + c - 52;
if (c == 62) return '$';
return '@';
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden