objective-c

objective c, checking if object is undefined or nil

Ok, I created my own class(MyObject) subclassing NSObject then in my code I declare this: MyObject * myObject; Then further down in my function, I do: if(myObject == nil) { myObject = [self getObject]; } My if statement returns false, which I want it to be true. In debug mode: just declaring it is assigning an instance to it wit...

Is possible build an iPhone project from mac os x terminal and without an xcode project?

Hello everyone, is possible build an iPhone project from Mac os x terminal and without an xcode project? I'd like to make an iPhone static library without create and using xcode project and only with the terminal. Thanks ...

Cocoa app handling a standard HTTP url scheme

I need to handle HTTP URLs that begin with a certain domain with my app, because it points to a REST source. The web service however is not under my control, so i can't easily introduce a custom url scheme to open the links with my app. Is there a way to intercept and handle such URLs in a Cocoa app? Example: http://static.domain.name/...

Delegate to Self Concept!

Hi Guys, Spare me if you find this too basic and generic. But i hope answering would benefit lot of noobs out there like me. Why we set Delegate to self? Thanks, Taimur ...

How to change the keyboard type for a text field in Xcode

I created a text field in XCode, not Interface Builder. In IB you can select different keyboard types. How can you do the same thing in XCode? ...

Is possible in a Mac App build an iPhone Static Library xcode project?

Hello, I see that I can build iPhone Static Library xcode project with -xcodebuild into the terminal. So I create a Mac App that execute a shell script which build the project. My question is if I can hide my iPhone Static Library project and its classes from user's eyes. Thank you in advance ...

Random number help in Objective-C?

I would like to create just one random number but instead a new random number is being made every time the button is clicked. Where should i put the random number declaration so that it only creates one random number? ...

isEqual doesn't always work for NSIndexPath? What can I use in its place?

I've got some code that relies on comparing two NSIndexPaths and executing different code based on their equality or lack thereof (using -isEqual). Most of the time it works properly, but sometimes it doesn't. I've used the debugger console to test the two indexpaths during code execution, and they look identical to me. Here's the code:...

Code only working in ViewDidLoad method

Hello, I'm using this code after in my ViewDidLoad method : [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:.5]; self.view.frame = CGRectMake(0, 0, 250, 50); [UIView commitAnimations]; It's working fine but if I try to do the same thing in an other method in the same implementation file like this : - (void)s...

How to call a method based from a protocol?

Hello, newbie here. This is an iPhone utility project. First things first. I have a protocol that is this: @protocol FlipsideViewControllerDelegate - (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller; - (void)updateLabels:(NSString *)text :(BOOL)isOn; @end I implement this protocol in my MainViewControlle...

Count number of newlines in a file

Hi, What is the smallest code I can use to count the number of occurrences of the newline character in a file with objective-c / cocoa touch? Thanks! ...

Generating permutations of NSArray elements

Let's say I have an NSArray of NSNumbers like this: 1, 2, 3 Then the set of all possible permutations would look something like this: 1, 2, 3 1, 3, 2 2, 1, 3 2, 3, 1 3, 1, 2 3, 2, 1 What's a good way to do this in XCode? ...

Why is my Objective-C object being deallocated?

I have a problem with an Objective-C object (in an iOS game app) that is being mysteriously deallocated. The object is a GameCharacter instance which is instantiated like so: for (int c = 0; c < kNrOfGuards; c++) { GameCharacter* guard = [[GameCharacter alloc] initGuard:self sprite:guardSprite]; [characterArray addObject:guard]...

how to scroll page left and right with user touch iphone

Hi all, in an Iphone app, I am in need of building a page that scroll left and right by user touch. Much like the built-in weather application already existing in every iphone/ipod, but I am not interested in having a page control. The left and right scrolling is like a sort of history browsing. Moving the finger left and right, I can ...

Control when menu disappears in UISplitViewController

I've got a UISplitViewController set up and working nicely. When a user touches a row, it pops out an indented row of options, which the user can then select to update the detail view. The only issue is that in portrait mode the menu disappears after selecting one of the non-indented rows, so the user has to hit the menu button again to ...

add and remove subview in code block doesn't animate

I have this code for flashing an image on a map as a part of MKAnnotationView: UIView* containerView = [mapView viewForAnnotation:enemy]; UIImageView* redCircle = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Red_half_circle.png"]]; [UIView transitionWithView:containerView duration:2.9 ...

How to pass a string to a function in Objective-C

I made a method like this: -(void) doSomething:(NSString *)str { } I call it like this doSomething(foo); It doesn't work. ...

How to convert this C# code to Objective-C

I need a function that does the same thing as the following: static public IEnumerable<string> permute(string word) { if (word.Length > 1) { char character = word[0]; foreach (string subPermute in permute(word.Substring(1))) { for (int index = 0; index <= subPermute.Length; index++) ...

Using NSMutableArray in a class

Whenever I try to add something to my array in the method nothing gets added to the array. I'm wanting it to when you press the button it will add a new object to the array. // JBNumberGeneration.h #import <Cocoa/Cocoa.h> @interface JBNumberGeneration : NSObject { IBOutlet NSTextField *displayLabel; int randNum; int level; int i...

Can you tell me what this code does in pseudocode?

Possible Duplicate: How to convert this C# code to Objective-C This code purportedly does what I need in Objective-C but it's written in a different language. So I'm trying to convert this code to objective-c but I need to understand it better. It would be easier to understand if it was in pseudocode static public IEnumerable...