AFNetworking is the de-facto standard for implementing a robust and scalable network infrastructure in your iOS or OS X application. I personally have used it for the implementation of many professional projects that I have been involved in. And lately I have stumbled across an delightful Framework, PromiseKit, a Promises implementation for iOS. I have then taken the liberty of incorporating Promises features into AFNetworking.
I have taken some time to update my GitHub repository, who has been lonely as of date. While developing code for my projects at the university, I came to realise that much of this code could prove useful to others.
First thing I did was to update the pop service for iOS library. The library is constructed to work with Chris Miles’ excellent CMPopTipView library, and improve automatisation of the appearance and disappearance of the pop tip views. The need for this came from the time I needed to construct a live demo with functionality from the application, so we needed to present and dismiss pop tip views automatically and at arbitrary time intervals.
Consider this code, taken from CSPopViewService.h
Presents the view after a delay
@param view the popTipView to display
@param delay after how many seconds will it be presented?
@param barButtonItem the bar button item to point the view at
@param dismissOther dismiss other views while presenting this one?
- (void) presentPopView:(CMPopTipView *)view afterDelay:(NSTimeInterval)delay pointingAtBarButtonItem:(UIBarButtonItem *)barButtonItem dismissOtherManagedPopViews:(BOOL)dismissOther;
And here is how it is actually used:
CMPopTipView *pop = [[CMPopTipView alloc] initWithTitle:@"Title" message:@"Message"];
CMPopTipView *pop2 = [[CMPopTipView alloc] initWithTitle:@"Title" message:@"Message"];
CMPopTipView *pop3 = [[CMPopTipView alloc] initWithTitle:@"Title" message:@"Message"];
self.popService = [[CSPopViewService alloc] init];
[self.popService presentPopView:pop afterDelay:2 pointingAtBarButtonItem:self.barItem1 dismissOtherManagedPopViews:NO];
[self.popService presentPopView:pop2 afterDelay:3 pointingAtBarButtonItem:self.barItem2 dismissOtherManagedPopViews:NO];
[self.popService presentPopView:pop3 afterDelay:5 pointingAtBarButtonItem:self.barItem3 dismissOtherManagedPopViews:YES];
This will have the following effect:
- It will present the ‘pop’ object pointing at the first bar item 2 seconds after the command is given.
- It will present the ‘pop2’ object pointing at the second bar item 1 second after the ‘pop’ item will appear.
- It will present the ‘pop3’ object pointing at the second bar item 2 seconds after the ‘pop2’ item appears. The other 2 pop items will be dismissed when ‘pop3’ appears.
That way, you can make presentation or tutorials within your application. You will not need to worry about threading or timers, since all timers can be cleaned up using the -stopAllTimers function. The best place for this function is the -viewWillDisappear function inside your view controller.
Sequential Reader – seqreader
Sequential Reader is a (little for the time being) file reader that I made, aimed at facilitating parsing files. I wanted a system that is fast and memory efficient, and can parse a file line by line. I had some line-by-line parsing to do in a HUGE file, to complete a project for the university. Turns out that many people had the same request as me, as Apple did not provide an easy way to do that.
Anyway, CSFileReader was created for this purpose. Just instantiate the reader with the file path, its encoding, and then assign a delegate to it. While parsing, the file will send you callbacks through the delegate functions, with the line that was read in NSString format.
I will have to invest some more time to these libraries to make them more mature. I will also have to create a new repository for CSWatchDog, a nice simple wrapper around GCD timers, aimed at facilitating working with events about to be fired after a few seconds. More on this, and updated code, soon.
Having troubles with JSONKit and nil and null exceptions in occasions you can’t understand? This thing happened to me when trying to use something like “self.textview.text = [dictionary valueForKey:@”someKey”];” and I couldn’t understand why I kept receiving extensions about mismatch of the classes and NULL.
Core data is fast, even on iOS, where handheld devices lack in speed when compared to desktop computers. However, there will be times where you will be required to do some heavy reading, wether that will be plain files from disk or information stored in Core Data. In my case, I initially tried to load too much data from a Core Data database using GCD, resulting in deadlocks, and later, I tried that using NSOperation. To save many people from frustration, I thought I should post my experiences and some general guidelines here.