cocoa

What is the point in a retain immediately followed by an autorelease?

I'm looking at some open source code and trying to understand why the author has done something in a particular way. The class is a wrapper around NSArray to create a stack data structure with push, pop, etc. One method is topObject which returns the topmost object on the stack and its implementation is: - (id)top { return [[[stac...

How to approach implementing a layout editor using Cocoa

I want to build an OS X application, in which one of the requirements is for the user to be able to generate PDF output according to a layout that they, the user, will create. Typical items on the page would be things like a corporate logo (a JPEG or PNG), an address (a block of text) and a narrative (another block of text). I'd like t...

Evaluating every conditional statement on an if... else if... block

Does Objective-C evaluate every statement on an if... else if... block or does it evaluate each as it comes to them and then skip the remaining evaluations if a true condition has been found? This is more of a pragmatic question related to performance than anything else. And yes I do know that the content of the if block itself isn't e...

How do you tell whether you need to release an object?

Can you describe the naming convention difference between a method that returns an object it has allocated for the caller (and that the caller should release), and a method that returns an autorelease object? If you declare a property with a retain attribute, do you need to release the property before you set it to nil? What does the ...

Can I change name displayed in Spotlight search results?

I am writing a Spotlight importer for an application that stores content in files with meaningless names. There is benefit from allowing the user to search for these files, however. It's easy enough to write an importer that extracts and returns useful metadata but when the user does a search in Spotlight they are presented with the m...

iPhone Core data entity lookup

I have a very simple problem that i'm sure has a simple solution, but after searching the internet for 2 days I can't find anything on it =( Here is the situation: I have decided to break my data into 2 sperate entities with a one-to-one relationship. So I have the PERSON entity and FEATURES entity. each PERSON has a related FEATURES en...

What is the difference between compare: and isEqualToString:?

I was working on this: NSString *str1 = @"This is string A"; NSString *str2 = @"This is string B"; NSComparisonResult compareResult; if([str1 isEqualToString:str2] == YES) NSLog (@"str1 == str2"); else NSLog (@"str1 != str2"); compareResult = [str1 compare: str2]; if (compareResult == NSOrderedAscending) NSLog (@"str1 < ...

Preset NSUserDefaults

I thought I read some where that I could include a NSUserDefaults file with a cocoa app. I cannot seem to find how to do that. I know I could just create on first app launch but I dont want to do that just yet... ...

NSView high-level overview?

I am trying to create a custom view and load it into a window. In the end, I know there will be a few steps to follow, reflecting the key relationships that I am missing. I am hoping someone can explain, in a series of steps, how one creates a view object, view controller, associated .xib, and then loads it into a window (after clearin...

Proper way to represent time of day for alarms

I'm trying to code part of a program that allows users to set up one or more alarms that will remind them to launch the application and do something at certain times of day. I basically understand that I need to use local notifications, but I'm having a hard time coming up with the best way to represent a time of day in my application s...

NSMutableArray initWithCapacity nuances

Hi, Does anyone have advice on how to best initialize an NSMutableArray when it comes to dictating the capacity? The documentation mentions that "...even though you specify a size when you create an array, the specified size is regarded as a “hint”; the actual size of the array is still 0." So... 1) If I init with a greater capacity t...

Cocoa: Obtaining an image that's displayed in another application

One Google Chrome extension displays a window with an image once in a while, how can I get the image from it with Cocoa? Basically there is a window and image inside it, and I need that image for my program. Thanks for reading! ...

Three20 : how to pass a class of objects between 2 views

Hi, I have a TTableView. The items in this table a mapped to an url, so that when I click on an item, another view appear with informations about this item. All these informations are attributes of a class. So, how can I build my TTableTextItem URL in order to transmit the class containing informations to the view responsible for the di...

Best practice of copying and serializing Quartz references

I have objects containing Quartz-2D references (describing colors, fill patterns, gradients and shadows) in Cocoa. I would like to implement the NSCoding protocol in my objects and thus need to serialize those opaque Quartz-2D structures. Possible solutions might be: Define a set of properties in my objects that allow to setup the dat...

VPN on a Cocoa app

Hey, I'm developing an app for a customer. He has a company and he wants the app to connect to the other Macs via VPN. I googled for a tutorial, but I could not find any. Does anyone know a good tutorial/guide for that? Thanks! ...

Cocoa - iTunes track Persistent IDs - Scripting Bridge vs Distributed Notifications

Hello, I'm writing some Cocoa code and having trouble with the iTunes track persistent IDs returned by Scripting Bridge and Distributed Notifications. Taking one track as an example - in a Scripting Bridge call I get the following values: Persistent ID: 2FBA59E028DC5E51 (NSString) - Hexadecimal? ...but from a Distributed Notificatio...

NSDocument get real save path?

Hey guys, I am trying to get the path that an NSDocument is being saved to at save time. I tried overriding writeToURL but that would pass me an obscure temp file URL, which was not where it was getting saved. Also asking the document like this [document fileURL] only works after it has been saved. I can get the path when it is loaded bu...

Why are my table view delegate methods not being called?

I'm building a document based Mac application. I have two classes myDocument and Person. The difficulty I'm having is when I push the button to add a new Person in the table view and display it it doesn't show in the table view. I've placed log statements inside the delegate methods. Since my log statements are not being displayed in the...

My NSOpenGLView won't work. I've tried everything.

I want to display something in an NSOpenGLView, but since there is a total of zero bytes of documentation on it, and the sample code is as big and complex as the documentation should be, I can't get any wise out of it. This is my code so far, and my ANOpenGLView is an NSOpenGLView in a NIB subclassed as ANOpenGLView: @implementation ANO...

Bad-practice to retain 'self'?

I have a simple query that I'd like cleared up by someone... Is it bad-practice to retain self? I have a server request object that I'd like to make. I'd like to be able to use it in the following fashion: ARequest *request = [ARequest request: someParam]; request.delegate = self; [request begin]; In order for the object not to self ...