Tag: cocoa

controlTextDidChange with 2 nstextfields – call different selectors

cocoa newbie here i have 2 nstextfields connected with controlTextDidChange. it works fine. – (void)controlTextDidChange:(NSNotification *)anotif{ [self eval]; } when either of the textfields change eval is called. what i want to do is check the textfield that changed and if it’s the first one call eval1, if it’s the second call eval2. how can […]

Core Data issue – checking if item exists

I am working on a code example from NSScreenCast that deals with importing to a Core Data application. (https://github.com/subdigital/nsscreencast/tree/master/012-core-data-importing-data/BeerBrowser). I have the example working for the most part. I am able to push the refresh button, it parses the json and imports it in to the database. However, every time I press the refresh button […]

NSCoding protocol question

I want to add the archiving (NSCoding) protocol to my model class, and then i implement both methods encodeWithCoder:(NSCoder*)coder and initWithCoder:(NSCoder*)coder. MyModelClass has 2 instance variables (NSString and NSImage), so i use the encodeObject:(id)object forKey:(NSString*)string method to encode the object plus the value for particular key. But i keep got the error : *** -encodeObject:forKey: […]

How to get the address of an objective c object into a void * volatile * under ARC?

I have a simple objective c object NSManagedObjectContext * moc = nil Now I need to pass it into a function in an ARC environment that accepts parameter of type void *volatile * value I tried &((__bridge void *)moc)) but I get the following compiler error Address expression must be lvalue or a function pointer […]

CATextLayer doesn't draw NSAttributedString background color

I have CATextLayer and want to set background color to part of the string. But setting background color to attributed string (NSBackgroundColorAttributeName) doesn’t have any effect. Other attributes, such as foreground color, are applied correctly. NSMutableAttributedString *str = [[[NSMutableAttributedString alloc] initWithString:@”Some Text”] autorelease]; NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: [NSColor yellowColor], NSForegroundColorAttributeName, [NSColor redColor], NSBackgroundColorAttributeName, nil]; […]

Blue border appearing around NSScrollView

I’m sure this is normal and I’m just misunderstanding something, but since making one of my NSScrollViews slightly inset from the bottom of the window (as opposed to taking the full height), a blue border has appeared around it. I’ve set NSNoBorder on the scroll view, so this must be something else. [scrollView setBorderType:NSNoBorder]; Any […]

NSTextField resigning first responder

I’m trying to have my text field resign first responder when the user is done editing it, like when they hit enter. The delegate method is getting called but what I have now doesn’t work, what is the proper way to go about doing this? – (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor { [fieldEditor resignFirstResponder]; return YES; […]

NSScrollView in a NSWindow

I have an NSScrollView inside an NSWindow, but it seems to be disabled. It looks like it would work, but the scrollbars are unresponsive to the mouse or the scroll wheel. When I put the exact same NSScrollView inside a window on a new XCode project, it works perfect. There is something about the way […]

CFURLResourceIsReachable failed because it was passed this URL which has no scheme

I have a Cocoa program with deployment target 10.7, using the latest (10.8) SDK, I run it on 10.7.5 with XCode 4.6.2. In it I work with NSURLs with no problem whatsoever, everything works fine. One method I use is the NSURL method: [newURL checkResourceIsReachableAndReturnError:&error] with newURL a pointer to aNSURL. So far so good. […]

Pass arguments between Objective-C applications

I was wondering if it is possible to pass arguments between Mac applications and if it possible, how. I know that in Java is possible using the following syntax from the command line: java JavaApp arg1 arg2 arg3 arg4 And that is possible to access those through the main’s args[] array. public static void main(String[] […]