Code updates

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.

CSPopViewService

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

And here is how it is actually used:

This will have the following effect:

  1. It will present the ‘pop’ object pointing at the first bar item 2 seconds after the command is given.
  2. It will present the ‘pop2’ object pointing at the second bar item 1 second after the ‘pop’ item will appear.
  3. 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.

Making fat static Libraries (Simulator + Device), and applying to Three20

I am starting to get involved with the Three20 project. This project contains valuable classes and UI elements that I need. However, this big library is notorious for its difficulty to include inside an XCode 4 project. The included install script does not work, and the manual install instructions are a miss, and I ended up with Xcode complaining that it can’t find header files, even if I had set up the header search paths correctly.

So, I decided to pre-build the static libraries and include them to my project, and I was successful… to an extent. You see, I couldn’t use the same static libraries for the Simulator and the device, because the libraries built are built each time for the device you specify, and that device only. For example, if you build the libraries for the simulator, the produced libraries will work for the simulator. For the device, you need a different library package.

That led me to the long trip of finding a way to compile a static library for iOS that works for different architectures: armv6, armv7, and i386. Read on to find out how you can manage to make a static library that will work on all platforms.

Continue reading

Thoughts on Singletons

There are sometimes where some things keep bugging me in terms of programming. I often keep asking myself and others about utilizing the best techniques to solve various programming problems and applying certain concepts in a program.

Most answers I keep reading/hearing tend towards the “wow” factor. Which is something like “I don’t know exactly why, but it would be cooler if you did it like this”. I don’t usually listen to any recommendation regarding programming practices if it isn’t backed up by strong arguments as to how it may affect me in the long or short term as far as my projects are concerned. As programming languages are evolving, so do practices utilizing those languages, and often, as good programmers as we may be, we may sometimes find ourselves lagging behind others who may be less experienced, but better listeners.

Let’s face it. Many of us have utilized a not-so-well-thought technique in favor of completing a task within a certain amount of time. In other words, we have all sacrificed the chance to use good programming practices in need of being “faster”. Usually, this results in usable code, that may be improved in later versions. Less often, this isn’t the case.

As far as programming practices go, there are few of them that have received as much love and hate as Singletons.

Continue reading