objective-c

How to define a function that returns an NSString in Objective-C / Iphone SDK

Hmm i would have thought this would be a little more straightforward.. in my .h file, i'm trying the following #import <UIKit/UIKit.h> @interface myViewController : UIViewController { } - (int)doStuff; - (NSString)doMoreStuff; @end the compiler flags my doMoreStuff but allows doStuff.. any clues? thanks in advance ...

Best way to implement tap anywhere to cancel (a la App Store download button)?

I have a UI element. When I tap it, it animates to an intermediary state. A tap anywhere else on the screen should cancel the interaction, while another tap on the UI element should proceed. I've implemented this using a guard view (subview of window & above every other subview) and then reparenting the element into the guard view befor...

Arrays in Objective-C

If you want to use an array of characters/badguys is it better to have one array of badguy objects and each object have properties like Badguy1: color=blue, health=80. Then you loop through your array of characters and pull that information.... OR is it better to have multiple small arrays like character array, color array, health array ...

When to use self?

I have an iPhone app where one view, View A, updates another view in a tab bar, View B, using: // This works. - (void) reloadData { MyDB * db = _GET_DB_CLASS; if(data != nil) // data is a property of type NSMutableArray [data release]; NSMutableArray * d = [db getDataQuery]; data = s; // Don't release since we a...

Division and NSUInteger

I have some calculation that involves negative values: row = (stagePosition - col) / PHNumRow; Say stagePosition is -7 and col is 1. They are both NSInteger, including row. PHNumRow is 8. If PHNumRow is NSInteger, I get the result I expect: -1. But if PHNumRow is NSUInteger, the result is garbage. Why should it matter if the divisor...

sortUsingFunction and "void value not ignored as it ought to be"

Hi all, In my objective c class, I'd like to sort an array like this: NSArray *sorted = [unsortedArray sortUsingFunction: mySort context: NULL]; My sort function is implemented as: NSInteger mySort(id one, id two, void *ctx) { return 1; } When I build the program the compiler tells me: error: void value not ignored as it ought to...

Method in Objective-C that points to an object

I have created a few sprites using a spriteclass and I have loaded them into an array. In my app, I loop over the array checking for particular conditions (position, etc.). I want to create an explosion method that I can pass one of these objects to and then using the pointer pull the position of the object on the screen and show an expl...

Is it possible to declare a method as private in Objective-C?

Is it possible to declare a method as private in Objective-C? ...

How do I detect a touch over a specific area

Currently I see that a touch event will show me the UIView where the touch occured. But what if I need to detect a touch of some non rectangular shape, like a circle. How would I go about doing something like that ? Basically I want to do something only if the user touches somewhere within a circular area that's not visible. Any help/...

deep copy NSMutableArray in Objective-C ?

Hi All, Is there any built-in function in Objective-C allows me to deep copy a NSMutableArray? I looked around, some people say [aMutableArray copyWithZone:nil] works as deep copy. But I tried it seems no. Right now I am manually doing the copy one by one (a 9*9 array): //deep copy a 9*9 mutable array to a passed-in reference array ...

Cocoa or Objective-C?

In regards to iPhone development, how do you now when your using a Cocoa vs pure Objective-C objects. For example, the following are Objective-C: NSTimer NSString int, float NSMutableArray But these are Cocoa: UILabel UIColor(?) UIView And to be clear, does Cocoa Touch == iPhone development Cocoa == Mac OS X development ...

Best Method of Persisting Custom Objects

Hey guys, I have a custom object that simply inherits from NSObject. It has 3 members - two floats and an NSDate. My app is going to have an array with a number of these objects kicking around, and I need to persist it between runs. What is the best way to accomplish this? I've thought about using the SQLite db, but I'm thinking that ...

array of ints

im struggling to create an array of ints in objective c. the way I'd do this is javascript would be: arr = new Array ( 1, 2, 3, 4, 3, 2, 2 ); i need to use an nsmutablearray, as the values need to be updated (it's a tile map for a game). any help? ...

NSWorkspace notificationCenter not sending notifications under Garbage Collection

I'm not sure if I'm doing something wrong here: I'm registering for Workspace notifications using this snippet in awakeFromNib [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(noteReceived:) name:nil object:nil]; the selector noteReceived: takes a single NSNoti...

Is this all for Garbage Collection in Objective-C?

Hi I just picked up Obj-C and quite dislike its manual memory management. I decide to go with its Garbage Collection, by adding objc_startCollectorThread();//garbage collection in my Main() and change the garbage collection value to [-fobjc-gc] So is that all I need? So I can program "freely" like I do in Java/Python..etc? ...

Objective C: Modulo bias

Using value = arc4random() % x How can I avoid or eliminate modulo bias? Thanks all. BTW, at least according to Wikipedia, modulo bias is an issue when programming games of chance. ...

From Fraction to Decimal and Back?

Hi folks... Is it possible to store a fraction like 3/6 in a variable of some sort? When I try this it only stores the numbers before the /. I know that I can use 2 variables and divide them, but the input is from a single text field. Is this at all possible? I want to do this because I need to calculate the fractions to decimal odds. ...

UINavigationController and modalViewController problems

Hi I'm having this problem: I have a UITabBarController with UINavigationControllers in each tab. However, I'm trying to implement an action that, when I click on a button, should present me a new view with a UINavigationController (since it will be multi-view) in a modal way. What I've tried is to implement a new UIViewController, wi...

Why Emacs/Vim/Textmate? Isn't Xcode good enough?

Hi I mostly do C++, Objective-C programming. And I found Xcode plus an auto completion/macro plugin (Completion Dictionary) quite adequate. However, all people seem to praise over their pure text editors. I tried Textmate for a bit; liked its simplicity but dislike its files/framework handling. Am I missing something here? Or, do Vim ...

Is there any way to enforce typing on NSArray, NSMutableArray, etc.?

Can I make an NSMutableArray where all the elements are of type SomeClass? ...