Tag: objective c

Should I use properties or direct reference when accessing instance variables internally?

Say I have a class like this: @interface MyAwesomeClass : NSObject { @private NSString *thing1; NSString *thing2; } @property (retain) NSString *thing1; @property (retain) NSString *thing2; @end @implementation MyAwesomeClass @synthesize thing1, thing1; @end When accessing thing1 and thing2 internally (i.e, within the implementation of MyAwesomeClass), is it better to use the property, or just reference […]

Launching an Mac App with Objective-C/Cocoa

When launching Path Finder app with command line, I use open -a Path Finder.app /Users/. Based on this idea, I use the following code to launch Path Finder. Can I have launch app without using open command line? NSTask *task; task = [[NSTask alloc] init]; [task setLaunchPath: @”/usr/bin/open”]; NSArray *arguments; arguments = [NSArray arrayWithObjects: @”-a”, […]

Loading image from CoreData at cellForRowAtIndexPath slows down scrolling

I am working on a UITableView that is very much like the iOS’s native Photo app: it has many rows with 4 image thumbnails in each row. (i.e. each UITableViewCell has 4 UIImageViews) All thumbnails loaded from Core Data. I have revised my implementation multiple times and I can see performance improvements, but it is […]

Why is my transformable Core Data attribute not using my custom NSValueTransformer?

I have a Core Data app with a fairly simple data model. I want to be able to store instances of NSImage in the persistent store as PNG Bitmap NSData objects, to save space. To this end, I wrote a simple NSValueTransformer to convert an NSImage to NSData in PNG bitmap format. I am registering […]

How does -performSelector:withObject:afterDelay: work?

I am currently working under the assumption that -performSelector:withObject:afterDelay: does not utilize threading, but schedules an event to fire at a later date on the current thread. Is this correct? More, specifically: – (void) methodCalledByButtonClick { for (id obj in array) { [self doSomethingWithObj:obj]; } } static BOOL isBad = NO; – (void) doSomethingWithObj:(id)obj { […]

How to get substring of NSString?

If I want to get a value from the NSString @”value:hello World:value”, what should I use? The return value I want is @”hello World”.

Why write 1,000,000,000 as 1000*1000*1000 in C?

In code created by Apple, there is this line: CMTimeMakeWithSeconds( newDurationSeconds, 1000*1000*1000 ) Is there any reason to express 1,000,000,000 as 1000*1000*1000? Why not 1000^3 for that matter?

Objective-C and sqlite's DATETIME type

I have a sqlite3 table that I’m trying to map to an object in objective-C. One attribute of the table is ‘completed_at’ which is stored as a DATETIME. I want to create a property on my objective-C class (which inherits from NSObject) that will map well to the ‘completed_at’ attribute. Objective-C has an NSDate type […]

how do I detect whether I have iPhone 2G,3G,3GS

I want to detect my current device name. How do I detect it through iPhone SDK? Also how do I detect if the iPhone doesn’t have a SIM inserted?

How to detect a pause in input for UISearchBar/UITextField?

I have the following UISearchbar code: – (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; NSString* endpoint =[NSString stringWithFormat:@”http://www.someurl/”, [searchText stringByReplacingOccurrencesOfString:@” ” withString:@”+”]]; NSURL* url = [NSURL URLWithString:endpoint]; NSURLRequest* request = [NSURLRequest requestWithURL:url]; GTMHTTPFetcher* myFetcher = [GTMHTTPFetcher fetcherWithRequest:request]; [myFetcher beginFetchWithDelegate:self didFinishSelector:@selector(searchResultsFetcher:finishedWithData:error:)]; } I want to send this request after a pause in input and […]