objective-c

Putting an NSPopUpButton in an NSToolbar

Having wrestled with NSPopUpButton in a previous question here I am now trying to place a NSPopUpButton inside an NSToolbar. Essentially I want to create something similar to what XCode has by default on the left hand side of it's toolbar. E.g. a pop up button with an action button next to it. I have seen a method that show's a programm...

Override a method via ObjC Category and call the default implementation?

When using categories, you can override implementation methods with your own like so: // Base Class @interface ClassA : NSObject - (NSString *) myMethod; @end @implementation ClassA - (NSString*) myMethod { return @"A"; } @end //Category @interface ClassA (CategoryB) - (NSString *) myMethod; @end @implementation ClassA (CategoryB) -...

How to get language locale of the user in Objective-C?

I develop an application for MacOSX. Therefore I want to change indication contents by the language locale (English, Spanish, etc.) of the application user, How to get information which language use ? I'm happy , If you give me some example codes ...

How to count lines? : Objective-C

I want to count the lines in an NSString in Objective-C. NSInteger lineNum = 0; NSString *string = @"abcde\nfghijk\nlmnopq\nrstu"; NSInteger length = [string length]; NSRange range = NSMakeRange(0, length); while (range.location < length) { range = [string lineRangeForRange:NSMakeRange(range.location, 0)]; range.lo...

Why do these errors in Xcode Mean?

2009-07-06 06:49:13.666 Spark[9825:10b] -[<NSUserDefaultsController 0x137af0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key hotKeyDisplayEntry. 2009-07-06 06:49:13.667 Spark[9825:10b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSUserDefaultsController 0x137...

NSAutoreleasePool thread and main thread sharing an autoreleased object

performSelectorOnMainThread with waitUntilDone:NO and withObject: an autoreleased object from the thread.So just after the thread terminates itself with a [NSAutoreleasePool release] What happens to my autorelease object from this thread that has been passed to the main thread ?? ...

Exception/Error handling in Objective-C (iPhone app)

I actually have two questions regarding exception/error handling in the iPhone app that I am making: The app uses Internet, but when there's no connection, the app just dies (during launch). How can I handle this to print some infomsg to the user, instead of just getting thrown back to the springboard? Can someone show me an example of...

Objective C - static variables

I don't quite understand static variables when defined in the implementation of an interface. In methods I do understand how they differ from local variables, but not when defined directly in an implementation. Look at these examples. What difference do these two make practically? #include "MyClass.h" @implementation MyClass int myInt...

How to obtain the address of object in objective-C

Hi, I have to call an objective C method from a cpp Function. I have a class C, whose object address is required in this function. I did come across another link which guided me on how to have a reference to the class C, and use it for invocation from the cpp function. In my case, there is one small difference in that the Class C is al...

Can I make this code work with Shortcut Recorder?

I have this code(below) to create a customizable Hot Key. OSStatus MyHotKeyHandler(EventHandlerCallRef nextHandler,EventRef theEvent,void *userData) { EventHotKeyID hkCom; GetEventParameter(theEvent,kEventParamDirectObject,typeEventHotKeyID,NULL,sizeof(hkCom),NULL,&hkCom); HotKeyController *controller = (HotKeyController *)u...

Who is responsible for releasing objects in an array when copying?

In Objective-C, if array1 is copied onto array2 using mutableCopy, and suppose the code is done in main(), who is responsible for releasing the objects contained in the array? Is it main() or array2? ...

Global object for Javascript to interact with Safari plug-in

The issue is that I've written a Safari plug-in (http://tr.im/growler) that allows web applications to send Growl notifications by calling Javascript functions. However, at the moment the way it is written, people need to use <embed> to initialise the plug-in so that Javascript can begin using it (something I picked up from Apple's examp...

How can i unit test an object internal to a method in Objective-C?

I'm wondering how to go about testing this. I have a method that takes a parameter, and based on some properties of that parameter it creates another object and operates on it. The code looks something like this: - (void) navigate:(NavContext *)context { Destination * dest = [[Destination alloc] initWithContext:context]; if (conte...

Parsing XML in Cocoa

Hi Everyone: Today I am looking into how to make a simple XML parser in Cocoa (for the desktop). I am thinking of using NSXMLParser to parse the data, but am not quite sure where to start. The XML file on the web doesn't have the much data in it, just a simple listing with a few things that I need to save into a variable. Does anyone...

Casting sender parameter

I have a method that accepts a sender and is called with a UIbutton. How do I get that object to casted into a UIImageView? Basically how do I re-use the code for the button. - (IBAction)startClick:(id)sender { button.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"Pic_1.png...

iPhone simulator shows app's images but iPhone does not

Hello I have create an application on iphone using objective-c.In this application i am just displaying different players images stored in one folder, which will be run perfectly on simulator. But when I deploy it on iphone it is not showing the images of the player. for that the code is: UIImageView *imageplayer = [[UIImageView allo...

Invoking an Objective-C method by name

How can I invoke a method at runtime on an Objective-C class when all I have is it's signature in string form: NSString* typeName = @"Widgets"; NSString* methodName = [NSString stringWithFormat:@"add%@Object:", typeName]; Note that the method name can change at runtime but the number of arguments stays fixed - one in this instance. ...

Date increment

I want to take the next day by giving the current date The code i used as follows +(NSDate *)getForDays:(int)days fromDate:(NSDate *) date { NSTimeInterval secondsPerDay = 24 * 60 * 60 * days; return [date addTimeInterval:secondsPerDay]; } this works fine but when the daylight saving enabled this leads to errors. How can ...

Objective C - Using insertString for an NSMutable string

With a NSMutableString, how would I insert a "-" sign at the index "0" for an NSMutableString called "a". Right now my code looks like this: a = [insertString: @"-" atIndex: 0]; Xcode throws an error saying that 'insertString' is undeclared. Something looks very wrong with my code. Please give me guidance. ...

Objective C - Using deleteCharactersInRange for NSMutableStrings

How would I use deleteCharactersInRange to remove the first character of a NSMutableString? ...