objective-c

Why are alloc and init called separately in Objective-C?

Note: I'm relatively new to Objective-C and am coming from Java and PHP. Could someone explain to me why I always have to first allocate and then initialize an instance? Couldn't this be done in the init methods like this: + (MyClass*)init { MyClass *instance = [MyClass alloc]; [instance setFoo:@"bla"]; return instance; }...

Is calling [self release] allowed to control object lifetime?

I want to create an object in Objective C but I don't hold a reference to it. Is it allowed to let the object control its own lifetime by calling [self release]? In case you're wondering why I need this: I want to create an object that subscribes to some notifications, but after a while the object is no longer needed and should go awa...

Making the Children Rows in an Outline View be deleted when their parent is.

How would I do this? I think this has something to do with editing the Outline Views Data Source file. The Outline View is currently is being used with Core Data. ...

Making an NSAlert be displayed when the User attempts to delete a row from an NSOutlineView when it has children.

How would I do this? The Outline View is being used with Core Data. ...

formatting european characters from JSON results

hi, i am building an application that imports JSON results and parses the objects to a table cell. Nothing fancy, but in my results, many of the terms/names are European with characters such as è or ú which come out as \u00E9 or \u00FA. I think these are ASCII ? or unicode? ( i can never keep em staight). Anyway, like all good NSSTring's...

Is NSURLConnection thread safe?

I have multiple NSURLConnections running providing data back to the delegate objects. Is it safe for these delegate objects all to store their data into a single instance of an sqlite database connection? ie Do the callbacks to the delegates come back in on different threads? ...

Animating rows in an NSTableView

Is there a simple way of animating rows in an NSTableView? I'd like to be able to do something like flash a row, or fade out a row. Essentially - to provide a bit of visual feedback when rows are added or removed. Edited to add: I'd had a quick look over Google before posting this; but I wanted to know if there was some way to do thi...

Objective C: why release immediately after creating ui object

Many iPhone code samples (from Apple, etc.) include code like this: - (void)viewDidLoad { CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame]; // add the top-most parent view UIView *contentView = [[UIView alloc] initWithFrame:applicationFrame]; contentView.backgroundColor = [UIColor blackColor]; self.view = contentView;...

Create and send a bluetooth command frame in Cocoa

I'm using the IOBluetooth Cocoa framework to communicate with a bluetooth device. So far I have gotten down the whole process of discovering the device and its services, pairing with it, connecting to it and now I want to send some actual commands, but I'm having some trouble with it. Below is an graphic from the spec for the AVRCP profi...

How do you handle memory management of outlets in the iPhone SDK

Since KVC is used to set outlets on the iPhone, there are 2 methods (that I know of) to make sure you've properly handled memory management. Specifically, I am referring to this article written by Aaron Hillegass. My question is which method do you use and what is your reasoning? Release all your outlets in dealloc and viewDidUnload ...

Instruments point a memory leak !

Hi, i'm have this code for initialize my class. - (id)initWithSize:(int)size { self = [super init]; if( self != nil ) { [self setMyVector:[[NSMutableArray alloc] initWithCapacity:size]]; for ( int i = 0; i < size; i++ ) { [myVector addObject: [[NSMutableArray alloc] initWithCapacity:size]]; } ...

Observe a File or Folder in Objective-C

What is the best way to listen to a folder or file to see if it has been saved or if a new file has been added? ...

Objective-C Protocol Madness -- how to return object based on protocol?

@protocol Eating @end @interface Eat : NSObject<Eating> { } - (id<Eating> *)me; @end @implementation Eat - (id<Eating> *)me { return self; } @end In the above piece of Objective-C code, why does "return self" result in a "Return from incompatible pointer type" warning? What's the incompatible pointer type and how to fix it? ...

When reflecting: Should set property or directly set value? (Objective-C)

I'm writing an xml serialization class for objective-c. The point is to give the class a class type and an xml file. It should return an instance with data. I've got it working, and it does quite a bit - handles primitives (+nsstring), user defined classes and nsarrays. Doesn't handle pointers or C-arrays. Obviously this relies heavily ...

Cocoa: Incomplete implementation of class 'Driver'

Hi! In advance: sorry for the noob question but I'm learning Cocoa & Objective-C and I have this problem on which I've been searching for a complete hour. It'll be very nice if someone could find the problem! Here's my two files: Driver.m #import "Driver.h" @implementation Driver - (int)go:(BOOL)distance { if (distance) { return ...

Problem dismissing an ABUnknownPersonViewController. Shows up fine but app crashes when dismissing

Hello everyone. My app is consisted of 2 views. The MainView and ResultsView. MainView contains a UITextField that needs to be filled and then if a button is touched, the view changes to ResultsView. Below is the juicy part of the code that handles that. // In CallerIDAppDelegate.h @class MainViewController; @class ResultsViewController...

rightMouseDown: not called in NSControl subclass

I have an NSControl subclass (which is configured as a layer-hosting view, although I doubt that's relevant). I've been attempting to write the code to get and display a context menu. However, neither menuForEvent: or rightMouseDown: are being called. Any idea what could be causing that? Other mouse events work correctly. As an aside, ...

Core Data bindings with subviews and multiple NIBs

I have a document-based Core Data app. My main Core Data entity has several string fields, most of which are bound to NSTextFields, but one is bound to an NSTextView. I am using the technique for view switching (with multiple view controllers) as explained in the Hillegass book. All of my subviews are controlled by a ManagedViewControll...

iPhone touch cancelling in OS 3.0

I have a new iPhone app that has the following (and only the following) UIView heirarchy: UIWindow -> UIScrollView -> UIViewSubclass The UIScrollView is the view of a UIViewController. In UIViewSubclass I want to be tracking and responding to touch events and have set up the "standard four" handling routines therein. Under the Simulat...

Do I lose perfomance by using .xib files to provide an iPhone app's GUI?

I was wondering if there is a difference between using .xib files for GUI design and doing this programmatically. As it is a compiler I would assume that there is no relevant time lost. Am I wrong? ...