nsdata

How to store an image using NSData in Objective C

How do I take a UIImage and store it preferably as NSData (to write to a file)? Is there some obvious method out there, or could someone provide a code snippet? Thanks in advance! PS. My next question will probably be for a code snippet to capture the current screen image. The snippets I've seen so far appear to be serious overkill f...

NSDictionary From NSMutableData

I was previously using initWithContentsOfURL to download a plist into an NSDictionary, but this hangs the UI when run on the same thread so now I have moved to NSURLConnection the issue is that I can no longer call a method to init the NSDictionary with NSMutableData. What is the best way to take NSMutableData and place it into an NSDict...

How do I convert NSString to NSData?

I have this line of code to convert NSString to NSData: NSData *data = [NSData dataWithBytes:[message UTF8String] length:[message lengthOfBytesUsingEncoding:NSUTF8StringEncoding]]; How do I do this in Unicode instead of UTF8? My message may contain cyrillic characters or diacritical marks. ...

What might cause half of an NSData object to stay in memory after releasing it?

I'm loading a series of images from a server into NSData objects like so: for (int i = 0; i < 36; i++) { NSURL *url = [NSURL URLWithString:@"http://12.34.56.78/image.jpg"]; NSData *data = [NSData dataWithContentsOfURL:url]; // Further processing here } The problem is that half of each data object is being kept in memory. This d...

Best way to serialize a NSData into an hexadeximal string

Hi all, I am looking for a nice-cocoa way to serialize a NSData object into an hexadecimal string. The idea is to serialize the deviceToken used for notification before sending it to my server. I have the following implementation, but I am thinking there must be some shorter and nicer way to do it. + (NSString*) serializeDeviceToken:(...

Getting an XML file from URL to NSData object ?

Hello, I need to load a .xml file from a URL adress into an NSData object for further parsing with some libraries that I already own, ( but they ask me the .xml file as NSData ), how could I do this ? The url format would be something like this: http://127.0.0.1/config.xml ...

Memory Leak Copying data From server

for (int i=0; i<[images count] ;i++) { url=@"http://192.168.0.101/titan/titanimages/"; url=[url stringByAppendingString:[images objectAtIndex:i]]; //NSData *imageData=[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:url]]; NSData *imageData=[NSData dataWithContentsOfURL:[NSURL URLWithString:url]]; destinationPath=[document...

Trying to Write NSString sha1 function, but it's returning null

I have the following Objective-C function: +(NSString *)stringToSha1:(NSString *)str{ NSMutableData *dataToHash = [[NSMutableData alloc] init]; [dataToHash appendData:[str dataUsingEncoding:NSUTF8StringEncoding]]; unsigned char hashBytes[CC_SHA1_DIGEST_LENGTH]; CC_SHA1([dataToHash bytes], [dataToHash length], hashBytes)...

Memory Problem using NSData

this is my code it does not releases memory it reaches to 60 mb and application kills for (int i=0; i<[modelList count] ;i++) { url=@"http://192.168.0.101/images/projectimages/"; url=[url stringByAppendingString:[modelList objectAtIndex:i]]; url=[url stringByAppendingString:@".jpg"]; [[NSURLCache sharedURLCache] setMemoryCapaci...

cocoa 64bit binaries leak memory? (releasing NSData does not free memory)

i've been playing some time with different builds of my application and there seem strange things to happen: my app has a 5mb idle footprint. when uploading a file memory in size of the file is reserved. after the upload the reserved memory should be freed. now there are differences in the builds (gc = garbage collector): 32bit i386 n...

NSData to NSString converstion problem!

Hi guys, I'm getting an html file as NSData and need to parse it to extract some info. My approach was to convert it to NSString with UTF8 encoding (the html has non english characters, russian for example) - it failed. I used something like that: NSString *respData = [NSString stringWithUTF8String:[theData bytes]]; but it returned n...

NSData to NString conversion problem

I'm getting an HTML file as NSData and need to extract some parts of it. For that I need to convert it to NSString with UTF8 encoding. The thing is that this conversion fails, probably because the NSData contains bytes that are invalid for UTF8. I have tried to get the byte array of the data and go over it, but each time I come across no...

Read only a portion of a file from disk in objective-c

I am reading a very large file using a NSInputStreamer and sending them to a device in packets. If the receiver does not get a packet, I can send back to the sender with a packet number, representing the starting location in bytes of the packet missing. I know an NSInputStreamer cannot rewind and grab the packet, but is there another w...

iPhone - parsing nsdata to get multiple files stored there.

I'm trying to find a the new line and returns that are inside a nsdata object that I'm parsing . Here's some code: uint8_t *arr = [receivedData bytes]; NSUInteger begin1 = 0; NSUInteger end1 = len; uint8_t *arr1 = (Byte *)malloc(sizeof(Byte)*((end1-begin1+1))); int j = 0; for (int i = begin1; i < end1; i++){ ...

Create UiImage from NSData

Below is code I copied (from this site) and modified only slightly since the original code would not compile. I want to manipulate the byte array for edge detection and eventually simple changes to colors, but first I wanted to get the basic code working. Currently, the system compiles and runs. It displays a badly drawn elephant on scre...

Encrypted NSData to NSString in obj-c?

I have an iPhone app which encrypts an inputted NSString using CCCrypt (AES256) and a plaintext key. The string and key are given to the encryption method which returns an NSData object. Requesting [data description] where 'data' is the encrypted string data gives an NSString like: "<0b368353 a707e7de 3eee5992 ee69827e e3603dc2 b0dbbc0b...

NSData & NSURL - url with space having problem

I have following code in my application. NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:pathOfThumbNail]]; pathOfThumbNail has following path http://70.84.58.40/projects/igolf/TipThumb/GOLF 58B.jpg When I open above path in safari browser - path is changed automatically & image is successfully displayed. http:/...

NSData & NSMutabledata. How do I read from within the body of a data object?

I have a lllooonnnggg NSMutableData instance. I want to feed non-overlapping sub-ranges this data to other objects. I've perused the NSData/NSMutableData docs and don't quite have a grasp of the proper way to do this. So for example the NSMutableData replaceBytesInRange:withBytes: looks ideal but I need the withBytes: parameter to point...

NSData Behaving as a Consumable Data Stream. Possible?

I am currently doing a lot of data wrangling. I ingest a lloonngg NSData byte streams and then parse that data. The parsing is trivial. However, I have to simulate consumption of the data as I parse via not particularly elegant bookkeeping. Here is what a typical method looks like in the category of NData I have implemented: // Grab a l...

NSMutabledata. Why is the retain count 1 higher that I would have expected?

I am trying to floss daily, get my exercise, and make sure I maintain a balance between my retains and releases. Here is what has me puzzled. I have a ivar: NSMutabledata *_alignmentData and a synthesized property associated with it: // .h file @property (nonatomic, retain) NSMutableData *alignmentData; // .m file @synthesize align...