Skip to main content

Posts

iPhone - How to handle errors at runtime

When writing code, there are many situations that must be treated as runtime errors : an alloc/init returns nil, a resource is not found, a [someClass canDoThis] returns NO for an absolutely-needed feature where YES would be the natural answer, ... For all these situations, I have written an exitWithMessage routine (that displays an alert box), and each class has a kill method that frees allocated memory. So... When in an init method, you have these kind of exceptions, I supposed you could do : [self kill]; [OneClass exitWithFatalErrorMessage]; return nil; - (void) exitWithFatalErrorMessage:(NSString*)message { UIAlertView* alert = [[UIAlertView alloc] initWithTitle:NSLocalizedStringFromTable(@"Error" @"ErrorMessages", @"") message:message delegate:self cancelButtonTitle:NSLocalizedStringFromTable(@"Understood", @"ErrorMessages", @"") otherButtonTitles: nil]; [alert show]; [alert release]; } - (void)alertV

Convert an iPhone phone number format for a "dial-able” string

I am building an iphone app that reads a phone number from the address book and dial it (with some other things of course...:)). When I load the phone numbers from the AB they are in this following format: "1 (111) 111-1111" which is not "dial-able" when using this: fullNumber = [NSString stringWithFormat:@"%@%@", @"tel:", phoneNum]; Why is that happening? What would be the best way to approach this? How could I convert the phone number into a string of digits (with no spaces or "-")? Thanks.

What control should i use when doing this in objectice C

following are my snapshot please look at it: http://bit.ly/y7U05k or below is the attached image in this snapshot i have to make the boot control like images when i click image#1 then image#1 show on the upper side UIImageView i also define on the image... image#1 .. image#1000 so please help me what control's should i use, i think i should use UIScrollView but i don't know what is the heigh and width i should take for that because UIScrollView has only game of height and width and also how to define click control on them. please help and i am very thankful if u give me the code but don't mind .. thanks I want some slider look like .. i slide the below images

Developing a new app; is maintaining iOS 4 compatibility still worth it? [closed]

I am currently in the starting phase of developing a new iOS app (for both iPhone and iPad) for a client. I'm really indecisive if I should still support iOS 4 or not. I tried to find some statistics about the adoption of iOS 5, one of the only fairly recent articles that I could find was this one. This article shows that 59,16% of all users of Bump for iPhone were using iOS 5 or later as of December 30th of last year. The (free) app will not be out for another 1.5 to 2 months, my personal guess is that the iOS 5 adoption percentage will be pretty large by then. I fully realize that there is no single answer to this question, but I would like to know what your experiences with backwards compatibility are and if you think it is worth the hassle. I would really like to use the new Storyboard functionality of Xcode and I would also really like to use ARC (although I understand that it is partially useable with iOS 4 too). The app will also use quite a bit of JSON and which is no

Recursively traverse object in Objective-C

I'm converting diverse JSON objects to structured objects and want to iterate over all the nodes to process each one hierarchically. JSON framework supports conversion to an NSDictionary, which I thought was unstructured. I want to recursively iterate through each item and pay respect to the structure. How would this be done with either a dictionary or generic NSOBject? Example: - (void) processParsedObject:(NSDictionary *)obj { if (atTheEndOfTheTail) { NSLog(@"Object description: %@\n\n", obj.description); } for (id object in obj) { [self processParsedObject:object]; } } Update: I asked the question more clearly here (with answer): Recursively traverse NSDictionary of unknown structure

get ascii code from string in xcode for iphone app

hey just a couple quick noob questions about writing my first ios app. Ive been searching through the questions here but they all seem to address questions more advanced than mine so im getting confused. (1) All I want to do is turn a string into an array of integers representing the ASCII code. In other words, I want to convert: "This is some string. It has spaces, punctuation, AND capitals." into an array with 62 integers. (2) How do I get back from the NSArray to a string? (3) Also, are these expensive operations in terms of memory or computation time? It seems like it might be if we have to create a new variable at every iteration or something. I know how to declare all the variables and im assuming I run a loop through the length of the string and at each iteration I somehow get the character and convert it into a number with some call to a built in command. Thanks for any help you can offer or links to posts that might help!

Cocos2D iPhone - running actions on multiple targets + callback

I have an array of objects (objArray) and an array of actions (actArray). Both arrays are in order, I mean, object at index 0 of objArray has to perform action 0 on actArray. To make the explanation clear, lets imagine both arrays have 3 objects, obj0, obj1 and obj2. obj0 has to perform action 0 on actArray obj1 has to perform action 1 on actArray obj2 has to perform action 2 on actArray these 3 operations (or n, in the case of the array) have to happen simultaneously. When all animations end, I need the method animationsFinished to be called. How do I do that? I am beginning in Cocos. I have googled around and have not found any practical example around. I have found CCSpan but I don't see how this can be used with multiple objects each one with its own action. thanks.