objective-c

Can I override loginwindow on Tiger?

My software authorizes the user prior to booting Mac OS X (Tiger and Leopard.) I want to use SFAuthorizationPluginView to create a plugin to attempt to use our pre-boot authorization (cached securely) for user login to Mac OS X for single-sign-on capability. I have not yet validated if that will even work for Leopard, but am assuming I...

Run a method on tab switch or when leaving a UIViewController's focus

I'd like to run a method when a user switches to another tab or when the application is closed. Is there a way to do this with the iphone sdk? I've tried looking at the methods for the view controllers and the tab bars, but I didn't see any methods that seemed to do this. I've also tried doing this with "Editing Did End" methods, but...

Setting the background of NSBox to a gradient programmatically without subclassing

I want to set the background of an NSBox to be a gradient. In Interface Builder it is possible to set the background color of an NSBox to selectedMenuColor which is a gradient. NSBox only has a setFillColor method so how is Interface Builder filling it with a gradient? How do I programmatically fill an NSBox without subclassing it? I...

Persistent Connection to Web Server (Like AJAX on Web)

I am wanting to create a program that talks with a Cometd server to allow for pushing of data to the app. I have done this on the web side using AJAX, but I am a little unsure of the best way to do this with Cocoa. I can make a standard connection using NSURLRequest and NSURLConnection, but how do I keep this connection alive so I can ...

NSURLConnection chunked encoding upload - How?

I need to create a way to upload a bytestream using chunked encoding. I have a byte array that contains an audio file, I would like to send that file to a server using a chunked stream. I've been able to do a chunked upload via a native socket but I would really like to do this via one of the NSURL (NSURLConnection?) libs. Is that poss...

Using C++ from Objective C : how to allocate/deallocate?

Currently, my Objective C classes use C++ objects by doing a new when the owner is created, and calling delete when it is destroyed. But is there another way? I'd like to be able to declare, say, an auto_ptr whose scope lasts the duration of the Objective C class' lifetime. ...

Xcode Property Automation

Xcode has these handy time savers in the scripts menu called "Code->Place Accessor Defs on Clipboard" and "Code->Place Accessor Decls on Clipboard". These scripts allow you to automate the generation of getter and setter methods for any highlighted instance variables. Does anyone know of a similar script that outputs Objective-C 2.0 Pr...

Avoiding @property-itis (i.e. overuse of properties, when are they appropriate)?

Objective-C 2.0 gave us @properties. They allow for introspection. They allow for declarative programming. The @synthesize and @dynamic mechanisms relieve use from having to write repetitive, stock accessors. Finally, there is the ‘dot’ property syntax, which some love, and some hate. That isn't what I'm hear to ask. Like any new fea...

Using the GCC __unused attribute with Objective-C

Is it possible to use the __unused attribute macro on Objective-C object method parameters? I've tried placing it in various positions around the parameter declaration but it either causes a compilation error or seems to be ignored (i.e., the compiler still generates unused parameter warnings when compiling with -Wall -Wextra). Has anyo...

Best JSON library to use when developing an iPhone application?

There are a few JSON libraries/frameworks available for objective-c developers, but I wanted to get the opinion of the resident gurus here on which one is the best, and why. Any thoughts? ...

How to get a Phone Number from an Address Book Contact (iphone sdk)

I am showing an addressbook view to the user and letting them click on a contact and select a phone number. If they select a phone number, I want to get the phone number as an integer and the contact's name as an NSString. I've tried doing it with the following code: //printf("%s\n",[[(NSArray *)ABMultiValueCopyArrayOfAllValues(t...

How can I create a zip file by using Objective C?

I am developing a iPhone application, and trying to zip the file I have created in the application, is there any built in function able to do this? ...

How do I convert a float to an int in Objective C?

Total newbie question but this is driving me mad! I try myInt = [myFloat integerValue]; and I get an error saying essentially integerValue doesn't work on floats. How do I do it? ...

OOP: Designing a menu system

Hello! I am currently trying to create a menu system for a game and cannot arrive at any really sound way to do it. There are several menu screens, each of them non-trivial, so that I would like to keep these as separate classes. The main problem I am having is passing control between these menu screens. I tried building each of the scr...

Xcode regions

Does Xcode support anything akin to Visual Studio style #region directives for arbitrary code folding? ...

How to fade an NSSound object

I've written a cheap & cheerful sound board in for my Mac, and I play the various sounds with NSSound like this: -(void)play:(NSSound *)soundEffect:(BOOL)stopIfPlaying { BOOL wasPlaying = FALSE; if([nowPlaying isPlaying]) { [nowPlaying stop]; wasPlaying = TRUE; } if(soundEffect != nowPlaying) { ...

How to dump data stored in objective-c object (NSArray or NSDictionary)

Forgive me for a potentially silly question here, but in other programming languages (scripting ones like PHP or Perl) it is often easy to dump everything contained within a variable. For instance, in PHP there are the var_dump() or print_r() functions. Perl has the Data Dumper CPAN class, etc etc. Is there something like this for Obje...

Problem dealloc'ing memory used by UIImageViews with fairly large image in an UIScrollView

I have a large UIScrollView into which I'm placing 3-4 rather large (320x1500 pixels or so) UIImageView image tiles. I'm adding these UIImageViews to the scroll view inside of my NIB files. I have one outlet on my controller, and that is to the UIScrollView. I'm using a property (nonatomic, retain) for this, and sythesizing it. My qu...

Memory Usage on convenience method vs init method

Recently when I looked into iPhone memory management, I tried to compare the convenience method and init method on the same object. For example, I have UIImageView where it displays a downloaded NSData: Convenience method: imageView.image = [UIImage imageWithData:[downloads dataAtIndex:0]]; init method: UIImage *aImage = [[UIImage a...

Syntax for creating View delegate in Objective-C

I am trying to create a delegate protocol for a custom UIView. Here is my first attempt: @protocol FunViewDelegate @optional - (void) funViewDidInitialize:(FunView *)funView; @end @interface FunView : UIView { @private } @property(nonatomic, assign) id<FunViewDelegate> delegate; @end This doesn't work because the FunView inter...