How do I send string data in iOS?

 

A Chirp payload is just an array of bytes, which in iOS is represented as the NSData type.


// Sending Objective-C
NSString *identifier = [NSString stringWithUTF8String:@"parrotbill"];
NSData *payload = [identifier dataUsingEncoding:NSUTF8StringEncoding];
//Sending Swift
let identifier: String = "parrotbill"
let payload: Data = identifier.data(using: .utf8)


// Receiving Objective-C
[self.connect setReceivedBlock:^(NSData * _Nonnull data) {
NSString *identifier = [NSString stringWithUTF8String:data.bytes];
}];
// Receiving Swift
connect.receivedBlock = { (data : Data) -> () in if let data = data { let identifier = String(data: data, encoding: .utf8)) } }

 

 

 

 

 



Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.