cocoa

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...

Does the iPhone timeout if a function takes too long to execute?

I have a function in which I get en external resource from the web using cocoa's Url object. And it works fine on the simulator, but occasionally fails on the device itself (it's a google query so the resource obviously does exist). Which leads me to believe that there is some internal timeout barrier on the hardware, but haven't read t...

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? ...

Change Sound (or other) System Preferences in Mac OS X

I'd like to be able to switch the sound output source in Mac OS X without any GUI interaction. There are tools to do control the sound output, such as SoundSource and an applescript to open the preferences dialog. What I am looking for is something that switches the preference instantly, like SoundSource but it has to be scriptable. T...

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! ...

Specific help with Xcode Project Template that is not doing substitution in file contents

We are trying to make a project template, but the documentation on this is spotty or non-existent. Doing some reverse-engineering on some template files, we have come up with the following. However, it doen't actually work! First of all, we have figured out that project templates should be installed inside: ~/Library/Application Supp...

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 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 better way to find midnight tomorrow?

Is there a better way to do this? -(NSDate *)getMidnightTommorow { NSCalendarDate *now = [NSCalendarDate date]; NSCalendarDate *tomorrow = [now dateByAddingYears:0 months:0 days:1 hours:0 minutes:0 seconds:0]; return [NSCalendarDate dateWithYear:[tomorrow yearOfCommonEra] month:[tomorrow mon...

How to change the height of an NSProgressIndicator?

By default, cocoa progress bars are slightly fat and I want something a little slimmer, like the progress bars seen in the Finder copy dialog. However, Interface Builder locks the NSProgressIndicator control height to 20 pixels and my programmatic attempts to slim down aren't working, as calls to [progressBar setControlSize:NSMiniContro...

NSAutoreleasePool in NSOperation main?

The documentation for +[NSThread detachNewThreadSelector:toTarget:withObject:] says: For non garbage-collected applications, the method aSelector is responsible for setting up an autorelease pool for the newly detached thread and freeing that pool before it exits. My question is, do I need to create my own NSAutoreleasePool in ...

Linking File's Owners and View Controller [iPhone SDK]

I seem to be having an issue with iPhone SDK 2.1 in as far as being able to establish a relationship between a ViewController and a View window. In as far as a Cocoa Touch Class, I went forward and added a UIViewController subclass. I made sure that the target is part of the existing project. Right afterwards I added a User Interfaces ->...

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...