Search Results

Search found 290 results on 12 pages for 'nsnumber'.

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

  • Why is the compiler caching my "random" and NULLED variables?

    - by alex gray
    I am confounded by the fact that even using different programs (on the same machine) to run /compile, and after nilling the vaues (before and after) the function.. that NO MATTER WHAT.. I'll keep getting the SAME "random" numbers… each and every time I run it. I swear this is NOT how it's supposed to work.. I'm going to illustrate as simply as is possible… #import <Foundation/Foundation.h> int main(int argc, char *argv[]) { int rPrimitive = 0; rPrimitive = 1 + rand() % 50; NSNumber *rObject = nil; rObject = [NSNumber numberWithInt:rand() % 10]; NSLog(@"%i %@", rPrimitive, rObject); rPrimitive = 0; rObject = nil; NSLog(@"%i %@", rPrimitive, rObject); return 0; } Run it in TextMate: i686-apple-darwin11-llvm-gcc-4.2 8 9 0 (null) Run it in CodeRunner: i686-apple-darwin11-llvm-gcc-4.2 8 9 0 (null) Run it a million times, if you'd like. You can gues what it will always be. Why does this happen? Why oh why is this "how it is"?

    Read the article

  • Memory Leak in returning NSMutableArray from class

    - by Structurer
    Hi I am quite new to Objective C for the iPhone, so I hope you wont kill me for asking a simple question. I have made an App that works fine, except that Instruments reports memory leaks from the class below. I use it to store settings from one class and then retrieve them from another class. These settings are stored on a file so they can be retrieved every time the App is ran. What can I do do release the "setting" and is there anything that can be done to call (use) the class in a smarter way? Thanks ----- Below is Settings.m ----- import "Settings.h" @implementation Settings @synthesize settings; -(NSString *)dataFilePath // Return path for settingfile, including filename { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; return [documentsDirectory stringByAppendingPathComponent:kUserSettingsFileName]; } -(NSMutableArray *)getParameters // Return settings from disk after checking if file exist (if not create with default values) { NSString *filePath = [self dataFilePath]; if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) // Getting data from file { settings = [[NSMutableArray alloc] initWithContentsOfFile:filePath]; } else // Creating default settings { settings = [[NSMutableArray alloc] initWithObjects: [NSNumber numberWithInteger:50], [NSNumber numberWithInteger:50], nil]; [settings writeToFile:[self dataFilePath] atomically:YES]; } return settings; } ----- Below is my other class from where I call my Settings class ----- // Get settings from file Settings *aSetting = [[Settings alloc] init]; mySettings = [aSetting getParameters]; [aSetting release];

    Read the article

  • Refreshing a MKMapView when the user location is updated or using default values

    - by koichirose
    I'm trying to refresh my map view and load new data from the server when the device acquires the user location. Here's what I'm doing: - (void)viewDidLoad { CGRect bounds = self.view.bounds; mapView = [[MKMapView alloc] initWithFrame:bounds]; mapView.showsUserLocation=YES; mapView.delegate=self; [self.view insertSubview:mapView atIndex:0]; [self refreshMap]; } - (void)mapView:(MKMapView *)theMapView didUpdateUserLocation:(MKUserLocation *)userLocation { //this is to avoid frequent updates, I just need one position and don't need to continuously track the user's location if (userLocation.location.horizontalAccuracy > self.myUserLocation.location.horizontalAccuracy) { self.myUserLocation = userLocation; CLLocationCoordinate2D centerCoord = { userLocation.location.coordinate.latitude, userLocation.location.coordinate.longitude }; [theMapView setCenterCoordinate:centerCoord zoomLevel:10 animated:YES]; [self refreshMap]; } } - (void)refreshMap { [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; [self.mapView removeAnnotations:self.mapView.annotations]; //default position NSString *lat = @"45.464161"; NSString *lon = @"9.190336"; if (self.myUserLocation != nil) { lat = [[NSNumber numberWithDouble:myUserLocation.coordinate.latitude] stringValue]; lon = [[NSNumber numberWithDouble:myUserLocation.coordinate.longitude] stringValue]; } NSString *url = [[NSString alloc] initWithFormat:@"http://myserver/geo_search.json?lat=%@&lon=%@", lat, lon]; NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; [url release]; [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO]; } I also have a - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data, to create and add the annotations. Here's what happens: sometimes I get the location after a while, so I already loaded data close to the default location. Then I get the location and it should remove the old annotations and add the new ones, instead I keep seeing the old annotations and the new ones are added anyway (let's say I receive 10 annotations each time, so it means that I have 20 on my map when I should have 10). What am I doing wrong?

    Read the article

  • NSPredicate always gives back the same data

    - by Stef Geelen
    I am trying to work with NSPredicates. But it always give me back the same array. Here you can see my predicate. NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"whichAlbum.album_id == %d", AlbumId]; [request setEntity:[NSEntityDescription entityForName:@"Picture" inManagedObjectContext:self.genkDatabase.managedObjectContext]]; [request setPredicate:predicate]; Also when I try it hardcoded. It gives back the same array. NSPredicate *predicate = [NSPredicate predicateWithFormat:@"whichAlbum.album_id == 5"]; Here you can see my database model. And here you can see how I put data in my database for entity Picture. + (Picture *)pictureWithGenkInfo:(NSDictionary *)genkInfo inManagedObjectContext:(NSManagedObjectContext *)context withAlbumId:(int)albumId withPictureId:(int)pictureId; { Picture *picture = nil; picture = [NSEntityDescription insertNewObjectForEntityForName:@"Picture" inManagedObjectContext:context]; picture.url = [genkInfo objectForKey:PICTURES_URL]; picture.pic_album_id = [NSNumber numberWithInt:albumId]; picture.picture_id = [NSNumber numberWithInt:pictureId]; return picture; } Anybody can help me ? Kind regards

    Read the article

  • NSInvocation making app crash

    - by neha
    Hi all, I'm using NSInvocation as follows: In my init, I'm writing this in my viewDidLoad: SEL mySelector; mySelector = @selector(initParsersetId:type:); NSMethodSignature * sig = nil; sig = [[self class] instanceMethodSignatureForSelector:mySelector]; myInvocation = nil; myInvocation = [NSInvocation invocationWithMethodSignature:sig]; [myInvocation setTarget:self]; [myInvocation setSelector:mySelector]; SEL mySelector; mySelector = @selector(initParsersetId:type:); NSMethodSignature * sig = nil; sig = [[self class] instanceMethodSignatureForSelector:mySelector]; myInvocation = nil; myInvocation = [NSInvocation invocationWithMethodSignature:sig]; [myInvocation setTarget:self]; [myInvocation setSelector:mySelector]; And I'm calling it like this: Idea *tempIdea = [[Idea alloc]init]; tempIdea = [genericArray objectAtIndex:indexPath.row]; idea.ideaId = tempIdea.ideaId; [tempIdea release]; NSNumber *_id_ = [NSNumber numberWithInt:idea.ideaId]; [myInvocation setArgument:_id_ atIndex:2]; //CRASHING AT THIS LINE My application is crashing at the indicated line. Can anybody please help me?

    Read the article

  • UIBezierPath too many paths = too slow?

    - by HHHH
    I have a loop in which I'm adding many (10000+) lines to a UIBezierPath. This seems to be fine, but once I try and render the bezierpath, my device becomes extremely slow and jerky. Is this because I've added too many lines to my path? Adding lines to UIBezierPath - simplified: (this seems fine) [path moveToPoint:CGPointZero]; for (int i = 0; i < 10000; i++ ) { [path addLineToPoint:CGPointMake(i, i)]; } Rendering BeizerPath (Suggested by Rob) - this seems slow. - (void)drawBezierAnimate:(BOOL)animate { UIBezierPath *bezierPath = path; CAShapeLayer *bezier = [[CAShapeLayer alloc] init]; bezier.path = bezierPath.CGPath; bezier.strokeColor = [UIColor blueColor].CGColor; bezier.fillColor = [UIColor clearColor].CGColor; bezier.lineWidth = 2.0; bezier.strokeStart = 0.0; bezier.strokeEnd = 1.0; [self.layer addSublayer:bezier]; if (animate) { CABasicAnimation *animateStrokeEnd = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; animateStrokeEnd.duration = 100.0; animateStrokeEnd.fromValue = [NSNumber numberWithFloat:0.0f]; animateStrokeEnd.toValue = [NSNumber numberWithFloat:1.0f]; [bezier addAnimation:animateStrokeEnd forKey:@"strokeEndAnimation"]; } } Qs: 1) Is this because I'm adding too many paths too quickly? 2) I want to eventually draw many different lines of different colors, so I assume I would need to create multiple (10000+) UIBezierPaths - would this help or greatly slow the device as well? 3) How would I get around this? Thanks in advance for your help.

    Read the article

  • Is conditional return type ever a good idea?

    - by qegal
    So I have a method that's something like this: -(BOOL)isSingleValueRecord And another method like this: -(Type)typeOfSingleValueRecord And it occurred to me that I could combine them into something like this: -(id)isSingleValueRecord And have the implementation be something like this: -(id)isSingleValueRecord { //If it is single value if(self.recordValue = 0) { //Do some stuff to determine type, then return it return typeOfSingleValueRecord; } //If its not single value else { //Return "NO" return [NSNumber numberWithBool:NO]; } } So combining the two methods makes it more efficient but makes the readability go down. In my gut, I feel like I should go with the two-method version, but is that really right? Is there any case that I should go with the combined version?

    Read the article

  • Core Data migration failing with error: Failed to save new store after first pass of migration

    - by unforgiven
    In the past I had already implemented successfully automatic migration from version 1 of my data model to version 2. Now, using SDK 3.1.3, migrating from version 2 to version 3 fails with the following error: Unresolved error Error Domain=NSCocoaErrorDomain Code=134110 UserInfo=0x5363360 "Operation could not be completed. (Cocoa error 134110.)", { NSUnderlyingError = Error Domain=NSCocoaErrorDomain Code=256 UserInfo=0x53622b0 "Operation could not be completed. (Cocoa error 256.)"; reason = "Failed to save new store after first pass of migration."; } I have tried automatic migration using NSMigratePersistentStoresAutomaticallyOption and NSInferMappingModelAutomaticallyOption and also migration using only NSMigratePersistentStoresAutomaticallyOption, providing a mapping model from v2 to v3. I see the above error logged, and no object is available in the application. However, if I quit the application and reopen it, everything is in place and working. The Core Data methods I am using are the following ones - (NSManagedObjectModel *)managedObjectModel { if (managedObjectModel != nil) { return managedObjectModel; } NSString *path = [[NSBundle mainBundle] pathForResource:@"MYAPP" ofType:@"momd"]; NSURL *momURL = [NSURL fileURLWithPath:path]; managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL]; return managedObjectModel; } - (NSManagedObjectContext *) managedObjectContext { if (managedObjectContext != nil) { return managedObjectContext; } NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; if (coordinator != nil) { managedObjectContext = [[NSManagedObjectContext alloc] init]; [managedObjectContext setPersistentStoreCoordinator: coordinator]; } return managedObjectContext; } - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (persistentStoreCoordinator != nil) { return persistentStoreCoordinator; } NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"MYAPP.sqlite"]]; NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; NSError *error = nil; persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]]; if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) { // Handle error NSLog(@"Unresolved error %@, %@", error, [error userInfo]); } return persistentStoreCoordinator; } In the simulator, I see that this generates a MYAPP~.sqlite files and a MYAPP.sqlite file. I tried to remove the MYAPP~.sqlite file, but BOOL oldExists = [[NSFileManager defaultManager] fileExistsAtPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"MYAPP~.sqlite"]]; always returns NO. Any clue? Am I doing something wrong? Thank you in advance.

    Read the article

  • NSDictionary - Read BOOL from Internet-Downloaded Plist

    - by David Schiefer
    Hi, I am downloading a PLIST file from my server using NSURLDownload. Once it is downloaded, I read the file using NSDictionary's dictionaryWithContentsOfFile: method. I need to read a BOOL value, so this is my code: if ([dict objectForKey:string] == [NSNumber numberWithBool:YES]) This however always returns NO, no matter what the value is. The same happens if I replace the == with isEqual:. Am I doing this wrong?

    Read the article

  • iPhone Objective C - error: pointer value used where a floating point value was expected

    - by Mausimo
    I do not understand why i am getting this error. Here is the related code: Photo.h #import <CoreData/CoreData.h> @class Person; @interface Photo : NSManagedObject { } @property (nonatomic, retain) NSData * imageData; @property (nonatomic, retain) NSNumber * Latitude; @property (nonatomic, retain) NSString * ImageName; @property (nonatomic, retain) NSString * ImagePath; @property (nonatomic, retain) NSNumber * Longitude; @property (nonatomic, retain) Person * PhotoToPerson; @end Photo.m #import "Photo.h" #import "Person.h" @implementation Photo @dynamic imageData; @dynamic Latitude; @dynamic ImageName; @dynamic ImagePath; @dynamic Longitude; @dynamic PhotoToPerson; @end This is a mapViewController.m class i have created. If i run this, the CLLocationDegrees CLLat and CLLong lines: CLLocationDegrees CLLat = (CLLocationDegrees)photo.Latitude; CLLocationDegrees CLLong = (CLLocationDegrees)photo.Longitude; give me the error : pointer value used where a floating point value was expected. for(int i = 0; i < iPerson; i++) { //get the person that corresponds to the row indexPath that is currently being rendered and set the text Person * person = (Person *)[myArrayPerson objectAtIndex:i]; //get the photos associated with the person NSArray * PhotoArray = [person.PersonToPhoto allObjects]; int iPhoto = [PhotoArray count]; for(int j = 0; j < iPhoto; j++) { //get the first photo (all people will have atleast 1 photo, else they will not exist). Set the image Photo * photo = (Photo *)[PhotoArray objectAtIndex:j]; if(photo.Latitude != nil && photo.Longitude != nil) { MyAnnotation *ann = [[MyAnnotation alloc] init]; ann.title = photo.ImageName; ann.subtitle = photo.ImageName; CLLocationCoordinate2D cord; CLLocationDegrees CLLat = (CLLocationDegrees)photo.Latitude; CLLocationDegrees CLLong = (CLLocationDegrees)photo.Longitude; cord.latitude = CLLat; cord.longitude = CLLong; ann.coordinate = cord; [mkMapView addAnnotation:ann]; } } }

    Read the article

  • NSObjectController confusion binding to a class property. Help!

    - by scottw
    Hi, I'm teaching myself cocoa and enjoying the experience most of the time. I have been struggling all day with a simple problem that google has let me down on. I have read the Cocoa Bindings Program Topics and think I grok it but still can't solve my issue. I have a very simple class called MTSong that has various properties. I have used @synthesize to create getter/setters and can use KVC to change properties. i.e in my app controller the following works: mySong = [[MTSong alloc]init]; [mySong setValue:@"2" forKey:@"version"]; In case I am doing something noddy in my class code MTSong.h is: #import <Foundation/Foundation.h> @interface MTSong : NSObject { NSNumber *version; NSString *name; } @property(readwrite, assign) NSNumber *version; @property(readwrite, assign) NSString *name; @end and MTSong.m is: #import "MTSong.h" @implementation MTSong - (id)init { [super init]; return self; } - (void)dealloc { [super dealloc]; } @synthesize version; @synthesize name; @end In Interface Builder I have a label (NSTextField) that I want to update whenever I use KVC to change the version of the song. I do the following: Drag NSObjectController object into the doc window and in the Inspector-Attributes I set: Mode: Class Class Name: MTSong Add a key called version and another called name Go to Inspector-Bindings-Controller Content Bind To: File's Owner (Not sure this is right...) Model Key Path: version Select the cell of the label and go to Inspector Bind to: Object Controller Controller Key: mySong Model Key Path: version I have attempted changing the Model Key Path in step 2 to "mySong" which makes more sense but the compiler complains. Any suggestions would be greatly appreciated. Scott Update Post Comments I wasn't exposing mySong property so have changed my AppController.h to be: #import <Cocoa/Cocoa.h> @class MTSong; @interface AppController : NSObject { IBOutlet NSButton *start; IBOutlet NSTextField *tf; MTSong *mySong; } -(IBAction)convertFile:(id)sender; @end I suspect File's owner was wrong as I am not using a document based application and I need to bind to the AppController, so step 2 is now: Go to Inspector-Bindings-Controller Content Bind To: App Controller Model Key Path: mySong I needed to change 3. to Select the cell of the label and go to Inspector Bind to: Object Controller Controller Key: selection Model Key Path: version All compiles and is playing nice!

    Read the article

  • Problem with core data migration mapping model

    - by dpratt
    I have an iphone app that uses Core Data to do storage. I have successfully deployed it, and now I'm working on the second version. I've run into a problem with the data model that will require a few very simple data transformations at the time that the persistent store gets upgraded, so I can't just use the default inferred mapping model. My object model is stored in an .xcdatamodeld bundle, with versions 1.0 and 1.1 next to each other. Version 1.1 is set as the active version. Everything works fine when I use the default migration behavior and set NSInferMappingModelAutomaticallyOption to YES. My sqlite storage gets upgraded from the 1.0 version of the model, and everything is good except for, of course, the few transformations I need done. As an additional experimental step, I added a new Mapping Model to the core data model bundle, and have made no changes to what xcode generated. When I run my app (with an older version of the data store), I get the following * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Object's persistent store is not reachable from this NSManagedObjectContext's coordinator' What am I doing wrong? Here's my code for to get the managed object model and the persistent store coordinator. - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (_persistentStoreCoordinator != nil) { return _persistentStoreCoordinator; } _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"gti_store.sqlite"]]; NSError *error; NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) { NSLog(@"Eror creating persistent store coodinator - %@", [error localizedDescription]); } return _persistentStoreCoordinator; } - (NSManagedObjectModel *)managedObjectModel { if(_managedObjectModel == nil) { _managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain]; NSDictionary *entities = [_managedObjectModel entitiesByName]; //add a sort descriptor to the 'Foo' fetched property so that it can have an ordering - you can't add these from the graphical core data modeler NSEntityDescription *entity = [entities objectForKey:@"Foo"]; NSFetchedPropertyDescription *fetchedProp = [[entity propertiesByName] objectForKey:@"orderedBar"]; NSSortDescriptor* sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"index" ascending:YES] autorelease]; NSArray* sortDescriptors = [NSArray arrayWithObjects:sortDescriptor, nil]; [[fetchedProp fetchRequest] setSortDescriptors:sortDescriptors]; } return _managedObjectModel; }

    Read the article

  • Migration Core Data error code 134130

    - by magichero
    I want to do migration with 2 core database. I have read apple developer document. For the first database, I add some attributes (string, integer and date properties) to new version database. And follow all steps, I have done migration successfully with the first once. But the second database, I also add attributes (string, integer, date, transformable and binary-data properties) to new version database. And follow all steps (like the first database) but system return an error (134130). Here is the code: if (persistentStoreCoordinator_) { PMReleaseSafely(persistentStoreCoordinator_); } // Notify NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc postNotificationName:GCalWillMigrationNotification object:self]; // NSString *sourceStoreType = NSSQLiteStoreType; NSString *dataStorePath = [PMUtility dataStorePathForName:GCalDBWarehousePersistentStoreName]; NSURL *storeURL = [NSURL fileURLWithPath:dataStorePath]; BOOL storeExists = [[NSFileManager defaultManager] fileExistsAtPath:dataStorePath]; // NSError *error = nil; NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; persistentStoreCoordinator_ = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:self.managedObjectModel]; [persistentStoreCoordinator_ addPersistentStoreWithType:sourceStoreType configuration:nil URL:storeURL options:options error:&error]; if (error != nil) { abort(); } error is not nil and below is log: Error Domain=NSCocoaErrorDomain Code=134130 "The operation couldn\u2019t be completed. (Cocoa error 134130.)" UserInfo=0x856f790 {URL=file://localhost/Users/greensun/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/D10712DE-D9FE-411A-8182-C4F58C60EC6D/Library/Application%20Support/Promise%20Mail/GCalDBWarehouse.sqlite, metadata={type = immutable dict, count = 7, entries = 2 : {contents = "NSStoreModelVersionIdentifiers"} = {type = immutable, count = 1, values = ( 0 : {contents = ""} )} 4 : {contents = "NSPersistenceFrameworkVersion"} = {value = +386, type = kCFNumberSInt64Type} 6 : {contents = "NSStoreModelVersionHashes"} = {type = immutable dict, count = 2, entries = 0 : {contents = "SyncEvent"} = {length = 32, capacity = 32, bytes = 0xfdae355f55c13fbd0344415fea26c8bb ... 4c1721aadd4122aa} 1 : {contents = "ImportEvent"} = {length = 32, capacity = 32, bytes = 0x7676888f0d7eaff4d1f844343028ce02 ... 040af6cbe8c5fd01} } 7 : {contents = "NSStoreUUID"} = {contents = "51678BAC-CCFB-4D00-AF5C-8FA1BEDA6440"} 8 : {contents = "NSStoreType"} = {contents = "SQLite"} 9 : {contents = "_NSAutoVacuumLevel"} = {contents = "2"} 10 : {contents = "NSStoreModelVersionHashesVersion"} = {value = +3, type = kCFNumberSInt32Type} }, reason=Can't find model for source store} I try a lot of solutions but it does not work. I just add more attributes to 2 new version database, and succeed in migrating once. Thanks for reading and your help.

    Read the article

  • How can I use this animation code?

    - by O.C.
    I'm a newbie and I need some help. I want to display a popup image over a given UIView, but I would like it to behave like the UIAlertView or like the Facebook Connect for iPhone modal popup window, in that it has a bouncy, rubbber-band-like animation to it. I found some code on the net from someone who was trying to do something similar. He/she put this together, but there was no demo or instructions. Being that I am so new, I don't have any idea as to how to incorporate this into my code. This is the routine where I need the bouncy image to appear: - (void) showProductDetail { . . . //////////////////////////////////////////////////////////////////////// // THIS IS A STRAIGHT SCALE ANIMATION RIGHT NOW. I WANT TO REPLACE THIS // WITH A BOUNCY RUBBER-BAND ANIMATION _productDetail.transform = CGAffineTransformMakeScale(0.1,0.1); [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; _productDetail.transform = CGAffineTransformMakeScale(1,1); [UIView commitAnimations]; } . . . } This is the code I found: float pulsesteps[3] = { 0.2, 1/15., 1/7.5 }; - (void) pulse { self.transform = CGAffineTransformMakeScale(0.6, 0.6); [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:pulsesteps[0]]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(pulseGrowAnimationDidStop:finished:context:)]; self.transform = CGAffineTransformMakeScale(1.1, 1.1); [UIView commitAnimations]; } - (void)pulseGrowAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:pulsesteps[1]]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(pulseShrinkAnimationDidStop:finished:context:)]; self.transform = CGAffineTransformMakeScale(0.9, 0.9); [UIView commitAnimations]; } - (void)pulseShrinkAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:pulsesteps[2]]; self.transform = CGAffineTransformIdentity; [UIView commitAnimations]; } Thanks in advance for any help that you can give me.

    Read the article

  • objective-c determine if parameter is an object

    - by Broch Pirate
    in Objective-c I have this function prototype: -(NSString*)formatSQL:(NSString*) sql, ... I may pass to this function any type of parameters: NSString, NSNumber, integer, float How can I determine in the function if a parameter is an object (NSString..) or a primitive (integer...)? thanks BrochPirate

    Read the article

  • How can Core Data store an NSData?

    - by mystify
    The documentation says, that core data properties can only store NSString, NSNumber and NSDate types. However, a lot of Core Data users claim Core Data could also store an NSData type. But I wasn't able to see that in the documentation, although the Xcode Data Modeler allows to choose a data type called "binary" (which seems to be NSData). Did I miss something? Is there a hidden place in the documentation that indeed lists NSData for binary stuff?

    Read the article

  • How can I use this downloaded Class(es) on my Prototype Routine?

    - by O.C.
    I'm a newbie and I'm in need of some help. I'm working on a prototype for an app, but I'm learning at the same time. I want to display a popup image over a given UIView, but I would like it to behave like the UIAlertView or like the Facebook Connect for iPhone modal popup window, in that it has a bouncy, rubbber-band-like animation to it. I was able to find the following class(es) on the net, from someone who was trying to do something similar. He/she put this together, but there was no Demo, no instructions nor a way to contact them. Being that I am so new, I don't have any idea as to how to incorporate this into my code. This is the routine where I need the bouncy image to appear... //======================================================== // // productDetail // - (void) showProductDetail { _productDetailIndex++; if (_productDetailIndex > 7) { return; } else if (_productDetailIndex == 1) { NSString* filename = [NSString stringWithFormat:@"images/ICS_CatalogApp_0%d_ProductDetailPopup.png", _productDetailIndex]; [_productDetail setImageWithName:filename]; _productDetail.transform = CGAffineTransformMakeScale(0.1,0.1); [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; // other animations goes here _productDetail.transform = CGAffineTransformMakeScale(1,1); // other animations goes here [UIView commitAnimations]; } NSString* filename = [NSString stringWithFormat:@"images/ICS_CatalogApp_0%d_ProductDetailPopup.png", _productDetailIndex]; [_productDetail setImageWithName:filename]; _productDetail.x = (self.width - _productDetail.width); _productDetail.y = (self.height - _productDetail.height); } and here is the code I found... float pulsesteps[3] = { 0.2, 1/15., 1/7.5 }; - (void) pulse { self.transform = CGAffineTransformMakeScale(0.6, 0.6); [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:pulsesteps[0]]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(pulseGrowAnimationDidStop:finished:context:)]; self.transform = CGAffineTransformMakeScale(1.1, 1.1); [UIView commitAnimations]; } - (void)pulseGrowAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:pulsesteps[1]]; [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(pulseShrinkAnimationDidStop:finished:context:)]; self.transform = CGAffineTransformMakeScale(0.9, 0.9); [UIView commitAnimations]; } - (void)pulseShrinkAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:pulsesteps[2]]; self.transform = CGAffineTransformIdentity; [UIView commitAnimations]; } My routine is based on the Prototyping class given by Apple during WWDC 09. It may not be "correct" but it works as is. I just would like to add the animation to this image/screen to really make the concept clear.

    Read the article

  • Import csv data (SDK iphone)

    - by Ni
    I am new to cocoa. I have been working on these stuff for a few days. For the following code, i can read all the data in the string, and successfully get the data for plot. NSMutableArray *contentArray = [NSMutableArray array]; NSString *filePath = @"995,995,995,995,995,995,995,995,1000,997,995,994,992,993,992,989,988,987,990,993,989"; NSArray *myText = [filePath componentsSeparatedByString:@","]; NSInteger idx; for (idx = 0; idx < myText.count; idx++) { NSString *data =[myText objectAtIndex:idx]; NSLog(@"%@", data); id x = [NSNumber numberWithFloat:0+idx*0.002777778]; id y = [NSDecimalNumber decimalNumberWithString:data]; [contentArray addObject: [NSMutableDictionary dictionaryWithObjectsAndKeys:x, @"x", y, @"y", nil]]; } self.dataForPlot = contentArray; then, i try to load the data from csv file. the data in Data.csv file has the same value and the same format as 995,995,995,995,995,995,995,995,1000,997,995,994,992,993,992,989,988,987,990,993,989. I run the code, it is supposed to give the same graph output. however, it seems that the data is not loaded from csv file successfully. i can not figure out what's wrong with my code. NSMutableArray *contentArray = [NSMutableArray array]; NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"csv"]; NSString *Data = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil ]; if (Data) { NSArray *myText = [Data componentsSeparatedByString:@","]; NSInteger idx; for (idx = 0; idx < myText.count; idx++) { NSString *data =[myText objectAtIndex:idx]; NSLog(@"%@", data); id x = [NSNumber numberWithFloat:0+idx*0.002777778]; id y = [NSDecimalNumber decimalNumberWithString:data]; [contentArray addObject: [NSMutableDictionary dictionaryWithObjectsAndKeys:x, @"x", y, @"y",nil]]; } self.dataForPlot = contentArray; } The only difference is NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"csv"]; NSString *Data = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil ]; if (data){ } did i do anything wrong here?? Thanks for your help!!!!

    Read the article

  • Convert NSFileSystemSize to Gigabytes

    - by AWright4911
    I need to convert NSFileSystemSize to Gigabytes. NSDictionary * fsAttributes = [ [NSFileManager defaultManager] fileSystemAttributesAtPath:NSTemporaryDirectory()]; NSNumber *totalSize = [fsAttributes objectForKey:NSFileSystemSize]; NSString *sizeInGB = [NSString stringWithFormat:@"\n\n %3.2f GB",[totalSize floatValue] / 107374824]; //returns 69.86 GB any ideas why it doesnt return at leat 8.0GB's?

    Read the article

  • Crash in OS X Core Data Utility Tutorial

    - by vinogradov
    I'm trying to follow Apple's Core Data utility Tutorial. It was all going nicely, until... The tutorial uses a custom sub-class of NSManagedObject, called 'Run'. Run.h looks like this: #import <Foundation/Foundation.h> #import <CoreData/CoreData.h> @interface Run : NSManagedObject { NSInteger processID; } @property (retain) NSDate *date; @property (retain) NSDate *primitiveDate; @property NSInteger processID; @end Now, in Run.m we have an accessor method for the processID variable: - (void)setProcessID:(int)newProcessID { [self willChangeValueForKey:@"processID"]; processID = newProcessID; [self didChangeValueForKey:@"processID"]; } In main.m, we use functions to set up a managed object model and context, instantiate an entity called run, and add it to the context. We then get the current NSprocessInfo, in preparation for setting the processID of the run object. NSManagedObjectContext *moc = managedObjectContext(); NSEntityDescription *runEntity = [[mom entitiesByName] objectForKey:@"Run"]; Run *run = [[Run alloc] initWithEntity:runEntity insertIntoManagedObjectContext:moc]; NSProcessInfo *processInfo = [NSProcessInfo processInfo]; Next, we try to call the accessor method defined in Run.m to set the value of processID: [run setProcessID:[processInfo processIdentifier]]; And that's where it's crashing. The object run seems to exist (I can see it in the debugger), so I don't think I'm messaging nil; on the other hand, it doesn't look like the setProcessID: message is actually being received. I'm obviously still learning this stuff (that's what tutorials are for, right?), and I'm probably doing something really stupid. However, any help or suggestions would be gratefully received! ===MORE INFORMATION=== Following up on Jeremy's suggestions: The processID attribute in the model is set up like this: NSAttributeDescription *idAttribute = [[NSAttributeDescription alloc]init]; [idAttribute setName:@"processID"]; [idAttribute setAttributeType:NSInteger32AttributeType]; [idAttribute setOptional:NO]; [idAttribute setDefaultValue:[NSNumber numberWithInteger:-1]]; which seems a little odd; we are defining it as a scalar type, and then giving it an NSNumber object as its default value. In the associated class, Run, processID is defined as an NSInteger. Still, this should be OK - it's all copied directly from the tutorial. It seems to me that the problem is probably in there somewhere. By the way, the getter method for processID is defined like this: - (int)processID { [self willAccessValueForKey:@"processID"]; NSInteger pid = processID; [self didAccessValueForKey:@"processID"]; return pid; } and this method works fine; it accesses and unpacks the default int value of processID (-1). Thanks for the help so far!

    Read the article

  • Does the type in this KVC validation method matter?

    - by dontWatchMyProfile
    For example, in the docs a KVC-style validation method is implemented like this: -(BOOL)validateAge:(id *)ioValue error:(NSError **)outError They used id* as the type for ioValue. Since that's not part of the method signature, I wonder if it would hurt to do something like: -(BOOL)validateAge:(NSNumber *)ioValue error:(NSError **)outError Is this still fine with KVC?

    Read the article

  • Animating a pulsing UILabel?

    - by fuzzygoat
    I am trying to animate the color the the text on a UILabel to pulse from: [Black] to [White] to [Black] and repeat. - (void)timerFlash:(NSTimer *)timer { [[self navTitle] setTextColor:[[UIColor whiteColor] colorWithAlphaComponent:0.0]]; [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{[[self navTitle] setTextColor:[[UIColor whiteColor] colorWithAlphaComponent:1.0]];} completion:nil]; } . [self setFadeTimer:[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerFlash:) userInfo:nil repeats:YES]]; Firstly I am not sure of my method, my plan (as you can see above) was to set up a animation block and call it using a repeating NSTimer until canceled. My second problem (as you can see above) is that I am animating from black (alpha 0) to white (alpha 1) but I don't know how to animate back to black again so the animation loops seamlessly Essentially what I want is the text color to pulse on a UILabel until the user presses a button to continue. EDIT_001: I was getting into trouble because you can't animate [UILabel setColor:] you can however animated [UILabel setAlpha:] so I am going to give that a go. EDIT_002: - (void)timerFlash:(NSTimer *)timer { [[self navTitle] setAlpha:0.5]; [UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{[[self navTitle] setAlpha:0.9];} completion:nil]; } This works (BTW: I do want it to stop which is why I hooked it up to a NSTimer so I can cancel that) the only thing is that this animates from midGray to nearWhite and then pops back. Does anyone know how I would animate back from nearWhite to midGray so I get a nice smooth cycle? EDIT_003: (Solution) The code suggested by dave DeLong (see below) does indeed work when modified to use the CALayer opacity style attribute: UILabel *navTitle; @property(nonatomic, retain) UILabel *navTitle; . // ADD ANIMATION CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"]; [anim setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; [anim setFromValue:[NSNumber numberWithFloat:0.5]]; [anim setToValue:[NSNumber numberWithFloat:1.0]]; [anim setAutoreverses:YES]; [anim setDuration:0.5]; [[[self navTitle] layer] addAnimation:anim forKey:@"flash"]; . // REMOVE ANIMATION [[[self navTitle] layer] removeAnimationForKey:@"flash__"];

    Read the article

  • How do I set an ABPeoplePickerNavigationController's prompt?

    - by mverzilli
    This is the code I'm using to call the people picker, but the prompt label text doesn't change: ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init]; picker.peoplePickerDelegate = self; picker.displayedProperties = [NSArray arrayWithObjects: [NSNumber numberWithInt:kABPersonEmailProperty], nil]; picker.navigationItem.prompt = @"Choose a contact to..."; [self presentModalViewController:picker animated:YES];

    Read the article

  • Release Quickie

    - by Meltemi
    How to succinctly handle this situation. I'm not properly releasing contactDictionary in the if statement... NSNumber *pIDAsNumber; ... NSMutableDictionary *contactDictionary = [NSMutableDictionary dictionaryWithDictionary:[defaults dictionaryForKey:kContactDictionary]]; if (!contactDictionary) { contactDictionary = [[NSMutableDictionary alloc] initWithCapacity:1]; } [contactDictionary setObject:pIDAsNumber forKey:[myClass.personIDAsNumber stringValue]]; [defaults setObject:contactDictionary forKey:kContactDictionary];

    Read the article

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