nsdata

malloc error - incorrect checksum for freed object - object was probably modified after being freed

心不动则不痛 提交于 2020-01-06 01:53:17
问题 I'm trying to get sub data of NSData object and at the same time multiple bytes by some value for my personal need . actually this affect the volume of .wav sound file . but i get after few calls to the following function a malloc error at the malloc statement . +(NSData *) subDataOfData: (NSData *) mainData withRange:(NSRange) range volume (CGFloat) volume { // here is the problematic line: Byte * soundWithVolumeBytes = (Byte*)malloc(range.length); Byte * mainSoundFileBytes =(Byte *)

How to convert NSData variable into NSInteger variable in iOS

前提是你 提交于 2020-01-05 11:49:13
问题 I have the following api method which returns NSData . I have called this method in another view controller. How to convert the NSData to NSInteger ? -(NSData *)getBusXMLAtStop:(NSString*)stopnumber { NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: [NSString stringWithFormat:@"http://www.google.com/ig/api?weather=,,,50500000,30500000",stopnumber]]]; [request setHTTPMethod: @"GET"]; dataReply = [NSURLConnection sendSynchronousRequest:request

How to convert NSData variable into NSInteger variable in iOS

主宰稳场 提交于 2020-01-05 11:49:10
问题 I have the following api method which returns NSData . I have called this method in another view controller. How to convert the NSData to NSInteger ? -(NSData *)getBusXMLAtStop:(NSString*)stopnumber { NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: [NSString stringWithFormat:@"http://www.google.com/ig/api?weather=,,,50500000,30500000",stopnumber]]]; [request setHTTPMethod: @"GET"]; dataReply = [NSURLConnection sendSynchronousRequest:request

Not all keys work when converting JSON String to NSDictionary

感情迁移 提交于 2020-01-04 07:00:32
问题 I'm using the following code to convert a JSON string literal to an array holding an NSDictionary for each item: NSString* json = @"[{\"name\":\"Item 1\",\"id\":\"999\",\"lang\":\"en\",\"type\":\"A\",\"version\":15}]"; NSData* data = [json dataUsingEncoding:NSUTF8StringEncoding]; NSArray* values = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; After removing the app from my test device, the app started crashing when attempting to access, in a

Converting NSData to CGImage and then back to NSData makes the file too big

柔情痞子 提交于 2020-01-04 04:10:48
问题 I have built a camera using AVFoundation . Once my AVCaptureStillImageOutput has completed its captureStillImageAsynchronouslyFromConnection:completionHandler: method, I create a NSData object like this: NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer]; Once I have the NSData object, I would like to rotate the image -without- converting to a UIImage . I have found out that I can convert to a CGImage to do so. After I have the imageData,

How to convert NSData of Image from database to NSString in iPhone?

﹥>﹥吖頭↗ 提交于 2020-01-03 05:06:11
问题 I am converting NSData of Image from database to NSString in iPhone Here is my code imageData1 = [[NSData alloc] initWithBytes:sqlite3_column_blob(compiledStatement, 2) length: sqlite3_column_bytes(compiledStatement, 2)]; NSLog(@"the data length %d",[imageData1 length]); NSString* newStr1 = [[NSString alloc] initWithData:imageData1 encoding:NSUTF8StringEncoding]; The length of data is 6511 , but the newstr1 is nil With reference to this stack overflow question. I can't create a UTF-8 encoded

Undo in painting apps like Penultimate and iDraft

谁说我不能喝 提交于 2020-01-03 04:45:27
问题 In apps like iDraft and Penultimate, they perform undos and redos very well without any delay. I tried many approaches. Currently, my testing app writes raw pixel data directly to a file after each undo using [NSData writeToFile:atomically:] but I am getting 0.6s delay. Can anyone give some hints on it? 回答1: I don’t know iDraft nor Penultimate, but chances are they have a simpler drawing model than you have. When writing a drawing app you can choose between two essential drawing

JSON format: getting output in the correct order [duplicate]

。_饼干妹妹 提交于 2020-01-03 03:16:10
问题 This question already has an answer here : Keeping dictionary keys of JSON Object in order in Objective C (1 answer) Closed 5 years ago . Common task, converting strings to a JSON format. Yes, easy, plenty of answers on StackOverflow about this. What is not as easy is to understand for me is why the order I get is different from the order I put the pair objects in the NSDictionary. That's the code I wrote: -(NSString*)createJSONstring { //http://www.raywenderlich.com/5492/working-with-json-in

Storing and Restoring std::vector from NSData

风格不统一 提交于 2020-01-03 01:35:41
问题 I am attempting to store std::vector to NSData and back directly. My first attempt I converted each point to an NSValue and stored them with NSKeyedUnarchiver which seems terribly inefficient. My test dataset required 64MB of human readable text (with NSKeyedUnarchiver), versus converting each std:vector to NSData the resulting stored files is a much more reasonable 896kb. I am doing as follows to store the data: typedef std::vector<CGPoint> CGContour; typedef std::vector<std::vector<CGPoint>

Leak or Crash - difference between autorelease and release

核能气质少年 提交于 2020-01-02 11:27:13
问题 I have a comprehension question. This method is given: - (NSArray*)test { NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://stackoverflow.com/"]]; NSString *result = [[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSMacOSRomanStringEncoding]; result = [result stringByAppendingString:@"something"]; NSArray *arr = [NSArray arrayWithObject:result]; //[result release]; return arr; } If I uncomment the release the App would crash and say it