nsdata

get float value from nsdata objective-c iOS

↘锁芯ラ 提交于 2019-12-10 22:58:49
问题 I am trying to get a float value from a NSData object which contains several hex values. e.g. EC 51 38 41 From this 4 Byte values i want to get the float value 11.52. How do i have to do this in xcode? I have tried it with NSScanner (scanFloat, scanHexFloat), NSNumberformatter and NSNumber , i created an Byte Array and tried float myFloat = *(float*)&myByteArray . All these Options i found here at stackoverflow. I tested it in Windows with C# and there it was no problem: byte[] bytes = new

How to convert NSData to multiple type Ints

99封情书 提交于 2019-12-10 18:35:54
问题 I obtain magnetometer trim register as get NSData() that looks as follows: <00001a1a 4f56f202 00000000 1dfd421b> I need to convert it to Int8, UInt8, Int16, UInt16 depending on which byte I access. Sources from docs: s8 dig_x1;/**< trim x1 data */ s8 dig_y1;/**< trim y1 data */ s8 dig_x2;/**< trim x2 data */ s8 dig_y2;/**< trim y2 data */ u16 dig_z1;/**< trim z1 data */ s16 dig_z2;/**< trim z2 data */ s16 dig_z3;/**< trim z3 data */ s16 dig_z4;/**< trim z4 data */ u8 dig_xy1;/**< trim xy1

How should I read the data from a json string? iphone

一世执手 提交于 2019-12-10 17:34:27
问题 I have in a NSString "[{"van" : 1,312, "vuan":12,123}] and in order to get this values for every key, I am doing this: NSData *data1 = [jsonResponse1 dataUsingEncoding:NSUTF8StringEncoding]; jsonArray = [NSJSONSerialization JSONObjectWithData:data1 options:kNilOptions error:&err]; self.van = [NSMutableArray arrayWithCapacity:1]; self.vuan = [NSMutableArray arrayWithCapacity:1]; for (NSDictionary *json in jsonArray) { NSString * value = [json objectForKey:@"van"]; [self.van addObject:value];

Swift array element address

强颜欢笑 提交于 2019-12-10 17:34:22
问题 This is a practical question, i'm sending a file by breaking it into trunks of, say, 1000 bytes data = NSData.dataWithContentsOfFile(path) var dataPackage : [Byte](count: 1000, repeatedValue: 0) for offset = 0; offset < data.length; { // omit some range check here data.getBytes(&dataPackage, NSRange(location: offset, length: 1000)) send(dataPackage) } Everything was great, until I want to insert a sequence number into dataPackage, at position 0, so naturally, I would change the above to data

Converting an Integer to NSData in Swift

大憨熊 提交于 2019-12-10 17:31:25
问题 In Objective-C the code looked liked this, NSInteger random = arc4random_uniform(99) + 1 NSData *data = [NSData dataWithBytes:& random length: sizeof(random)]; But when I try to do this in Swift, let random:NSInteger = NSInteger(arc4random_uniform(99) + 1) //(1-100) let data = NSData(bytes: &random, length: 3) It gives me an error staying that "NSInteger is not convertible to @lvalue inout $T1 Any help would be greatly appreciated! 回答1: When you're going to send a pointer to a variable as a

Converting NSSecureCoding to NSData - Xcode - Swift

心已入冬 提交于 2019-12-10 16:13:01
问题 I have some code that creates an NSSecureCoding variable called "content" and I want to convert that variable into NSData that can then be made into a UIImage or be sent to a local server. How do I convert this properly? I want this for a Share Extension I am making in my iOS app, so when you press share on a photo, it gets the photo contents and converts it into NSData. Here is my code: inputItem = extensionContext!.inputItems.first as NSExtensionItem attachment = inputItem.attachments![0]

MKPolyline -> NSKeyedArchiver -> NSData SIGABRT

梦想的初衷 提交于 2019-12-10 15:19:29
问题 In my app I am trying to store an array of MKPolylines into NSUserDefaults . NSData *data = [NSKeyedArchiver archivedDataWithRootObject:overlays]; [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"theKey"]; Gives: [MKPolyline encodeWithCoder:]: unrecognized selector sent to instance 0x169c20` Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [MKPolyline encodeWithCoder:]: unrecognized selector sent to instance 0x1c57e0' Edit: I made some progress.

how append nsdata

老子叫甜甜 提交于 2019-12-10 13:24:26
问题 how i could append nsdata, i would append lenght data on first message to send on socket i use code like this but error on runing. int lendata = [message length]; NSData *firstdata = [NSData dataWithBytes: &lendata length: sizeof(lendata)]; NSData *mdata = [message dataUsingEncoding:NSUTF8StringEncoding]; NSMutableData *seconddata = [NSData dataWithData:mdata]; [firstdata appendData:secondata]; please tell if there is another way Thanks for your help. 回答1: Glancing into my crystal ball: You

Convert incoming NSStream to View

為{幸葍}努か 提交于 2019-12-10 12:31:46
问题 I'm successfully sending a stream of NSData. The delegate method below is getting that stream and appending to NSMutableData self.data. How do I take this data and make it into a UIView/AVCaptureVideoPreviewLayer (which should show video)? I feel like I'm missing another conversion, AVCaptureSession > NSStream > MCSession > NSStream > ? - (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode { switch(eventCode) { case NSStreamEventHasBytesAvailable: { if(!self.data) { self.data

Convert NSData [UIImage] to a NSString

假装没事ソ 提交于 2019-12-10 12:00:45
问题 I am aware this question has been asked several times, but I was unable to find a definate answer that would best fit my situation. I want the ability to have the user select an image from the library, and then that image is converted to an NSData type. I then have a requirement to call a .NET C# webservice via a HTTP get so ideally I need the resulting string to be UTF8 encoded. This is what I have so far: NSData *dataObj = UIImageJPEGRepresentation(selectedImage, 1.0); [picker