objective-c

Do OCUnit and OCMock work on the iPhone SDK?

I simply could not make it work, and I am wondering if I am wasting my time, or if I am simply stupid! Sorry I don't have the exact error I have right now. But I just want to know if it work or not! ...

Generating Random Numbers in Objective-C

I'm a java head mainly, and I want a way to generate a pseudo-random number between 0 and 74. In java I would use the method: Random.nextInt(74) I'm not interested in a discussion about seeds or true randomness, just how you accomplish the same task in Objective-C. I've scoured The Google, and it just seems to be lots of different and...

What's the best way to create a "magnifying glass" on a 2D scene?

I'm working on a game where I need to let the player look at a plane (e.g., a wall) through a lens (e.g., a magnifying glass). The game is to run on the iPhone, so my choices are Core Animation or OpenGL ES. My first idea (that I have not yet tried) is to do this using Core Animation. Create the wall and objects on it using CALayers....

What's the nicest way to do observer/observable in objective-c (iphone version)

I'm used to coding Java Swing UIs, and in those if you have some properties that change, and you want your UI to update, you would implement the observer/observable pattern. In Java you do this normally by having your class maintain a list of listeners that it notifies of different events. I've played with Objective-C on the Mac, and th...

Memory leaking with [NSKeyedUnarchiver decodeObjectForKey]

Every time I call this method my NSMutableData is leaking and I cannot figure out how to plug it. theData's retain count is upped by one after the decoder is allocated and initialized and I have no idea why. I am stuck with a retain count of 2 at the end of the method and attempting to release it causes an app crash. - (void)readVenueAr...

How to do string conversions in Objective-C?

I want to convert a string into a double and after doing some math on it, convert it back to a string. How do I do this in Objective-C? Is there a way to round a double to the nearest integer too? ...

Objective-C Tidy

I have a somewhat messily-formatted Objective-c code base. Is there a way to have Xcode reformat an entire project to conform to a coding standard (i.e., properly indent, spaces v. tabs, etc.)? Are there other tools that might accomplish this? ...

Avoiding, finding and removing memory leaks in Cocoa

Memory (and resource) leaks happen. How do you make sure they don't? What tips & techniques would you suggest to help avoid creating memory leaks in first place? Once you have an application that is leaking how do you track down the source of leaks? (Oh and please avoid the "just use GC" answer. Until the iPhone supports GC this isn't...

Best way to define private methods for a class in Objective-C

I just started programming Objective-C and, having a background in Java, wonder how people writing Objective-C programs deal with private methods. I understand there may be several conventions and habits and think about this question as an aggregator of the best techniques people use dealing with private methods in Objective-C. Please...

Does Objective-C compile to native code or byte-code?

On OS X, does Objective-C compile to native code or byte-code? Can Objective-C programs be compiled on Linux? ...

How to tell if the user's using 24 hour time using Cocoa

I'm trying to determine if the user is using 24 hour or 12 hour time, and there doesn't seem to be a good way to figure this out other than creating an NSDateFormatter and searching the format string for the period field ('a' character) Here's what I'm doing now: NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter s...

How do you document your source code in Xcode?

I'm a Mac developer with a very strong Java background. I've documented my sources using Javadoc, a lot. What's the way to go with Cocoa and Xcode? Are there any documentation tools supplied together with Apple's Developer Tools? Is Doxygen the way to go? What are the alternatives? Thank you all! ...

How do I hook up a referencing outlet in Interface Bulider for a UIImage?

I want to access a UIImage programmatically... i.e. myImage.hidden = TRUE; etc. I can do this fine for UILabel but when I repeat the process for UIImage it doesn't work. Specifically when I drag the blue line in Interface Builder over the icon I don't get a popup menu like I do when using UILabel. Perhaps using UIImageView instead of ...

What is the best way to solve an Objective-C namespace collision?

Objective-C has no namespaces; it's much like C, everything is within one global namespace. Common practice is to prefix classes with initials, e.g. if you are working at IBM, you could prefix them with "IBM"; if you work for Microsoft, you could use "MS"; and so on. Sometimes the initials refer to the project, e.g. Adium prefixes classe...

NSMutableArray destruction

I have an array NSMutableArray with happy objects. These objects viciously turn on (leak) me whenever I try to clear the array of all the objects and repopulate it. It's allocated in the init function like so self.list = [NSMutableArray array]; The different methods I have used to clear it out include: self.list = nil; self.list = [...

Learn C first before learning Objective-C

Being an aspiring Apple developer, I want to get the opinions of the community if it is better to learn C first before moving into Objective-C and ultimately the Cocoa Framework? My gut says learn C, which will give me a good foundation. ...

How can I add an additional "view" to my iphone app?

I have a simple iphone app that's based on the CrashLanding sample app. So basically you tap the title screen and do some stuff... all on the same "view". I want to add an "options" screen/page/view whatever with a few UISwitches. What's the easiest way to do this? Cheers! ...

How to create the "indexes" required for NSIndexPath:indexPathWithIndexes:length:

The class method to create an index path with one or more nodes is: + (id)indexPathWithIndexes:(NSUInteger *)indexes length:(NSUInteger)length How do we create the "indexes" required in the first parameter? The documentation listed it as Array of indexes to make up the index path but it is expecting a (NSUinteger *). To create an ...

Is there a documented way to set the iPhone orientation?

I have an app where I would like to support device rotation in certain views but other don't particularly make sense in Landscape mode, so as I swapping the views out I would like to force the rotation to be set to portrait. There is an undocumented property setter on UIDevice that does the trick but obviously generates a compiler warni...

How to scale a UIImageView proportionally ?

I have a UIImageView and the objective is to scale it down proportionally by giving it either a height or width. UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://farm4.static.flickr.com/3092/2915896504_a88b69c9de.jpg"]]]; UIImageView *imageView = [[UIImageView alloc] initWithIma...