Joshua Noble
Joshua Noble

Reputation: 894

How to create CBUUID in Objective C

The following crash is perplexing me:

        for( BLECharacteristic *chara in characteristics)
        {
            NSString *s = chara.uuid;
            CBUUID *uuid = [CBUUID UUIDWithString: (chara.uuid)]; // can't do this?

            [uuids addObject:uuid];
        }

Where my BLECharacteristic class is:

#import <Foundation/Foundation.h>

@interface BLECharacteristic : NSObject

@property NSString *uuid;
@property bool shouldNotify;

- (void)setId:(NSString *)thisId;

@end

The value isn't nil, I'm setting it elsewhere to just be an NSString, usually something like: "713D0003-503E-4C75-BA94-3148F18D941E". Actually even:

CBUUID *uuid = [CBUUID UUIDWithString:@"713D0003-503E-4C75-BA94-3148F18D941E"];

works totally fine, but I'd like things to be a little more configurable and dynamic.

I'm guessing this is very simple for someone who actually understands ObjC but I'm a lowly C/C++ guy and am baffled as to why I can't take a valid value and pass it to this method to create a CBUUID.

Upvotes: 1

Views: 1819

Answers (1)

ares777
ares777

Reputation: 3628

Since you already alloc s as NSString , first NSLog it's value. If it is valid, then use UUIDWithString:s. For more safety and to avoid crash due nill or NULL value, alloc NSString *s= [NSString stringWithFormat:@"%@"...]. Don't forget to alloc init your NSString before working with values.

Upvotes: 1

Related Questions