nsdata

Storing CLLocationCoordinates2D in NSMutableArray

强颜欢笑 提交于 2019-11-28 18:52:11
After some searching, I got the following solution : reference . CLLocationCoordinate2D* new_coordinate = malloc(sizeof(CLLocationCoordinate2D)); new_coordinate->latitude = latitude; new_coordinate->longitude = longitude; [points addObject:[NSData dataWithBytes:(void *)new_coordinate length:sizeof(CLLocationCoordinate2D)]]; free(new_coordinate); And access it as: CLLocationCoordinate2D* c = (CLLocationCoordinate2D*) [[points objectAtIndex:0] bytes]; However, someone claims that there is a memory leak here? Can anyone suggest me where is the leak and how to fix it. Further, is there a better

Compute a checksum on the iPhone from NSData

无人久伴 提交于 2019-11-28 18:23:40
Using the iPhone SDK, I'm having the user select images from the image picker. If the user selects an image they've selected before, I'd like to make the user aware of it. My initial plan (just to make sure other things work for now) is to save the image to a file (need to do this anyway for other reasons), using a checksum of the NSData as the filename. Then, when they select the same image later on, the checksum will be the same and so I can see that a file with that name already exists - hurrah! However, I've scoured the internet and the Apple docs for how to compute a checksum from a

NSData to [Uint8] in Swift

穿精又带淫゛_ 提交于 2019-11-28 18:12:48
问题 I couldn't find a solution to this problem in Swift (all of them are Objective-C, and they deal with pointers which I don't think exist in Swift in the same form). Is there any way to convert a NSData object into an array of bytes in the form of [Uint8] in Swift? 回答1: You can avoid first initialising the array to placeholder values, if you go through pointers in a slightly convoluted manner, or via the new Array constructor introduced in Swift 3: Swift 3 let data = "foo".data(using: .utf8)! /

Create an Array in Swift from an NSData Object

▼魔方 西西 提交于 2019-11-28 17:49:15
I'm trying to store an array of integers to disk in swift. I can get them into an NSData object to store, but getting them back out into an array is difficult. I can get a raw COpaquePointer to the data with data.bytes but can't find a way to initialize a new swift array with that pointer. Does anyone know how to do it? import Foundation var arr : UInt32[] = [32,4,123,4,5,2]; let data = NSData(bytes: arr, length: arr.count * sizeof(UInt32)) println(data) //data looks good in the inspector // now get it back into an array? You can use the getBytes method of NSData : // the number of elements:

NSData and UIImage

浪尽此生 提交于 2019-11-28 17:09:37
I am trying to load UIImage object from NSData , and the sample code was to NSImage , I guess they should be the same. But just now loading the image, I am wondering what's the best to troubleshoot the UIImage loading NSData issue. Noah Witherspoon UIImage has an - initWithData: method. From the docs: "The data in the data parameter must be formatted to match the file format of one of the system’s supported image types." b123400 I didn't try UIImageJPEGRepresentation() before, but UIImagePNGRepresentation works fine for me, and conversion between NSData and UIImage is dead simple: NSData

Using ALAssetsLibrary and ALAsset take out Image as NSData

廉价感情. 提交于 2019-11-28 17:05:47
I wish to extract the image using ALAssetsLibrary and ALAsset directly in the form of a NSData object. Using a NSURL I take out the image in the following manner. NSURL *referenceURL =newURL; ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; [library assetForURL:referenceURL resultBlock:^(ALAsset *asset) { UIImage *copyOfOriginalImage = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullResolutionImage]]; } Now here we take the image as a UIImage, but I need to take the image directly as NSData. I wish to do this because (I have read that) once you take the image in UIImage,

NSDictionary to NSData and NSData to NSDictionary in Swift

孤街醉人 提交于 2019-11-28 16:57:58
I am not sure if I am using the dictionary or the data object or both incorrectly. I m trying to get used to the switch to swift but I'm having a little trouble. var dictionaryExample : [String:AnyObject] = ["user":"UserName", "pass":"password", "token":"0123456789", "image":0] // image should be either NSData or empty let dataExample : NSData = dictionaryExample as NSData I need the NSDictionary to encode to an NSData object as well as taking that NSData object and decode it into a NSDictionary . Any help is greatly appreciated, thanks. Leo You can use NSKeyedArchiver and NSKeyedUnarchiver

Convert UIImage to NSData without using UIImagePngrepresentation or UIImageJpegRepresentation

浪子不回头ぞ 提交于 2019-11-28 16:53:39
I Need to convert UIImage to NSData but without using UIImagePngRepresentation or UIImageJpegRepresentation , for images from photolib i can use assetlib method as mentioned here Using ALAssetsLibrary and ALAsset take out Image as NSData , but for captured image , assset url is not there hence in that case i need to convert UIImage directly to bytes with exif data , how can i accomplish this ? please help H Bastan, Based on your comment: ...I want to save the captured image return by device camera, through UIImagepicker delegate method in document directory... It looks like your real goal is

Data corruption when reading realtime H.264 output from AVAssetWriter

拟墨画扇 提交于 2019-11-28 15:53:14
问题 I'm using some tricks to try to read the raw output of an AVAssetWriter while it is being written to disk. When I reassemble the individual files by concatenating them, the resulting file is the same exact number of bytes as the AVAssetWriter's output file. However, the reassembled file will not play in QuickTime or be parsed by FFmpeg because there is data corruption. A few bytes here and there have been changed, rendering the resulting file unusable. I assume this is occurring on the EOF

Get underlying NSData from UIImage

泄露秘密 提交于 2019-11-28 15:35:28
问题 I can create UIImage from NSData using [UIImage imageWithData:] or [UIImage initWithData:] methods. I wonder if I can get the NSData back from an existing UIImage ? Something on the line of NSData *myData = [myImage getData]; 回答1: NSData *imageData = UIImageJPEGRepresentation(image, 0.7); // 0.7 is JPG quality or NSData *imageData = UIImagePNGRepresentation(image); Depending if you want your data in PNG format or JPG format. 回答2: When initialising a UIImage object with init(data: originalData