Objective-C call function on another class?

(I’ll assume loggedIn is an instance method taking no parameters.) First, several terminology issues: They’re not functions, they’re methods (same idea, though). You don’t call methods, you send messages (usually same idea, though). Most importantly, we usually send messages not to classes, but to instances of those classes. (If you can’t visualize the difference, imagine … Read more

Sort NSArray of custom objects by their NSDate properties

Are you sure that the startDateTime instance variables of the node events are non-nil? If you don’t have one already, you might add a (custom) -description method to your node event objects that does something like this: – (NSString *)description { return [NSString stringWithFormat:@”%@ – %@”, [super description], startDateTime]]; } Then in your sorting code … Read more

How to get global screen coordinates of currently selected text via Accessibility APIs.

You can use the accessibility APIs for that. Make sure that the “Enable access for assistive devices” setting is checked (in System Preferences / Universal Access). The following code snippet will determine the bounds (in screen coordinates) of the selected text in most applications. Unfortunately, it doesn’t work in Mail and Safari, because they use … Read more

Gap above NSMenuItem custom view

Your post is tagged “Objective-C” and “Cocoa”, although your sample code is C and Carbon. I assume you’d prefer a Cocoa solution? It’s actually pretty simple in Cocoa. The only trick is learning how to draw outside the lines. 🙂 @interface FullMenuItemView : NSView @end @implementation FullMenuItemView – (void) drawRect:(NSRect)dirtyRect { NSRect fullBounds = [self … Read more

Objective-C dot notation with class methods?

This is correct behavior. foo.method is syntactic sugar for [foo method]—a straight conversion with identical semantics. Similarly foo.prop = bar is syntactic sugar for [foo setProp:bar], again with identical semantics. This transformation is implemented in the compiler. Thus you can use dot notation to call 0-parameter methods as in foo.doSomething instead of [foo doSomething]. Of … Read more

Combining a UILongPressGestureRecognizer with a UIPanGestureRecognizer

actually, you don’t have to combine gesture recognizers – you can do this solely with UILongPressGestureRecognizer… You enter StateBegan once your touch(es) have stayed within ‘allowableMovement’ for ‘minimumPressDuration’. You stay in your continuous longPressGesture as long as you don’t lift any of your fingers – so you can start moving your fingers and track the … Read more

Objective-C passing around … nil terminated argument lists

You can’t do this, at least not in the way you’re wanting to do it. What you want to do (pass on the variable arguments) requires having an initializer on UIAlertView that accepts a va_list. There isn’t one. However, you can use the addButtonWithTitle: method: + (void)showWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, … Read more

Play Audio iOS Objective-C

Maybe you should try using the NSBundle method pathForResource:ofType: method to create the path to the file. The following code should successfully play an audio file. I have only used it with an mp3, but I imagine it should also work with m4a. If this code does not work, you could try changing the format … Read more