objective-c

Why can't I create an variable in an switch block?

Strange: switch(type) { case NSFetchedResultsChangeInsert: int x = 5; // error: "Expected expression before int" break; } So it isn't possible to create a local variable in an switch-case-block? ...

How to make an NSURL that contains a | (pipe character)?

Hi all, I am trying to access google maps' forward geocoding service from my iphone app. When i try to make an NSURL from a string with a pipe in it I just get a nil pointer. NSURL *searchURL = [NSURL URLWithString:@"http://maps.google.com/maps/api/geocode/json?address=6th+and+pine&bounds=37.331689,-122.030731|37.331689,-122.030731&...

Why are Objective-C instance variables declared in an interface?

I'm just getting into Objective-C (Java is my primary OO language). Defining an object's instance variables in the interface instead of the class seems strange. I'm used to an interface being a public API definition with nothing besides method signatures (not counting constants here). Is there some reason that state is defined in an in...

_NSAutoreleaseNoPool Breaking but No Helpful Stack Trace

I am getting the message: * _NSAutoreleaseNoPool(): Object 0x3f43660 of class UICFFont autoreleased with no pool in place - just leaking I have placed a break point using the symbol _NSAutoreleaseNoPool and the program does break, however, the stack trace does not show me any of my code only some UIView and Core Animation layer...

iPhone: What is the best approach to changing the sound of a rolling ball based on speed?

I need to play a sound of a ball rolling and change the sound based on the ball's speed. I was using AVFoundation and just playing different samples but that didn't sound natural enough. I tried OpenAL and something like: alSourcef(sourceID, AL_PITCH, thePitch); and passing in thePitch, but didn't like the results. Does anyone have a...

Basic iphone timer example

Okay, I have searched online and even looked in a couple of books for the answer because I can't understand the apple documentation for the NSTimer. I am trying to implement 2 timers on the same view that each have 3 buttons (START - STOP - RESET). The first timer counts down from 2 minutes and then beeps. The second timer counts up...

How to use accessors within the same class in Objective C?

Hi, I have a few properties defined in my header file like so @property (assign) bool connectivity_N; @property (assign) bool isConnected_N; In my implementation file I have an init and the synthesized properties like so @implementation Map @synthesize connectivity_N; @synthesize isConnected_N; a init to set the initial values like...

Replace an Array with an Array

I have and NSMutableArray and I want to replace it with another, but if I try to do it like this... firstArray = secondArray; ...then it seems to erase the entire firstArray and I get this error message.. Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0...

Autorelease with elements in a UITableViewCell - memory leak

In my 'cellForRowAtIndexPath' method for a UITableView delegate, I'm allocating a cell if it doesn't exist, and in this cell, I'm creating a new activity spinner like so: UIActivityIndicatorView *actView = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray ] autorelease]; I'm using Leaks...

Function to swap pointers in Objective-C

- (void) swapController:(MyViewController*)controller1 with:(MyViewController*)controller2 { MyViewController *swap = controller2; controller2 = controller1; controller1 = swap; } Looks like this doesn't work because I'm not passing references. How to do it anyway? ...

Memory management technique for Objective-C iVars/properties

Is the following code doing anything unnecessary? @interface MyClass { NSArray *myArray; } -(void)replaceArray:(NSArray *)newArray; @implementation MyClass -(void)replaceArray:(NSArray *)newArray { if( myArray ) { [myArray release]; myArray = nil; } myArray = [[NSArray alloc] initWithArray: newArray]; }...

Is Objective-C++ a totally different language from Objective-C?

As the title says... are they considered different languages? For example if you've written an application using a combination of C++ and Objective-C++ would you consider it to have been written in C++ and Objective-C, C++ and Objective-C++ or all three? Obviously C and C++ are different languages even though C++ and C are directly comp...

Where'd my sounds go?

In my Row class I have the initWithCoder method and everything restored in that method works fine, but only within the method. After the method is called I loose an array of sounds that is in my Row class. The sounds class also has the initWithCoder method, and the sound plays fine but only in the Row class initWithCoder method. After de...

iPhone Development - calling external JSON API (will Apple reject?)

Ok guys, so im new to iPhone development, so apologies if this is a silly question, but before i actually create my app i want to know if this is possible, and if Apple will reject this. (Note this is all theoretical) So i'd have a API (.NET) that runs on a cloud server somewhere and can return HTML/JSON/XML. I'll have a website that ...

How to detect if Safari is disabled on iPhone

How can you detect whether Safari has been disabled by parental controls on the iPhone? I know it is possible because the App X3Watch refuses to work until Safari is disabled. As far as I can see there is no api for the parental controls, so what technique can be used for this? ...

can a uiviewcontroller push a uitabbarcontroller?

if so, how do i setup my uitabbarcontroller in IB? all the examples ive seen create the uitabbarcontroller in the app delegate. ...

non reference-counting dictionary in objective-c

Is there any 'easy' way of having pure objective-c containers, such as NSMutableDictionary or CFMutableDictionary, that don't increment the reference count of added objects, without using the c++ standard library? EDIT: Explanation - the reason I want this is so I can implement a kind of "Exactly One" pattern - a class will have a stati...

how to draw square after load the application in iphone(graphics) ?

how to draw square after load the application in iphone(graphics) ?(I know how to draw shapes but i exactly want to show draw shape after my app. launch what can i do) and also want to fill color after app. launch ? ...

+(void) initialize in objective-c class static variables constructor

I found some sample code from here. static UIImage *backgroundImageDepressed; /** * */ @implementation DecimalPointButton + (void) initialize { backgroundImageDepressed = [[UIImage imageNamed:@"decimalKeyDownBackground.png"] retain]; } is it something like this - +(void) initialize method initialize static variables of a class...

how to make a sprite goes behind another sprite

I'm using CCSprite to redraw my app's background image (it's like a moving background). However I'm also using CCSprite to draw my hero and enemies. At some cases the enemies goes behind my background image. My understanding is that if you do: [self addChild:sprite1]; [self addChild:sprite2]; Then sprite1 will be behind sprite2 if the...