objective-c

Need to do the opposite of NSSelectorFromString()

In Cocoa, you can write @selector(mySelectorNameWithObject:) to get a compiled SEL, or at runtime, NSSelectorFromString(@"mySelectorNameWithObject:") with return a SEL. According to Apple documentation: The only thing that makes the selector method name different from a plain string is that the compiler makes sure that selectors are ...

Core Data unique attributes

Is it possible to make a Core Data attribute unique, i.e. no two MyEntity objects can have the same myAttribute? I know how to enforce this programatically, but I'm hoping there's a way to do it using the graphical Data Model editor in xcode. I'm using the iPhone 3.1.2 SDK. ...

NSMutableArray of Objects Returning Type UICGColor during cellForRowAtIndexPath Event

Hi everyone I'm pretty new to Objective C and iPhone development and have hit a problem which has completely stumped me I have a class, Sale, which has the following class method: +(NSMutableArray*)liveSales { NSMutableArray *liveSales = [[NSMutableArray alloc] init]; for(int i = 0; i <= 100; i++) { Sale *s = [[Sale alloc] init];...

Mem management for returned local variable

I am a little confused about retain/release count when a local variable is allocated within a method, then returned to its caller. For example -(NSMutableString*)foo { NSMutableString *str = [[[NSMutableString alloc] init] autorelease]; [str appendString:@"Just a test"]; return str; } NSMutableString *myString = [self foo]; ...

After using an NSArray *sort* method, am I responsible for releasing the returned array.

Hi, Im used to c programming where im responsible for freeing everything, and this objective c funky stuff is throwing some spanners in the work. I am using the below code. NSArray *b = [a allObjects]; NSArray *c = [b sortedArrayUsingDescriptors:sortDescriptors]; Who's responsible for releasing "b" and "c". For the record, "a" is a NS...

Friend classes in Objective-C

Is there any way to create something like friend classes in Objective-C? ...

Objective C: Looking for advice on a web service helper class

I'm writing a program for the iPhone that will need to call web services (asynchronously). I'd like to create a helper class that will abstract away some of the complexity of using the NSURLConnection class from my various view controllers. The approach that I'm currently taking is to extend the NSURLConnection class so that it has 4 a...

How do I safely access the contents of an NSArray property from a secondary thread?

I have an app (using retain/release, not GC) that maintains an NSArray instance variable, which is exposed as a property like so: @interface MyObject : NSObject { NSArray* myArray; } @property (copy) NSArray* myArray; @end I want to access the contents of this array from a secondary thread, which is detached using -performSelector...

Syntax question on accessing properties of objects stored in a NSMutableArray

Could someone explain why the second syntax of the same expression does not work? If you need some background, manyViews is a pointer to an NSMutableArray loaded with UIView objects. [[manyViews objectAtIndex:0] setFrame:CGRectMake(30,30,100,20)]; // works as intended [manyViews objectAtIndex:0].frame = CGRectMake(30,30,100,20); ...

Selectors with arguments in Obj-C

So basically I have a big list of buttons that's present dropdowns and other things, and these buttons are created dynamically. So to capture the value for the appropriate button's data, I need to set it's action selector to a function that takes 1 extra parameter. For example, using this selector on this dropdown, with the method below...

When do you use * in variable definitions (in Objective-C)?

Hi there, I'm still getting confused by Objective-C. Sometimes you declare a variable like so: NSRect rect; And sometimes like so: NSValue *value; I never know when to add the *, so far I always looked it up in Apple's documentation. I know the difference is between a value and a pointer to an object. But are there any hard and ...

Pattern for Ownership and References Between Multiple Controllers and Semi-Shared Objects?

For example, I have window (non-document model) - it has a controller associated with it. Within this window, I have a list and an add button. Clicking the add button brings up another "detail" window / dialog (with an associated controller) that allows the user to enter the detail information, click ok, and then have the item propaga...

@protocol implementation in @interface in Objective-C

Hello, I need to develop an application which has a interface which implements methods of 3 protocols. Assume protocol A extends protocol B and protocol C, and interface implements protocol A. This is how my code looks, // This is in MyClass.h file #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #import "protocol_A" @interfac...

How do you manage releasing an object created in an instance method on iPhone without autorelease?

I'm fairly new to iPhone development and I've hit a roadblock in my understanding of memory management. I've read through the Memory Management Guide for Cocoa and have read many, many questions and answers on SO, but have not found a complete answer. If I have an instance method that creates an object, every example I've seen seems to ...

Memory management of a view controller in Objective-c

Consider the following code in the initialiser of a class: UIViewController* blankViewController=[[DisplayViewController alloc] initWithNibName:@"Blank" bundle:nil]; self.nextView=blankViewController.view; nextView is a property that uses retain. Notice that blankViewController was not released. If it were released...

Adding a new view on rightcalloutaccessoryview button press

Hello all: I want to add a new view on a rightcalloutaccessoryview button press. I currently have the functionality for dropping a pin on the map. A callout (MKAnnotation) with a title, subtitle, and chevron loads when I tap the pin. When I tap the chevron (rightcalloutaccessoryview) I want another view to pop up showing more informatio...

"NSUnknownKeyException" exception raised..applicaton crashes

Hello, I'm not matching any key to value in my code, my code is only about implementing protocol in interface implementation.but when i try to execute, i'm not getting any error, but its crashing due to this exception: ***Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<MyClass 0X3d1d2b0>setvalue:forundefin...

NSMenuItem's value binding with BOOL

Hi, I am having some issues binding an NSMenuItem's "value" binding to a BOOL. I simplified the problem to this: 1) The menu item must call the action method that changes the value of the BOOL otherwise it doesn't work (i.e. if an NSButton calls a method that changes the value of the BOOL then the menu item won't update) 2) Even if ...

Can we do nil or NULL in dealloc method and releasing that variable?

- (void)dealloc { [refreshProgressInd release]; [DetailsObject release]; List=nil; [List release]; [mapView release]; addAnnotation=nil; [addAnnotation release]; [reverseGeocoder release]; [super dealloc]; } ...

How to make SOAP WSDL request in Objective-C ?

Hi all, I have a WSDL script which has the following format <definitions name="ProcessData" targetNamespace="urn:ProcessData"> <message name="CreateAccount"> <part name="firstName" type="xsd:string"/> <part name="lastName" type="xsd:string"/> <part name="password" type="xsd:string"/> <part name="emailAddress" type="xsd:string"/> <part...