Valerio Ferrucci (valfer) develops software on Apple Macintosh since the 1990s until today for MacOS, OSX and, since some years, iOS. He is also a Web (PHP/MySQL/JS/CSS) and Android Developer.
In iOS8 the code to show a simple alert to the user is completely changed. UIAlertView is now deprecated:
The new class is UIAlertController and it is not complex to use (more in a minute). But we also want to support our iOS7 users, so wouldn’t it be nice to have a single class handling the different code? This is what we are going to create in this post.
Sometimes it happens to me to observe my code and to say: “no, these things should be made differently”. Then I go into “refactoring”. I think this is an important step of every programmer. Don’t be afraid to refactor (don’t listen to the voice inside you: “… don’t touch that code! Nothing will work correctly after changing this single byte …”): code is something always in evolution (and in test …).
Seeing the code of Part 2 I don’t like two different callbacks to be passed to the start method:
Design Patterns are something we should use not just because they exists, but because they help us to solve a real problem we are trying to fix. The problem I wanted to solve some times ago was the strong coupling of two view controllers when they want to communicate via a segue.
One of the news of iOS8 is that we can now simply create framework to separate, organize and reuse our code (it wasn’t impossible before but it was more complex).
In some simple steps we will see how to create a version of our PopDatePicker (see A simple iOS PopDatePicker) built as a separate framework.