Tag: nsdata

Elegant Algorithm for Parsing Data Stream Into Record

I am interfacing with a hardware device that streams data to my app over Wifi. The data is streaming in just fine. The data contains a character header (DATA:) that indicates a new record has begun. The issues is that the data I receive doesn’t necessarily fall on the header boundary, so I have to […]

Finding file type of NSData recieved from server

I am receiving a text file from a socket over TCP/IP. There is no file extension (or filename for that matter) as the data is received as bytes. I can take the data from this (in the form of NSData) and load it into a UITextView and display it fine. I want to persist this […]

How do i insert UIImage on UIWebView

I’m trying to display an Animated-GIF image in a UIImageView. Because this way only the first frame is shown i wanted to try a different approach. UIWebView. How can i get an Animated-GIF that is in memory (NSData) to display on a UIWebView with all frames..?

NSData dataWithContentsOfFile returning null

I am trying to fetching a JSON file which exist in my xcode resources using this code -(void)readJsonFiles { NSString *str=[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@”classes.json”]; NSLog(@”Path: %@”, str); NSData *fileData = [NSData dataWithContentsOfFile:str]; NSLog(@”Data: %@”, fileData); SBJsonParser *parser = [[SBJsonParser alloc] init] ; NSDictionary *jsonObject = [parser objectWithData:fileData]; NSLog(@”%@”, jsonObject); } path return me this link […]

NSData from NSKeyedArchiver to NSString

I’m trying to convert NSData generated from NSKeyedArchiver to an NSString so that I can pass it around and eventually convert it back to NSData. I have to pass this as a string (I’m using three20 URL passing). I’ve gone through various encodings, UTF8, ASCII, etc. and can’t get anything to work. NSKeyedArchiver says that […]

How do I extract the width and height of a PNG from looking at the header in objective c?

I have a need to find the dimensions of images online without downloading them. To accomplish this I do this: + (CGSize) getImageDimensions:(NSString *)url { // Send a synchronous request NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString: url]]; NSString *rangeString = [url hasSuffix: @”png”] ? @”bytes=0-100″ : @”bytes=0-1300″; [urlRequest setValue:rangeString forHTTPHeaderField:@”Range”]; NSURLResponse * response = […]

How to pack struct in NSData?

Possible Duplicate: Send and receive NSData via GameKit I have struct which consists of int variable and 2 float pointers (arrays). How can I pack this struct ib NSData and later unpack it?

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

I am reading a very large file using a NSInputStream 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 NSInputStream cannot rewind and grab […]

Best way to generate NSData object with random bytes of a specific length?

If I create a new NSData object of a specific size using dataWithBytes:length:, what is the most efficient way to create the input bytes (20 Mb worth) of random characters, preferably without reading the data in from a file? I need a unique buffer of a specific size each time. Thanks

How do we clear out contents in NSMutableData

How do we clear an NSMutableData without using release and then re-alloc/init again to be used again? I was looking at resetBytesInRange to be set at zero but I am unsure of this. Anyone can help?