nsdata

iPhone - int to NSData?

I'm making an iPhone app where I want to save state of the Application. This includes an int property which I'm persisting to a file on its own. I have it written and working, but I know the way I did it was a bit hacky, converting the int to a String and then NSData. Can anybody suggest a better way? int someInt = 1; NSString *aString ...

Converting int64 to NSData

Hi guys, I need to convert a long value from int64 to NSData, so I can later run a hash algorithm on it. I perform: int64_t longNumber = 9000000000000000000L; NSMutableData *buffer = [NSMutableData dataWithBytes:&longNumber length:sizeof(longNumber)]; NSLog(@"%lld", [buffer bytes]); NSLog(@"%lld", longNumber); The resultant console ...

Slow start for AVAudioPlayer the first time a sound is played

I'm trying to eliminate startup lag when playing a (very short -- less than 2 seconds) audio file via AVAudioPlayer on the iPhone. First, the code: NSString *audioFile = [NSString stringWithFormat:@"%@/%@.caf", [[NSBundle mainBundle] resourcePath], @"audiofile"]; NSData *audioData = [NSData dataWithContentsOfMappedFile:audioFile]; NSE...

NSString to Nsdata

How to convert NSString value to NSData.. thanks and regards ...

Read only "N" bytes from a file in Cocoa

How to read only "N" bytes from a specified file? ...

iPhone NSData/NSUrl with cookie

Hi, I'm trying to play/stream a mp3 hosted on a website. The site requires a cookie header to be set, but I'm having trouble setting that or getting the container to do that for me. NSURL *sampleUrl = [NSURL URLWithString:@"http://domain/files/sample.mp3"]; NSData *sampleAudio = [NSData dataWithContentsOfURL:sampleUrl]; Up until ...

Compute a checksum on the iPhone from NSData

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 NSDat...

UIImage from bytes held in NSString

Hi all, I am trying to create a UIImage from a byte array that is actually held within a NSString. Can someone please tell me how I can do that? Here is what I was thinking of doing: NSString *sourceString = @"mYActualBytesAREinHERe="; //get the bytes const char *bytesArray = [sourceString cStringUsingEncoding:NSASCIIStringEncoding];...

What is NSConcreteData, and where is it defined?

The following code: [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mapURL]] returns an instance of NSConcreteData as opposed to NSData (which I expected!). What does NSConcreteData represent, exactly, and why is it being returned instead of an instance of NSData? Further, where is this class defined? XCode is complaining th...

Saving/loading a 2D C array with NSKeyedArchiver

Malloc like this int **terrain; terrain = malloc(sizeof(int*) * mapSize.x); for (int i = 0; i < mapSize.x; i++) { terrain[i] = malloc(mapSize.y * sizeof(int)); } Use it. Convert to NSdata like this before saving NSData *data=[NSData dataWithBytes:terrain length:(30*sizeof(int*) +30*30*sizeof(int) )]; [rootObject setValue:data ...

Does NSNumber add any extra bytes to the number it holds?

I'm working with Objective-C and I need to add int's from a NSArray to a NSMutableData (I'm preparing a to send the data over a connection). If I wrap the int's with NSNumber and then add them to NSMutableData, how would I find out how many bytes are in the NSNumber int? Would it be possible to use sizeof() since according to the apple d...

Load image from url in iPhone, only if small

I'm using initWithContentsOfURL of NSData to load an image from a url. However, I don't know the size of the image beforehand, and I would like to the connection to stop or fail if the response exceeds a certain size. Is there a way to do this in iPhone 3.0? Thanks in advance. ...

How do I turn an NSMutableData into an image in a view?

I downloaded a .jpg file from the Internet with this code: NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://cvcl.mit.edu/hybrid/cat2.jpg"]]; NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; receivedData=[[NSMutableData data] retain]; // etc etc Everyt...

UIImagePNGRepresentation slow or am I doing something wrong?

I'm working on an iPhone App that uses the camera to take pictures, then I'm saving them to the Applications Documents directory. I'm using the following code to convert the UIImage to NSData, NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)]; Then I write the NSData using [imageData writeToFile:path atomical...

NSData initWithContentsOfURL: options: errorPtr: delegate object?

Is there a way to assign some sort of delegate object when [[NSData alloc] initWithContentsOfUrl:... options:... errorPtr:...] is called so that I can monitor percentage complete of a download or is the best way to handle this sort of thing through the use of the asynchronous NSURLConnection stuff? ...

Using NSTask: app freezing after returning output

Hi I have the following code: - (IBAction)runTask:(id)sender { NSTask *proc; NSPipe *output; NSData *data; NSString *buffer; proc = [[NSTask alloc] init]; output = [[NSPipe alloc] init]; [proc setLaunchPath:@"/bin/sh"]; [proc setArguments:[NSArray arrayWithObjects: @"-c", @"/usr/bin/otool -L /Applicatio...

Append NSData to a file in Objective C

Hiya, I'm attempting to download a large file on the iPhone and save it to disk as it is downloaded. Ideally, in: -(void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data { } I want to append 'data' to a file on disk. I've checked out the NSData documentation. There are functions to write to a file, but I can't ...

[NSData writeToFile:options:error:] fails, but no error object is returned. Why?

I'm trying to understand the meaning of the value returned by [NSData writeToFile:options:error:]. The method returns a BOOL, which according to Apple's documentation is "YES if the operation succeeds, otherwise NO." Fair enough, but if it's NO, I would have assumed that the error parameter would then be set to some retrievable NSError*...

Needs solution to store XML as object or as such in iPhone Apps

Hi, I am a beginner to iPhone App development. Please help me out. In my iPhone application, I am making an API request and getting an XML. I have to parse it, store it in a object(or xml as such) and also display it in my application at a later point of time (Its more like storing the current state). I figured out how to request A...

NSData subdataWithRange question

Hello, i feel like having memory leak in the next code while([outData length] + ptr[currentPacket].mDataByteSize < inBytesToGet && currentPacket < packetsCount) { NSLog(@" ++> %d", [aData retainCount]) ; NSInteger sO = ptr[currentPacket].mStartOffset ; NSInteger dS = ptr[currentPacket].mDataByteSize ; NSLog(@" get: cP: %d...