objective-c

Programming coordinates-based game, like dots or checkers

I'm looking to learn some fundamentals on cartesian geometry or coordinates based game programming. Platform is irrelevant, although I'm most proficient in JavaScript, C, Objective-C. Ultimately being able to create something such as dots or checkers would be ideal. The idea is for me to learn how sprites work and how pathing works progr...

Cocoa: Memory management with NSString

When creating a string using the following notation: NSString *foo = @"Bar"; Does one need to release foo? Or is foo autoreleased in this case? ...

List selectors for obj-c object

I have an object, and I want to list all the selectors to which it responds. It feels like this should be perfectly possible, but I'm having trouble finding the APIs. ...

How do I trigger a callback when a NSAnimationContext ends?

I have an animation which moves some views around. When this animation completes I want the window to recalculate the keyview loop. My code is simmilar to the follow mock code: [NSAnimationContext beginGrouping]; [newView setAlpha: 0.0]; //hide newView [self addSubView:newView]; //position the views [[oldView animator] setFrame...

Cocoa Threadsafe Mutable Collection Access

I'm creating a KVC/KVO-compliant mutable array on one of my objects the recommended way: @interface Factory { NSMutableArray *widgets; } - (NSArray *)widgets; - (void)insertObject:(id)obj inWidgetsAtIndex:(NSUInteger)idx; - (void)removeObjectFromWidgetsAtIndex:(NSUInteger)idx; @end Clearly this is a tricky thread-safety issue. In ...

Why does NSSet objectEnumerator increment the retain count?

After getting the objectEnumerator in the following code, the set1 retain count goes to 3. I was surprised to see that because I didn't expect it to change. I searched the documentation and can't find where this effect is explained. I assume the extra retains are probably set to autorelease by the Cocoa enumeration logic and won't reall...

Managing multiple asynchronous NSURLConnection connections

Hey folks, I have a ton of repeating code in my class that looks like the following: NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; The problem with asynchronous requests is when you have various requests going off, and you h...

NSURLConnection and handling response code and response data

I have an odd edge case right now in that a response code from an NSURLConnection delegate method: - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response; Is triggered before the subsequent delegate method: - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data; My code...

Repository of BNF Grammars?

Is there a place I can find Backus–Naur Form or BNF grammars for popular languages? Whenever I do a search I don't turn up much, but I figure they must be published somewhere. I'm most interested in seeing one for Objective-C and maybe MySQL. ...

methods: multiple parameters or structure?

I noticed by looking at sample code from Apple, that they tend to design methods that receive structures instead of multiple parameters. Why is that? As far as ease of use, I personally prefer the latter, but as far as performance goes, is there one better choice than the other? [pencil drawPoint:Point3Make(20,40,60)] [pencil drawPointA...

Delayed call, with possibility of cancelation?

How do I trigger a delay, let's say I want to call a method (once) in 3 seconds from now, and how do I cancel that call if I need to? ...

How can I troubleshoot my custom URL scheme?

I set up a simple event handler as mentioned here, but it appears that the selector isn't called. I put the code in my AppDelegate class and wired up the delegate in IB. Tried putting in some NSLog()s and breakpoints in the selector I expect to be called, but none of it is hit. The URL scheme works inasmuch as it launches my app, but it ...

Best way to display a game score on iPhone with cocos2d?

I am looking to persistently display a game score in an iPhone app using cocos2d. Going off the code that cocos2d shows the FPS the app is running at: -(void) showFPS { frames++; accumDt += dt; if ( accumDt > 0.1) { frameRate = frames/accumDt; frames = 0; accumDt = 0; } NSString *str = [NSString st...

COMET (server push to client) on iPhone

I'm looking to establish some kind of socket/COMET type functionality from my server(s) to my iPhone application. Essentially, anytime a user manages to set an arbitrary object 'dirty' on the server, by say, updating their Address.. the feedback should be pushed from the server to any clients keeping a live poll to the server. The buzzwo...

Global Variables in Cocoa/Objective-C?

According to Cocoa Programming for Mac OS X, 3rd Edition, on page 202 (chapter 13): You will be registering, reading, and setting defaults in several classes in your application. To make sure that you always use the same name, you should declare those strings in a single file and then simply #import that file into any fil...

NSString's initWithData:encoding: return type issue

I have a couple of lines of trivial code such as the following: NSData *dataReply; NSString *stringReply; dataReply = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; stringReply = [[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding]; The problem here is, initWithData:encodi...

iPhone proper usage of Application Delegate

I'm looking to be able to reference certain state/objects through anywhere in my application. For instance, a user logs in to their application, I need to call a web service and retrieve the users information. Then I want to be able to access this information from anywhere in the application with something like the following: myAppDeleg...

Settings-style grouped table

So it's trivial to create a Settings style table on the iPhone. The problem is, they add a great deal of code as your Settings have a gamut of options/styled cells. One section might have a check list, another might have cells with accessory disclosures to drill down further, another might be labels with UITextFields. My question here i...

Best way to determine that a UIViewController has been loaded, and has a valid view?

When the view property of a UIViewController is accessed, it first checks to see if it's got an existing view, and returns that. If not, it loads its nib or calls -loadView. When a controller receives a -didReceiveMemoryWarning message, the default behavior is to remove that cached view (assuming it's not in use at the time). If I ov...

Radio dial type functionality as seen on Where To? App

Straight forward question. I'm trying to understand UI design more and how to make it work with code. In particular there used to be an app that went through several design sessions, named Where To? by Tap Tap Tap. They had a table which they turned into a radio dial, screenshot: My question is, is this nothing more than 22 or so imag...