objective-c

Modifying NSDate to represent 1 month from today

I'm adding repeating events to a Cocoa app I'm working on. I have repeat every day and week fine because I can define these mathematically (3600*24*7 = 1 week). I use the following code to modify the date: [NSDate dateWithTimeIntervalSinceNow:(3600*24*7*(weeks))] I know how many months have passed since the event was repeated but I ca...

Add Custom Controls to MoviePlayer

I am trying to figure out how to add a custom control to the iPhone MoviePlayer. For an example of what I am trying to do see the following image. I am trying to add something like the controls on the right and left of the basic movie controls. I had done this in the Open SDK by adding a subclass to the playerview, but now in the off...

How can I disable the UITableView selection highlighting?

When you tap a row in a UITableView, the row is highlighted and selected. Is it possible to disable this so tapping a row does nothing? ...

Can I access the keychain on the iPhone?

This question discusses encrypting data on the iPhone using the crypt() function. As an alternative, is there a keychain on the iPhone and if so, what code would I use to access it in order to store login details and then retrieve them for us in an application? ...

Why shouldn't I use Objective C 2.0 accessors in init/dealloc?

In @mmalc's response to this question he states that "In general you should not use accessor methods in dealloc (or init)." Why does mmalc say this? The only really reasons I can think of are performance and avoiding unknown side-effects of @dynamic setters. Discussion? ...

How can my iPhone Objective-C code get notified of Javascript errors in a UIWebView?

I need to have my iPhone Objective-C code catch Javascript errors in a UIWebView. That includes uncaught exceptions, syntax errors when loading files, undefined variable references, etc. This is for a development environment, so it doesn't need to be SDK-kosher. In fact, it only really needs to work on the simulator. I've already fou...

What is the cost of using autorelease in Cocoa?

Most of Apples documentation seems to avoid using autoreleased objects especially when creating gui views, but I want to know what the cost of using autoreleased objects is? UIScrollView *timeline = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, 320, 34)]; [self addSubview:timeline]; [timeline release]; Ultimately should I use ...

Is there a key combination in Xcode to implement a Protocol?

In Visual Studio if I define a class to implement an interface e.g. class MyObject : ISerializable {} I am able to right click on ISerializable, select "Implement Interface" from the context menu and see the appropriate methods appear in my class definition. class MyObject : ISerializable { #region ISerializable Members publi...

Is there a way to suppress warnings in Xcode?

Is there a way to suppress warnings in Xcode? For example I am calling an undocumented method and since the method is not in the header I get a warning on compile. I know I can add it to my header to stop the warning, but I am wondering if there is a way other then adding it to the header (so I can keep the headers clean and standard) t...

Is it possible to make the -init method private in Objective-C?

I need to hide (make private) the -init method of my class in Objective-C. How can I do that? ...

Test Driven Design for iPhone Native apps

I'm experimenting with the iPhone SDK and doing some TDD ala Dr. Nic's rbiPhoneTest project. I'm wondering how many, if any, have been successful using this or any other testing framework for iPhone/Cocoa? More important, I'd like to know how to best assert a proprietary binary request/response protocol. The idea is to send a binary requ...

Is there a pattern for dealing with non-memory resources on cleaning up an ObjC object?

It's usual for objects which have some state related to a non-memory resource to provide a method for explicitly 'finishing' with that resource. Is there a preferred common practice for dealing with the case where an object deallocation is attempted while still in the "using my resource" state? I have seen a couple of different approache...

Is there a way to control the animation on a UITableView scrollToRowAtIndexPath?

I would like to modify the animation duration and attach a callback to be called when the animation finishes when calling scrollToRowAtIndexPath with animated:YES but I can't find a handle to its animation proxy or any other way to do it. Anyone know if this is possible? ...

Is it possible to design NSCell subclasses in Interface Builder?

I'm trying to subclass NSCell for use in a NSTableView. The cell I want to create is fairly complicated so it would be very useful if I could design it in Interface Builder and then load the NSCell from a nib. Is this possible? How do I do it? ...

Is there a performance hit for using UIImage in CALayer?

I'm using a whole bunch of CALayers, creating a tile-based image not unlike GoogleMaps (different versions of the same image with more/less detail). The code I'm using to do this is: UIImage* image = [self loadImage:obj.fileName zoomLevel:obj.zoomLevel]; [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableAct...

Multiple NSURLConnection delegates in Objective-C

I have two NSURLConnections. The second one depends on the content of the first, so handling the data received from the connection will be different for the two connections. I'm just picking up Objective-C and I would like to know what the proper way to implement the delegates is. Right now I'm using: NSURL *url=[NSURL URLWithString...

Cocoa Bad Habits

What are those bad habits you've developed since you've started coding in Cocoa? I think making a list of bad habits and actively adding to it and, more importantly, breaking those habits is a good technique to produce your code quality. So start now, get your bad habits off your chest. Maybe other people share your bad habits. ...

Rounded Corners on UIImage

I'm trying to draw images on the iPhone using with rounded corners, a la the contact images in the Contacts app. I've got code that generally work, but it occasionally crashes inside of the UIImage drawing routines with an EXEC_BAD_ACCESS - KERN_INVALID_ADDRESS. I thought this might be related to the cropping question I asked a few weeks...

How do I profile how long a piece of code takes to execute in Objective-C/Cocoa for optimization purposes

Lets say I've got two interchangeable pieces of code and I want to figure out which one of them takes less processor time to execute. How would I do this? To get a very rough estimation I could just put NSLog() calls on either side of the code I wanted to profile, but it seems like the processor being otherwise very busy could skew the ...

How would you pass data from a child view to a parent view using the iPhone SDK?

Which method would you recommend to pass data from a child view back to it's parent view? ...