All posts by Admin

6 наиболее важных новинок в Android 5.0 Lollipop с точки зрения разработчика


Официальный выход Android 5.0 состоялся 3 ноября 2014 года. Я изучил новинки Android 5.0 Lollipop, поставил на свой Google Nexus 5, посмотрел своими глазами. На официальной странице все можно посмотреть и понять, правда скрыт факт изменения среды выполнения, так как это информация для пользователей. Просмотрел все популярные обзоры, но наилучшим источником на русском языке оказалась статья в Википедии.

Итак, наиболее важные новинки с моей точки зрения (по убыванию):

  1. Переход на виртуальную машину Android Runtime (ART), официально сменяющую Dalvik для повышения производительности и оптимизации, направленной на повышение энергоэффективности системы. Это ведет к увеличению времени работы батареи и отсутствию лагов во всем. Надеюсь, что правда, сложно проверить.
  2. Поддержка 64 битной архитектуры, 64-битных устройств и систем-на-чипе. Система на чипе или система на кристалле – это электронная схема, выполняющая функции целого устройства (например, компьютера) и размещенная на одной интегральной схеме.
  3. Улучшенные сетевые передачи и улучшенное подключение к интернету везде. Надеюсь, что правда, сложно проверить.
  4. Android 5 Lollipop теперь поддерживает не только смартфоны и планшеты, но и системы в автомобилях, часы и телевизоры.
  5. Еще больше настроек уведомлений. Теперь показывается оценка времени заряда батареи. И другие мелкие настройки, которыми будут пользоваться только гики.


  6. Новый дизайн под названием “Material design”. И он явно лучше, чем то, что было раньше. Хотя новый внешний вид трех главных кнопок мне лично не нравится. Поменялись анимации. Сильно изменилась клавиатура – но не уверен, что теперь она лучше. Вообще, не уверен, что мусолить дизайн и кричать о изменениях в нем как о чем-то крупном целесообразно.
  7. nexus2cee_image36

My visit to a YaC 2014 Conference (Mobile section)

YaC 2014 – Yet Another Conference was organized by Yandex in Moscow in October 2014. It is a largest developer conference in Russia. I have participated only in a Mobile section.

There was a presentation from Orta Therox – the creator of CocoaPods, called “Tools, Testing and new New Team Members. The Story of Post 1.0”. Here is his presentation.

A presentation from Ashley Nelson-Hornstein from Dropbox called “Building Quality Code That Lasts: A Dropbox Story”

and some other presentations from Russian developers.

All materials are published now and available for free.

What I did get from all that is something new about unit and integration testing – using mocks to speed up network connection related tests, information about some new instruments and team development, something new about View stacks and some understanding of possibilities of using JavaScript in a new iOS WebView – WKWebView. Found a new friend – another mobile developer.

Here are some of my own photos:

How to safely work with NSDictionary that may have empty values or may not have a key


NSDictionary sometimes can contain a key with empty values or even may not contain a key, that we expect to have. This is a very common problem, when you work with server APIs and parse network JSON responses to a NSDictionary. In this post I will describe how to safely work with NSDictionary that may have empty values or may not have a key.

The method objectForKey will return nil, if there is no a key, a key doesn’t exist in a dictionary.

You can’t add nil to a NSDictionary. NSDictionary will throw an NSInvalidArgumentException if you attempt to insert a nil value. You would have to use [NSNull null] instead. NSNull is something called nothing, while nil is simply nothing.

Checks that value for key is not empty.

But if a dic doesn’t contain a key, you will enter to the body of a condition dic[@”key”] != (id)[NSNull null].

For example, before taking integerValue from obj, you must be sure, that it is not [NSNull null]:

Checks that the key exists, but value for it can still be empty.

So the optimal check while reading NSDictionary is this, where key is “key”

You can’t add nil to a NSDictionary. So you have to check, that your object is not nil before adding:

But you can add [NSNull null]:

Version of code, where you check if dictionary entry exists and not empty:

I have created a NSDictionary category that has a method to check if a key exists and value is not empty:

This is an example, how to use it:

iOS : Creating Random E-mail and Phone Number


This is a sample code how to create random e-mail and phone number. I used it in my unit tests of authorization.

Solution for iOS Developer Technical Interview Problem

I have found an interesting iOS Developer Technical Interview Problem and solved it.

“I also have the ultimate iOS Developer technical test you can assign a potential hire. It should take 1-3 hours. It is easy to communicate, allows a lot of freedom of implementation so you can really get a better picture into how a developer thinks, and will make sure this developer knows the absolute fundamentals. Ready for it?

Calculate the and display each Fibonacci number from 1 -> max N possible on an iPhone with unsigned integers, and display each F(n) in a table view. The UITableView scrolling MUST remain smooth.

That’s it. You’ll be amazed at how profoundly simple this task sounds and yet how much iOS knowledge can be demonstrated. Not just what they know, but how they structure their work. You can assess their APIs, their separation of concerns when designing classes, the considerations they’ve made for performance, and their knowledge of concurrency. (Not to mention their knowledge of recursive functions.) It is ok to give them the formula, and allow them to use Google. F(n) = F(n-1) + F(n-2).”

This is the result:

GitHub repository with a solution is here.

I used recursion and concurrency. I added a little delay of 0.1 s to make a delay visible but scrolling is still smooth. This is my solution:

It scrolls without lags on iPhone 6 Plus. I do not calculate twice a fibonacci number if already have calculated it, I store a new fibonacci number in a NSMutableArray.

Using dispatch group to wait until multiple operations executed – including completion block (AFNetworking)

Android Java Serialization Using Generics

I have created a class – SerializationManager, it can serialize any objects and write them to files. It can be used to save and restore form states in Android. It is based on Java Generics. What is achieved by this is that you do not need to duplicate serialization code in every class.


Object must implement Serialized interface. Here form is an object instance of a class. It can be named as just obj.

This is how you can use it. First you declare a SerializationManager in your class and you tell it which class you are going to serialize:

Then in onCreate method you create SerializationManager instance:

Writing object to a file:

Reading objects from saved file:

A little joke for reading to the end:
java generics

Tips discovered while using Android spinners : setting selected item and finding objects in arrays in Java

To set a selected item programmatically in Android Spinner, you should use setSelection method.

To get an index of an item to select from an array of strings using IndexOf, you should first use java.util.Arrays.asList method.

Complete code:

Serialize an object, save it to a file and read it from a file in Android

Android interface Serializable is not sufficient to save your objects to the file, it only creates streams.

This is a complete code with error handling and handling closes of streams. Add it to your class that you want to be able to serialize and deserialize.

In my case the class name is CreateResumeForm. You should change it to your own class name.

Use it like this in your Activity:

Sorting objects in Objective-C in Alphabet Order by Name

It is a very easy but a common task. There is no need to create any custom NSSortDescriptors. Let’s say, we have an unsorted array of RRRegion objects, that have a name property. This is how we can sort this array: