Search Results

Search found 477 results on 20 pages for 'nsdata'.

Page 3/20 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • How to convert an NSArray of NSManagedObjects to NSData

    - by carok
    Hi, I'm new to Objective C and was wondering if anyone can help me. I am using core data with a sqlite database to hold simple profile objects which have a name and a score attribute (both of which are of type NSString). What I want to do is fetch the profiles and store them in an NSData object, please see my code below: NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"GamerProfile" inManagedObjectContext:managedObjectContext]; [fetchRequest setEntity:entity]; NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Name" ascending:YES]; NSArray *sortDecriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; [fetchRequest setSortDescriptors:sortDecriptors]; [sortDescriptor release]; [sortDecriptors release]; NSError *error; NSArray *items = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error]; NSData *data = [NSKeyedArchiver archivedDataWithRootObject:items]; [self SendData:data]; [fetchRequest release]; When I run the code I'm getting the error "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[GamerProfile encodeWithCoder:]: unrecognized selector sent to instance 0x3f4b530'" I presume I have to add an encodeWithCoderClass to my core data NSManagedObject object (GamerProfile) but I'm not sure how to do this even after reading the documentation, My attempt at doing this is below. I'm not sure if I'm going along the right lines with this as get a warning stating "NSManagedObject" may not respond to '-encodeWithCoder'" I would really, really appreciate it if someone could point me in the right direction!! Thanks C Here is the code for my GamerProfile (CoreData NSManagedObject Object) with my attempt at adding an encodeWithCoder method... Header File #import <CoreData/CoreData.h> @interface GamerProfile : NSManagedObject <NSCoding> { } @property (nonatomic, retain) NSString * GamerScore; @property (nonatomic, retain) NSString * Name; - (void)encodeWithCoder:(NSCoder *)coder; @end Code File #import "GamerProfile.h" @implementation GamerProfile @dynamic GamerScore; @dynamic Name; - (void)encodeWithCoder:(NSCoder *)coder { [super encodeWithCoder:coder]; [coder encodeObject:GamerScore forKey:@"GamerScore"]; [coder encodeObject:Name forKey:@"Name"]; }

    Read the article

  • MPMediaPickerController, MPMediaItems, and NSData

    - by ckrames1234
    I was wondering if Apple allowed you to access the MPMediaItem's raw data as an NSData object. If you can, thats great and I would like to know how. If you cannot, then Apple is way too over-protective, and my app that i started is utterly useless. Also if you cannot, Is there any hacky workarounds? I don't care if Apple doesn't accept my app as it would still be cool if me and my friends all had it. Thanks, Conrad

    Read the article

  • How create UIImage from bytes ?

    - by Sergey
    Hello, all! I need in UIImage created from my colors (for example, i need in image 1x1 pixel with black color). I've got array: unsigned char *color[] = {0, 0, 0, 1}; How can i create UIImage from this array ? I've try unsigned char *bytes[4] = {0,0,0,1}; NSData *data = [NSData dataWithBytes:bytes length:4]; UIImage *img = [UIImage imageWithData:data]; but this method has no result...

    Read the article

  • [IOS SDK] Sending Data to Other Players - Game Center

    - by mohacs
    Hi guys, I am developing a simple game center multiplayer game. i did manage almost everything except sending messeage to players. what i mean, i can invite player to play game, game is starts etc. regarding apple documentation i am using following method to send data but it' doesn't work at all. const char *bytes = "123"; NSData *packet = [NSData dataWithBytes:&bytes length:3]; [myMatch sendDataToAllPlayers: packet withDataMode: GKMatchSendDataUnreliable error:nil]; if possible a working sample would be great. many thanks.

    Read the article

  • What Am I Missing? : iPhone Objective-C NSInputStream initWithData

    - by gabe
    I'm creating an NSInputStream from an NSData object but once created the stream reports NO for hasBytesAvailable: NSData* data = [outputStream propertyForKey: NSStreamDataWrittenToMemoryStreamKey]; NSLog(@"creating stream with data 0x%x length %d", [data bytes], [data length]); NSInputStream *insrm = [[NSInputStream alloc] initWithData:data]; [insrm open]; uint8_t* buf = NULL; NSUInteger len; BOOL result = [insrm getBuffer:&buf length:&len]; BOOL hasbytes = [insrm hasBytesAvailable]; NSLog(@"getBuffer:%d hasBytes:%d", result, hasbytes); NSLog(@"created inputstream data %d len %d", buf, len); Log: [26797:20b] creating stream with data 0x7050000 length 34672 [26797:20b] getBuffer:0 hasBytes:0 [26797:20b] created inputstream data 0 len 0 What am I missing here?

    Read the article

  • Can't find .js file in my mainBundle?!

    - by Nic Hubbard
    This is driving me crazy as I cannot figure out what in the world is going on. I load up files form you main bundle all the time, xml files, html files, etc. But, now I am trying to get the contents of a javascript file but it can never find it. I am using: NSData *jsData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"global" ofType:@"js"]]; if (jsData) { NSLog(@"%@", jsData); } else { NSLog(@"Can't find file"); return; } Even checking the [[NSBundle mainBundle] pathForResource:@"global" ofType:@"js"] string returns null. My globaly.js file is in my Resources folder, the exact location where my other files are location that work totally fine using the above method. Why can't it find my js file?

    Read the article

  • Objective C: Can't find .js file in my mainBundle?!

    - by Nic Hubbard
    This is driving me crazy as I cannot figure out what in the world is going on. I load up files form you main bundle all the time, xml files, html files, etc. But, now I am trying to get the contents of a javascript file but it can never find it. I am using: NSData *jsData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"global" ofType:@"js"]]; if (jsData) { NSLog(@"%@", jsData); } else { NSLog(@"Can't find file"); return; } Even checking the [[NSBundle mainBundle] pathForResource:@"global" ofType:@"js"] string returns null. My activity.js file is in my Resources folder, the exact location where my other files are location that work totally fine using the above method. Why can't it find my js file?

    Read the article

  • How to convert CFDataRef data to UIImage / NSData - Iphone

    - by sagar
    Hello ! every one. I am having a little query regarding CFData in Objective C / iPhone Development. See, Apple documentation has following method for CGPDFStream CGPDFStreamCopyData(<#CGPDFStreamRef stream#>, <#CGPDFDataFormat *format#>) Above method return type is CGDataRef. I have data as stream. Now I wish to convert in image. & For that I think I should follow this way. CGPDFDataFormat t=CGPDFDataFormatJPEG2000; CFDataRef data = CGPDFStreamCopyData (stream, &t); After executing above statements - I have some reference in data variable. Now my Query is - How to convert this CFData to NSData or UIImage ? I have gone through the documentation of apple - But I am failure to find it. Thanks in advance for sharing your knowledge. Sagar

    Read the article

  • How to uncompress the NSData in Php which is compressed using zlib in Iphone

    - by Gaurav Arora
    Hello Everyone, I am quite new to Iphone development , so please bear me if I ask some some common questions. In my application I have to transfer data from my Iphone app to a PHP server and for this I have to compress the NSdata in my Iphone app and then pass it on to the PHP server and then Uncompress it in PHP and process the data sent by Iphone in PHP. For compressing the data in Iphone I have used zlib library.Now on PHP side I want to uncompress this data , but I am unable to do so. Can anyone help me in uncompressing this data in PHP. Thanks in Advance. Gaurav Arora

    Read the article

  • implementing UIActivityIndicatorView while NSData dataWithContentsOfURL is downloading

    - by padatronic
    Hi people, I am downloading an mp3 using NSData dataWithContentsOfURL:url. This takes a while and while the file is downloading the application hangs. I want to handle well and ideal would like to show the download progress but can't find methods for this. It is in a UIViewController and I have made a first attempt by putting in a UIActivityIndicatorView and start it spinning before I start the download, then stop it spinning after but nothing appears. So my question really is please could someone tell me what the best way to handle this is? Thanks so much

    Read the article

  • Releasing NSData causes exception...

    - by badmanj
    Hi, Can someone please explain why the following code causes my app to bomb? NSData *myImage = UIImagePNGRepresentation(imageView.image); : [myImage release]; If I comment out the 'release' line, the app runs... but a few times calling the function containing this code and I get a crash - I guess caused by a memory leak. Even if I comment EVERYTHING else in the function out and just leave those two lines, when the release executes, the app crashes. I'm sure this must be a newbie "you don't know how to clean up your mess properly" kind of thing ;-) Cheers, Jamie.

    Read the article

  • NSManagedObjectID into NSData

    - by papr
    I found this wonderful NSManagedObjectID. This would be very good for referencing an Entity/NSManagedObject/NSEntityDescription, right? Let's get an ID from an entity: NSEntityDescription *entity = [self newEntity]; NSManagedObjectID *objID = [entity objectID]; So... any idea how to get this objID into a string? Or better: NSData. Actually something to be able to save it to the NSUserDefaults. ;-) Btw: NSFetchRequest doesn't want to work in my case. I use an modified version of this example: answer of an old question.

    Read the article

  • obj-c problem setting array with componentsSeperatedByString

    - by Brodie4598
    I have a data source with about 2000 lines that look like the following: 6712,Anaktuvuk Pass Airport,Anaktuvuk Pass,United States,AKP,PAKP,68.1336,-151.743,2103,-9,A What I am interested in is the 6th section of this string so I want to turn it into an array, then i want to check the 6th section [5] for an occurrance of that string "PAKP" Code: NSBundle *bundle = [NSBundle mainBundle]; NSString *airportsPath = [bundle pathForResource:@"airports" ofType:@"dat"]; NSData *data = [NSData dataWithContentsOfFile:airportsPath]; NSString *dataString = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]; NSArray *dataArray = [dataString componentsSeparatedByString:@"\n"]; NSRange locationOfAirport; NSString *workingString = [[NSString alloc]initWithFormat:@""]; NSString *searchedAirport = [[NSString alloc]initWithFormat:@""]; NSString *airportData = [[NSString alloc]initWithFormat:@""]; int d; for (d=0; d < [dataArray count]; d=d+1) { workingString = [dataArray objectAtIndex:d]; testTextBox = workingString; //works correctly NSArray *workingArray = [workingString componentsSeparatedByString:@","]; testTextBox2 = [workingArray objectAtIndex: 0]; //correctly displays the first section "6712" testTextBox3 = [workingArray objectAtIndex:1] //throws exception index beyond bounds locationOfAirport = [[workingArray objectAtIndex:5] rangeOfString:@"PAKP"]; } the problem is that when the workingArray populates, it only populates with a single object (the first component of the string which is "6712". If i have it display the workingString, it correctly displays the entire string, but for some reason, it isn't correctly making the array using the commas. i tried it without using the data file and it worked fine, so the problem comes from how I am importing the data. ideas?

    Read the article

  • Covert uiiamge into string

    - by Warrior
    I am new iphone development.Is there any possibility to covert the uiimage into string and then once again back to image. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img1 editingInfo:(NSDictionary *)editInfo { [[picker parentViewController] dismissModalViewControllerAnimated:YES]; NSData *data = UIImagePNGRepresentation(img1); NSString *str1; str1 = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; MyAppAppDelegate *appDelegate = (MyAppAppDelegate *) [[UIApplication sharedApplication] delegate]; [appDelegate setCurrentLink:str1]; EmailPictureViewController *email = [[EmailPictureViewController alloc] initWithNibName:@"EmailPictureViewController" bundle:nil]; [self.navigationController pushViewController:email animated:YES]; } so i can use delegate methods to tranfer the image from one view to another view. so i should convert the string once again to image and display it in another view. In Another view - (void)viewDidLoad { MyAppAppDelegate *appDelegate =(MyAppAppDelegate *) [[UIApplication sharedApplication] delegate]; str1 = [appDelegate getCurrentLink]; NSLog(@"The String %@",str1); NSData *aData; aData = [str1 dataUsingEncoding: NSASCIIStringEncoding]; NSLog(@"The String Data %@",aData); NSLog(@"Inside Didload3"); [imgview setImage:[UIImage imageWithData:aData]]; } But this doesn't work for me.Where do i go wrong.Is there any way to solve it?.Please help me out.Thanks.

    Read the article

  • UIImage created from CGImageRef fails with UIImagePNGRepresentation

    - by Ari J.R.
    I'm using the following code to crop and create a new UIImage out of a bigger one. I've isolated the issue to be with the function CGImageCreateWithImageInRect() which seem to not set some CGImage property the way I want. :-) The problem is that a call to function UIImagePNGRepresentation() fails returning a nil. CGImageRef origRef = [stillView.image CGImage]; CGImageRef cgCrop = CGImageCreateWithImageInRect( origRef, theRect); UIImage *imgCrop = [UIImage imageWithCGImage:cgCrop]; ... NSData *data = UIImagePNGRepresentation ( imgCrop); -- libpng error: No IDATs written into file Any idea what might wrong or alternative for cropping a rect out of UIImage? Many thanks!

    Read the article

  • Storing CLLocationCoordinates2D in NSMutableArray

    - by Amarsh
    After some searching, I got the following solution : ref: http://stackoverflow.com/questions/1392909/nsmutablearray-addobject-with-mallocd-struct 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 way of storing a list of CLLocationCoordinate2D in NSMutableArray? Please give sample code since I am an Objective C newbie.

    Read the article

  • Elegant Algorithm for Parsing Data Stream Into Record

    - by Matt Long
    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 capture the data until what I've captured contains the header. Then, everything that precedes the header goes into the previous record and everything that comes after it goes into a new record. I have this working, but wondered if anyone has done this before and has a good computer-sciencey way to solve the problem. Here's what I do: Convert the NSData of the current read to an NSString Append the NSString to a placeholder string Check placeholder string for the header (DATA:). If the header is not there, just wait for the next read. If the header exists, append whatever precedes it to a previous record placeholder and hand that placeholder off to an array as a complete record that I can further parse into fields. Take whatever shows up after the header and place it in the record placeholder so that it can be appended to in the next read. Repeat steps 3 - 5. Let me know if you see any flaws with this or have a suggestion for a better way. Seems there should be some design pattern for this, but I can't think of one. Thanks.

    Read the article

  • While saving a PNG image using NSData writetofile saves corrupted data on the iphone disk

    - by jAmi
    I have a number of images (PNG,GIF and JPG) in my Application Resource Bundle. I want some images to be saved in my Documents Directory so i use : imgPath=[documentsDirectoryPath stringByAppendingPathComponent:@"myImage.png"]; if (![fileMgr fileExistsAtPath:imgPath]) { [[fileMgr contentsAtPath:[[NSBundle mainBundle] pathForResource:@"myImage"ofType:@"png"]] writeToFile:imgPath atomically:NO]; } This saves an Image file on my desired Path but this file has an Extra 300 bytes (of maybe junk data) in it which results in a corrupted image... Am i doing something wrong here? This works in the simulator but on the real device the image has some extra 300 bytes. Also a GIF image gets copied nicely and works but this problem occurs for PNG image.

    Read the article

  • game state singleton cocos2d, initWithEncoder always returns null

    - by taber
    Hi, I'm trying to write a basic test "game state" singleton in cocos2d, but for some reason upon loading the app, initWithCoder is never called. Any help would be much appreciated, thanks. Here's my singleton GameState.h: #import "cocos2d.h" @interface GameState : NSObject <NSCoding> { NSInteger level, score; Boolean seenInstructions; } @property (readwrite) NSInteger level; @property (readwrite) NSInteger score; @property (readwrite) Boolean seenInstructions; +(GameState *) sharedState; +(void) loadState; +(void) saveState; @end ... and GameState.m: #import "GameState.h" #import "Constants.h" @implementation GameState static GameState *sharedState = nil; @synthesize level, score, seenInstructions; -(void)dealloc { [super dealloc]; } -(id)init { if(!(self = [super init])) return nil; level = 1; score = 0; seenInstructions = NO; return self; } +(void)loadState { @synchronized([GameState class]) { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *saveFile = [documentsDirectory stringByAppendingPathComponent:kSaveFileName]; Boolean saveFileExists = [[NSFileManager defaultManager] fileExistsAtPath:saveFile]; if(!sharedState) { sharedState = [GameState sharedState]; } if(saveFileExists == YES) { [sharedState release]; sharedState = [[NSKeyedUnarchiver unarchiveObjectWithFile:saveFile] retain]; } // at this point, sharedState is null, saveFileExists is 1 if(sharedState == nil) { // this always occurs CCLOG(@"Couldn't load game state, so initialized with defaults"); sharedState = [self sharedState]; } } } +(void)saveState { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *saveFile = [documentsDirectory stringByAppendingPathComponent:kSaveFileName]; [NSKeyedArchiver archiveRootObject:[GameState sharedState] toFile:saveFile]; } +(GameState *)sharedState { @synchronized([GameState class]) { if(!sharedState) { [[GameState alloc] init]; } return sharedState; } return nil; } +(id)alloc { @synchronized([GameState class]) { NSAssert(sharedState == nil, @"Attempted to allocate a second instance of a singleton."); sharedState = [super alloc]; return sharedState; } return nil; } +(id)allocWithZone:(NSZone *)zone { @synchronized([GameState class]) { if(!sharedState) { sharedState = [super allocWithZone:zone]; return sharedState; } } return nil; } ... -(void)encodeWithCoder:(NSCoder *)coder { [coder encodeInt:level forKey:@"level"]; [coder encodeInt:score forKey:@"score"]; [coder encodeBool:seenInstructions forKey:@"seenInstructions"]; } -(id)initWithCoder:(NSCoder *)coder { CCLOG(@"initWithCoder called"); self = [super init]; if(self != nil) { CCLOG(@"initWithCoder self exists"); level = [coder decodeIntForKey:@"level"]; score = [coder decodeIntForKey:@"score"]; seenInstructions = [coder decodeBoolForKey:@"seenInstructions"]; } return self; } @end ... I'm saving the state on app exit, like this: - (void)applicationWillTerminate:(UIApplication *)application { [GameState saveState]; [[CCDirector sharedDirector] end]; } ... and loading the state when the app finishes loading, like this: - (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... [GameState loadState]; ... } I've tried moving around where I call loadState too, for example in my main CCScene, but that didn't seem to work either. Thanks again in advance.

    Read the article

  • NSMutableUrlRequest eats plus signs

    - by Mike
    I create NSMutableUrlRequest for sending data to server, add all necessary fields to it and then add the string for sending like this: [theRequest setHTTPBody:[postString dataUsingEncoding: NSUTF8StringEncoding]]; postString is a usual NSString. The problem is, when I receive this request at the server, all the plus (+) signs disappear from the http body. So if I had "abcde+fghj" on iPhone, I get "abcde fghj" on the server". Can this be some encoding problem from using dataUsingEncoding: NSUTF8StringEncoding? Or some NSMutableUrlRequest stripping feature? What can I do to make it stop stripping plus signs? I need to receive UTF8 strings at the server side.

    Read the article

  • Email from an app, but not use a a pop up controller, just text inside a text box.

    - by Sam Jarman
    Hey is there any way to send whats in a text view (im trying to make a suggestion box) to my email address? example user types in the box " I think you should add twitter support" then that is sent in the background to my email address [email protected] then a message is popped up on the screen saying "suggestion sent" just an example of what i mean Any ideas, tutorial links would be greatly appreciated guys Thanks

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >