I am to send data to digital meter for which I want data in NSMutableData form. I am trying to assign it data but getting errors.
NSMutableData *body = [[NSMutableData alloc] initWithData:[NSData @"1"];
I want to asign string e.g. "1", "start" etc to NSMutableData.
You can't convert directly from an NSString to
NSMutableData
, you have to encode the string asNSData
first. (There are several ways to go from NSData to NSMutableData, but I thinkmutableCopy
is the clearest.);Try this:
You could convert NSString into NSData with
[@"1" dataUsingEncoding:NSUTF8StringEncoding]
, the rest of your code is OK.