Split data from Arduino in Objective-C

77 Views Asked by At

Below is a code to receive data from a Bluno Beetle BLE:

 /* Data received */
else if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:BLECharacteristic]]){
    NSString *data = [[NSString alloc] initWithData:characteristic.value encoding:NSUTF8StringEncoding];
    NSLog(@"Received Data = %@", data);

    [_receiveText setText:data];
}

However, if I want to display multiple data values, is there a way for me to split the received text/data?

For example I want to display a number and a text, and the Arduino sends over a string. New to coding, so your help and patience will be appreciated!

1

There are 1 best solutions below

1
On BEST ANSWER

is there a way for me to split the received text/data?

Yes, of course. You can do whatever you like to the data once you've got it. Take a look at the NSString documentation and you'll find plenty of methods for splitting and otherwise extracting data from strings. Some examples: -componentsSeparatedByString:, componentsSeparatedByCharactersInSet:, -stringByTrimmingCharactersInSet:, -substringWithRange:, etc. There are also other Foundation classes that can help, like NSScanner and NSRegularExpression.

New to coding, so your help and patience will be appreciated!

Reading the fine manual should be your first move no matter what your experience level is. The documentation for Apple's frameworks is generally excellent, and it includes many guides and introductory "getting started" documents that make it easy to get up to speed.