I'm trying to access this custom obj-C category in Swift file:
#import "NSString+UUID.h"
@implementation NSString (UUIDCategory)
+ (NSString*)stringWithUUID
{
CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
NSString *string = (NSString*)CFMakeCollectable(CFUUIDCreateString(kCFAllocatorDefault, uuid));
CFRelease(uuid);
return [string autorelease];
}
@end
So, I added :
#import "NSString+UUID.h"
in my bridging header, but can't find a solution to use it.
var string = NSString.stringWithUUID()
EDIT: the code seems to work now (the problem was I didn't include #import Foundation/Foundation.h in my bridging header before importing my categories.
This is a factory method and Swift will create an initializer for you automatically!
You should be able to use it like this:
let string = NSString(UUID:uuid)
Off topic, but you should really adopt ARC :]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With