objective-c

How do I wrap text in a UITableViewCell without a custom cell

This is on iPhone 0S 2.0. Answers for 2.1 are fine too, though I am unaware of any differences regarding tables. It feels like it should be possible to get text to wrap without creating a custom cell, since a UITableViewCell contains a UILabel by default. I know I can make it work if I create a custom cell, but that's not what I'm tryin...

Pass NSMutableArray object

I'm getting lost in pointer land, I believe. I've got this (code syntax might be a little off, I am not looking at the machine with this code on it...but all the pertinent details are correct): NSMutableArray *tmp = [[NSMutableArray alloc] init]; I them pass that to a routine in another class - (BOOL)myRoutine: (NSMutableArray *)inA...

What are some good resources for learning Objective-C?

I've been using Objective-C for about 6 months, and have a good grasp on the basic concepts. What are some resources (websites, PDFs, Books, Blogs, etc) to advance past this level? ...

Java Developer meets Objective-C on Mac OS

I have developed in C++ many years ago, but these days I am primarily a Java software engineer. Given I own an iPhone, am ready to spring for a MacBook next month, and am generally interested in getting started with Mac OS developmentmt (using Objective C), I thought I would just put this question out there: What Next? More specificall...

How do I tell if a UIView is visible and on screen?

If I have a UIView (or UIView subclass) that is visible, how can I tell if it's currently being shown on the screen (as opposed to, for example, being in a section of a scroll view that is currently off-screen)? To maybe give you a better idea of what I mean, UITableView has a couple of methods for determining the set of currently visib...

Do I have a shot at learning Objective-C?

I do mostly ActionScript development, plus a bit of C# (and historically Lingo, Java and VB). What are my chances of learning Objective-C? I'd love to have a go at iPhone development, but the language just looks so insanely different to everything else. ...

NSDateFormatter, am I doing something wrong or is this a bug?

I'm trying to print out the date in a certain format: NSDate *today = [[NSDate alloc] init]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyyMMddHHmmss"]; NSString *dateStr = [dateFormatter stringFromDate:today]; If the iPhone is set to 24 hour time, this works fine, if on the other ...

What does your Objective-C singleton look like?

Mine is merely (or a close variant thereof): static MyClass *gInstance = NULL; + (MyClass *)instance { @synchronized(self) { if (gInstance == NULL) gInstance = [[self alloc] init]; } return(gInstance); } ...

Why is half of my compiled (small) objective-C file a large block of zeroes?

I opened up my compiled Hello World Obj-C application in a text editor and, to my surprise, I found about 8 kilobytes of 00 00 00 00 00 00 00 00 .... Why are these here? Is there a way to clear out these zeroes (which I doubt have too much function)? Obviously it's not so important in this file, seeing as it's only 16kB to begin with,...

What are those little Xcode tips & tricks you wish you knew about 2 years ago?

With a huge influx of newbies to Xcode I'm sure there are lots of Xcode tips and tricks to be shared. What are yours? ...

Crafting .webloc file

I'm writing a program (for Mac OS X, using Objective-C) and I need to create a bunch of .webloc files programmatically. The .webloc file is simply file which is created after you drag-n-drop an URL from Safari's location bar to some folder. Generally speaking, I need an approach to create items in a filesystem which point to some locat...

Low-level details of the implementation of performSelectorOnMainThread:

Was wondering if anyone knows, or has pointers to good documentation that discusses, the low-level implementation details of Cocoa's 'performSelectorOnMainThread:' method. My best guess, and one I think is probably pretty close, is that it uses mach ports or an abstraction on top of them to provide intra-thread communication, passing se...

Best way to make NSRunLoop wait for a flag to be set?

In the Apple documentation for NSRunLoop there is sample code demonstrating suspending execution while waiting for a flag to be set by something else. BOOL shouldKeepRunning = YES; // global NSRunLoop *theRL = [NSRunLoop currentRunLoop]; while (shouldKeepRunning && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFut...

Carbon vs Cocoa, is Carbon a dead end with OS X?

What are the trade-offs for using Carbon vs. Cocoa considering a developer with about 15 years of programming experience already in C/C++. Is Carbon a dead end with OS X? ...

File Sharing API or Framework in OS X 10.5.*

Is there any programming interface or CLI for changing network or file sharing settings in OS X Leopard? ...

Handling exceptions raised during method called via NSObject's performSelectorOnMainThread:withObject:waitUntilDone:

What happens to exceptions raised while in myMethod: if it is invoked via NSObject's performSelectorOnMainThread:withObject:waitUntilDone:? In particular, can I catch them in the scope of the call to performSelectorOnMainThread like this... @try { [self performSelectorOnMainThread:@selector(myMethod) withObject:nil waitUntilDone:Y...

What are best practices that you use when writing Objective-C and Cocoa?

I know about the HIG (which is quite handy!), but what programming practices do you use when writing Objective-C, and more specifically when using Cocoa (or CocoaTouch). ...

Object allocate and init in Objective C

What is the difference between the following 2 ways to allocate and init an object? AController *tempAController = [[AController alloc] init]; self.aController = tempAController; [tempAController release]; and self.aController= [[AController alloc] init]; Most of the apple example use the first method. Why would you allocate, init ...

Sending a message to nil?

As a Java developer whom is pouring over Apple's Objective-C 2.0 documentation: I am in a state of wonderment as to what sending a message to nil means - let alone how it is actually useful. Taking an excerpt from the documentation: There are several patterns in Cocoa that take advantage of this fact. The value returned from a m...

Cropping a UIImage

I've got some code that resizes an image so I can get a scaled chunk of the center of the image - I use this to take a UIImage and return a small, square representation of an image, similar to what's seen in the album view of the Photos app. (I know I could use a UIImageView and adjust the crop mode to achieve the same results, but these...