Comparison between pointer and integer

I am just learning Cocoa (from C #) and I am getting a weird error for something that seems very simple. ( charsSinceLastUpdate >= 36 )

 #import "CSMainController.h" @implementation CSMainController //global vars int *charsSinceLastUpdate = 0; NSString *myString = @"Hello world"; // - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { ... } //other functions - (void)textDidChange:(NSNotification *)aNotification { NSLog(@"charsSinceLastUpdate=%i",charsSinceLastUpdate); if (charsSinceLastUpdate>=36) { // <- THIS line returns the error: Comparison between pointer and integer charsSinceLastUpdate=0; [statusText setStringValue:@"Will save now!"]; } else { charsSinceLastUpdate++; [statusText setStringValue:@"Not saving"]; } } //my functions - (void)showNetworkErrorAlert:(BOOL)showContinueWithoutSavingOption { ... } // @end 

Any help would be appreciated, thanks!

+7
variables pointers objective-c cocoa
source share
1 answer

There is a pointer in your charsSinceLastUpdate code , you need to define it without * :

int charsSinceLastUpdate = 0;

If, of course, you meant to define it as a pointer, in which case you will need to use the dereference operator to get the value that it points to, for example:

 if(*charsSinceLastUpdate >= 36) { //... } 
+20
source share

All Articles