Objective C equivalent to javascripts setTimeout?

The performSelector: family has its limitations. Here is the closest setTimeout equivalent: dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * 0.5); dispatch_after(delay, dispatch_get_main_queue(), ^(void){ // do work in the UI thread here }); EDIT: A couple of projects that provide syntactic sugar and the ability to cancel execution (clearTimeout): https://github.com/Spaceman-Labs/Dispatch-Cancel https://gist.github.com/zwaldowski/955123

Objective C defining UIColor constants

A UIColor is not mutable. I usually do this with colors, fonts and images. You could easily modify it to use singletons or have a static initializer. @interface UIColor (MyProject) +(UIColor *) colorForSomePurpose; @end @implementation UIColor (MyProject) +(UIColor *) colorForSomePurpose { return [UIColor colorWithRed:0.6 green:0.8 blue:1.0 alpha:1.0]; } @end

urldecode in objective-c

I made a quick category to help resolve this 🙂 @interface NSString (stringByDecodingURLFormat) – (NSString *)stringByDecodingURLFormat; @end @implementation NSString – (NSString *)stringByDecodingURLFormat { NSString *result = [(NSString *)self stringByReplacingOccurrencesOfString:@”+” withString:@” “]; result = [result stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; return result; } @end Once defined, this quickly can handle an encoded string: NSString *decodedString = [myString stringByDecodingURLFormat]; Plenty of … Read more

Core Data: Error, “Can’t Merge Models With Two Different Entities Named ‘foo’ “

For those who come across this question after trying to use core data lightweight migrations: I was having this issue even after following the instructions for creating a new version of my data model. I noticed that there were two “.mom” files in my application bundle, one “.mom” and one “.momd” directory that contained “.mom” … Read more

How to view the data in sqlite file running in iphone application? [closed]

If you want to view your database when running on Simulator it is located at the following location user/Library/Application Support/iPhone Simulator/version of SDK(4.2eg)/Applications/4AF938D6-E981-4971-A588-3424B64E7EE7(eg)/Documents/yourdatabase.sqlite If you want to view the database in your device then you can use a software like iExplorer. Cheers Edit : The location of sqlite file has changed. It currently resides in … Read more

Get text of button from IBAction – iPhone

The sender should be the control which initiated the action. However, you should not assume its type and should instead leave it defined as an id. Instead, check for the object’s class in the actual method as follows: – (IBAction)onClick1:(id)sender { // Make sure it’s a UIButton if (![sender isKindOfClass:[UIButton class]]) return; NSString *title = … Read more

tech