objective-c

Instantiating new object within switch block - why does it fail?

Why does switch ([document currentTool]) { case DrawLine: NSBezierPath * testPath = [[NSBezierPath alloc]init]; //...rest of code that uses testPath.... result in error:syntax error before "*" token for testPath? ...

Is it necessary to override bind:toObject:withKeyPath:options: in an NSView subclass to implement binding?

I have an NSView subclass which has property which I want to be bindable. I've implemented the following in the subclass: myView.h: @property (readwrite, retain) NSArray *representedObjects; myView.m: @synthesize representedObjects; +(void)initialize { [self exposeBinding: @"representedObjects"]; } -(void)bind:(NSString *)bi...

Descendant Enumeration in Objective-C

Is it possible to get a list of all descendant classes of a particular class in objective-c? Something like: @interface A : NSObject @end @interface B : A @end @interface C : A @end NSArray *descendants = [A allDescendants]; // descendants = [B, C] ...

Sending fetch message to NSObjectController inside a modal loop.

I am using a modal sheet to edit a certain data entity. This sheet is run as application modal. When the sheet is launched, the object controller in the same nib as the sheet is set to the currently selected NSManagedObject. The code leading into the launching is as follows: [objectController setContent:object]; [NSApp beginSheet:[self...

How to define a preprocessor symbol in Xcode

Is it possible to set a symbol for conditional compilation by setting up properties in an Xcode project? My aim is to to create a symbol that is available to all files, without having to use import/include, so that a set of common classes can have a special behavior in some projects. Like the following, but with my own symbols. #if TAR...

Helper functions in Cocoa

What is the standard way of incorporating helper/utility functions in Obj-C classes? I.e. General purpose functions which are used throughout the application and called by more than 1 class. Can an Obj-C method exist outside of a class, or does it need to be a C function for it to have this kind of behaviour? ...

How to check if NSTimer has been already invalidated

Hi, I have a NSTimer object that I need to invalidate if a user taps on a button or if they exit a view. So I have: [myNSTimer invalidate]; inside my button handler and inside viewWillDisappear. If user taps on a button and then exists a view the app throws an exception because myNSTimer has already been invalidated. What I need to d...

Are there any commercial add on programming controls for Mac Cocoa/Objective C?

If developing for the Windows .NET APIs I can augment my efforts with 100's of commerically available add-on controls, graphing APIs and other usefull stuff. Can anyone point me in the direction of similar commerical software for Mac Cocoa/Objective C development? Additionally: Are there enough developers to do this commercially? The ...

UnitTesting on iPhone doesn't build

I am trying to perform some unit testing on the iphone but for some reason I cannot get it to build the executable I have downloaded TestMyApp from the Standford lecture slides and that compiles and runs perfectly. I have created a test project and even gone as far as to use the test code from the Stanford sample but for some reason dep...

Example of setting up a name entry box for high score submission on iPhone?

Does anyone have an example of setting up a text field where users can enter their name and/or email address to submit it online to a high score database? I would like to have it be similar to the form that pops up when you attempt to download something from the AppStore, where you put in your email and password then can hit OK or Canc...

Programatically Switching Views in Cocoa Touch

How would one change the view on the screen programatically in an iPhone app? I've been able to create navigation view's and programatically push/pop them to produce this behaviour, but if I wanted to simply change the current view (not using a UINavigation controller object), what is the neatest way to achive this? A simple example, i...

How do I find the correct case of a filename?

This is on the Mac: If I have two filenames /foo/foo and /foo/FOO they may refer to the same file or the may be different files depending on the file system. How do I figure out if they are both pointing to the same file? And if they are, how do I get the correct representation of the filename? My problem is caused by links. A link mig...

Undo and Object release

Newbie question. I have a NSMutableArray that holds multiple objects (objects that stores bezier paths and related variables e.g. path colour ect.) These are properly released whenever the relevant -dealloc method is called. Each object is instansiated with +alloc/-init and added to the array. After adding them to the array I release th...

Learn Obj-C Memory Management

I come from a web development background. I'm good at XHTML, CSS, JavaScript, PHP and MySQL, because I use all of those technologies at my day job. Recently I've been tinkering with Obj-C in Xcode in the evenings and on weekends. I've written code for both the iPhone and Mac OS X, but I can't wrap my head around the practicalities of me...

Calculating Connection/Download Speed

I have a client and server program (both in Obj-C) and I am transferring files between two devices using the programs. The transferring is working fine, but I would like to display to the user what transfer rate they are getting. So I know the total size of the file, and how much of the file has been transferred, is there a way to figu...

How much RAM is there in an iPhone?

Different iPhones have different published memory 4GB, 8GB and 16GB. The touch can have 32GB. My understanding is this is the off-line memory (disk alike). How much actual fast ram is there in the device available for my Cocoa Application? Is there a preconfigured virtual amount? ...

Asynchronous vs Synchronous vs Threading in an iPhone App

I'm in the design stage for an app which will utilize a REST web service and sort of have a dilemma in as far as using asynchronous vs synchronous vs threading. Here's the scenario. Say you have three options to drill down into, each one having its own REST-based resource. I can either lazily load each one with a synchronous request, bu...

Cocoa Interface Style

I'm on a project doing an iPhone application. We had a Cocoa consultant come in for a few weeks. He showed me an interesting idiom of Cocoa, dealing with interfaces, but there was a difficult language barrier between us, and he wasn't really able to explain why this was done or where it was documented so I could learn more on my own. I w...

UiTextField in Landscape Orientation

For the life of me I can't figure out how I'm supposed to set the UITextField to display the text vertically (landscape mode) instead of horizontally (portrait mode). The keyboard shows up properly, but when the keys are pressed the text is entered in the wrong orientation. Here is the screenshot for the window And here is the code for...

Finding the Current Active Window in Mac OS X using Python

Is there a way to find the application name of the current active window at a given time on Mac OS X using Python? ...