Implementing scrolling behaviour without UIScrollView

Suppose you want to create a screen that looks something like this.


How would you do it? You may think that the labels on the right side can be put inside a UITableView. But there is a problem: each label belongs to a certain sector on the wheel, meaning that each label should be aligned vertically to a corresponding number on the wheel. So, as you rotate the wheel, the vertical distances between the labels will not stay the same. I’m not sure if you can dynamically change the row height in UITableView, but even if you could, this approach doesn’t seem to be right.

When I had to implement such a screen, I basically created my own version of a table view, with reusable cells for the labels on the right side as well as for the sectors of the wheel. I’m not going to go into detail about how I did it. The process was pretty straightforward. Actually there was no table view. It was just a bunch of reusable views which I called cells by analogy with UITableView.

What I want to tell you about, though, is how I implemented the scrolling. Because I had some problems with it.

There are two parts to scrolling. First part is when your finger is on the screen. The second part is the inertial movement of views after you lift your finger off the screen.

The first part you implement in the touchesMoved:withEvent: method. It may look something like this:

What happens here is easy to understand.

In the second part, at the moment when you lift your finger off the screen, you need to calculate the initial angular velocity with which the wheel will start its rotation. That velocity will then decrease with time. The problem I had was about calculating that initial velocity.

The solution was easy but I was thinking too hard.  I tried to implement strange use cases. I thought, what if you put your finger on the screen, then move, then instead of lifting it you wait for some time, and then with quick movement you swipe and lift your finger? Now, I thought, the velocity in this case should be calculated based only on the last swipe. And the first movement should be ignored.

What I did was I saved the position and time of the last touchesMoved event. Then I used it in touchesEnded:withEvent to calculate velocity. So, to calculate the initial velocity of inertial movement of the wheel I used only the last microscopic movement of the finger. And it sort of worked. But not always. In most cases that last little movement would take about 0.01 seconds. But in some cases it would take much less than that, something like 0.00001 seconds. The movement itself almost always was no less then 2 pixels. That would result in a very high speed. Imagine that you don’t do a swipe, and just gently lift your finger off the screen, expecting the wheel to stay still, but it starts rotating!

I tried to artificially limit the velocity, but it resulted in stalling of the wheel from time to time. Finally, as an experiment I tried to use the whole movement of the finger, not just its tiny last part. And it worked! Then I compared the behaviour of my screen to that of a normal UITableView, and as far as I could see it was exactly the same. So, that lead me to believe that’s exactly how the scrolling is implemented in UITableView. Here is the code that I used (not exactly):

Update (September 6, 2016)

OK, it turned out that it wasn’t as simple as I described it in this post. I had to make one little adjustment.

Imagine, that you move your finger on the screen and then stop, wait a second, and then just lift your finger off the screen. In this case the wheel must not move. But in the simplistic model that I have described above you may produce an undesirable movement of the wheel.

How to fix this? You need to analyse the last part of your touch to learn if there was a significant enough movement of the finger in that last part. If there was no movement or it was less than a certain amount of points, you just set the angular velocity of the wheel to zero.


Creating a settings screen using UITableViewController

A settings screen is a screen that looks something like this:

When I started out with iOS development, I knew only one way of creating such a screen. I would create a UIScrollView and just put all the views and their constraints on it manually using the Interface Builder. That was a lot of work but at that time I didn’t know any better.

Once I had a job interview. And an interviewer asked me how I implemented a certain settings screen in my app. I told him it was a UIScrollView with a bunch of views in it. He asked me why I hadn’t used UITableView, that way I could have  implemented repeating elements as UITableViewCells. Good idea! – I thought.

Up until that point I only used UITableView with dynamic cells. So I tried table views with static sells. It turned out you can only use them inside UITableViewController, and not inside UIViewController with a table view. That got me confused. I couldn’t figure out what was the use of a UITableViewController, since there was no way to customise it. For instance, you can’t add a button at the bottom of the table view if that table view is inside UITableViewController.

Having no luck with static cells I tried using table views with dynamic cells to create settings screens.I used this approach in a couple of projects. It worked, but it wasn’t much of an improvement over using UIScrollView. With scroll view you have to do a lot of work in the Interface Builder. With table view with dynamic cells you have to do a lot of coding.   

Anyway, a couple of days ago I finally figured out how to use UITableView with static cells to create a settings screen. The solution is so simple, I can’t believe I figured it out only now, after 2 years of doing iOS programming.

This is how you do it. You create a UIViewController and a UITableViewController. Then you put your UITableViewController inside your UIViewController, as a child view controller. That’s it. If you want to put a button outside of the table view, just do it in the UIViewController. This is how it may look in your Storyboard. 

The cool thing is that once you created one cell, you can just copy it. Then in your UITableViewController you can make outlets for all your text fields, labels, buttons and other UI elements you have inside the table view. Also, when the keyboard goes up, the table view adjusts accordingly.

Unfortunately, I couldn’t customise the section headers right in the storyboard, so I had to do it programmatically. Here are the only three UITableViewDataSource methods that I implemented:



Adding and removing Child View Controllers

When you add or delete a child view controller, there is a number of things you need to do. For me it has always been  too easy to forget what things I needed to do and in which order. So I decided to create this post as a little reminder for myself. All the quotes and code examples are from Apple’s “View Controller Programming Guide for iOS”.

Adding a Child View Controller

  1. Call the addChildViewController: method of your container view controller. This method tells UIKit that your container view controller is now managing the view of the child view controller.
  2. Add the child’s root view to your container’s view hierarchy. Always remember to set the size and position of the child’s frame as part of this process.
  3. Add any constraints for managing the size and position of the child’s root view.
  4. Call the didMoveToParentViewController: method of the child view controller.


Removing a Child View Controller

  1. Call the child’s willMoveToParentViewController: method with the value nil.
  2. Remove any constraints that you configured with the child’s root view.
  3. Remove the child’s root view from your container’s view hierarchy.
  4. Call the child’s removeFromParentViewController method to finalize the end of the parent-child relationship.




Initializing the Core Data Stack

This post is a little memo I made for myself. Hope it will be useful to you too. You can find the sample code in Apple’s Core Data Programming Guide.

Here are the steps you take to initialise the Core Data Stack.

  1. Initialise Managed Object Model with modelURL. The model file may look like “DataModel.momd” and is located in the main bundle of your project.
  2. Initialise Persistent Store Coordinator with Managed Object Model from step 1.
  3. Initialise Managed Object Context. You can save it as a property, to access it later.
  4. Take Persistent Store Coordinator from step 2 and set it as a Persistent Store Coordinator of the Managed Object Context from step 3.
  5. Create storeURL. Your store can be named something like “DataModel.sqlite”, and should be placed in the Documents directory.
  6. Using the storeURL from step 5 add the store  to the Persistent Store Coordinator from step 2.

That’s it. You should end up with something that looks like this:


On writing short posts from now on

Today I came up with an idea of how I should run my blog from now on.

Here is the thing. I learn something about programming every day. But what I learn during one day is usually not enough to make for a good, average sized article on this blog. Of course, I can just research a specific topic for several days and when I have enough to say about the topic write a blog post. That’s the way I was trying to run this blog up until now.

But the problem is that I am not very consistent with my topics. I switch them very often. Some time ago I decided to create a web app with JavaMail and MySQL server (I wrote a post about it). The next day I thought it would be cool if I was able to do some UI/UX design on top of programming. So I started learning photoshop. Couple of days ago I had to use some Python on my job (I learned a little bit of Python a long time ago, but I have never used it at my job before). As a result I got interested in Python, so now I want to learn more about it. And so on.

What I like about my blog posts is that I can always come back to them and be reminded of the stuff that I have once learned. I like to use this blog as my personal learning diary. That way I don’t have to Google the same stuff over and over again. But again, the problem is that, because I am not consistent with my topics, I don’t write a lot of articles on this blog.

And here is my idea. What if instead of trying to write normal sized articles I would just write every day about the stuff that I learned that day. Sure, these short articles will be of lesser value for the readers. But at least I will be able to write on a regular basis. And I will have my learning diary, which is super cool.

That’s it. I don’t want to commit myself to daily blogging just yet, but I suspect that I will in the near future.

For now I just allow myself to write short posts. 


My new project – creating an email subscription web service (Part 1)

This post starts a series of posts on me creating a certain web app. I will create this app for educational purposed as I am currently learning web development. As you may know, my specialty is iOS development, but I feel like I need to get at least some experience in server side development.

The best way to learn how to program is to build something for real, so I have chosen to create an email subscription web service. You know, the kind of service for entrepreneurs that allows them to build lists of their potential customers with emails. The one example of such an app that I know of is MailChimp. So, I’m going to do something similar.

There will be a difference though, that will make things much easier for me. The difference is that my app will be entirely mine, meaning that I will be its only user. This app will help me collect the emails of other people. Who are those other people? Maybe the future readers of my blog. Maybe future customers of my future businesses. Who knows? The thing is that creating such an app is a challenging task and it requires learning a lot of useful stuff, like programming a web app and designing a database.

I will be using Java server with JavaMail framework and MySQL database. Mind you I don’t know much about any of those things. I will be learning them along the way as I will be developing my app.

The first step: database

First of all I guess I’m going to design a database. I have a MySQL server installed on my computer. I have already created a database called email_subscription_db in it. Before creating tables and populating them with data I decided that I should learn how to use some visual tool for dealing with databases. Designing a database through Terminal window requires too much typing. So I downloaded MySQL Workbench. I looked at it and it seems easy to use. I haven’t done much with it yet, though.

Before creating tables I need to figure out exactly which tables I will need. And still before that I need to decide what things my app should be able to do, because that will determine what tables I’ll be using.

Web app features

First of all there should be multiple lists of people. And I should be able to send different emails to different lists of people. Also it should be possible to send series of emails that were prepared in advance. I should be able to see the history of my communication with my subscribers as well as stats. It already sounds too complicated for me. Let’s simplify things a little bit. I don’t need to create the whole app in one iteration. For now I can create just a tiny part of the app with the most necessary functionality.


So, what are the things that I need right now? I’ll keep multiple lists, because they are not so hard to create. But I will forget about preprogrammed series of emails for now. And no stats. Basically what I need to be able to do is choose one list of subscribers and send them one letter.

Now what tables do I need to accomplish just that? Here is a list of tables that I think I will need.

  1. people table which will contain peoples emails, names and other information
  2.  lists table which will contain basically the names of the lists of subscribers. 
  3. Lists and people have a many-to-many relationship, meaning that one person can subscribe to multiple lists, and vice versa: one list can have multiple subscribers. To connect the two tables together I need an intermediate table, which I will call Subscriptions. Each subscription will contain an id of a person and an id of a list to which that person is subscribed.
  4. Letters table. This is a table that will contain the letters that I’ll be sending to my subscribers. Each letter will belong to exactly one list. For now this table won’t contain any information on the time when the letter were sent. Or, you know what? Maybe I don’t even need this last table right now. In the first release of my app there will be no way to save letters, so there really is no need for this table.

So, that’s it. I only need three tables: people, lists and subscriptions.

Now I’m going to start playing around with MySQL Workbench.

Part 2


How I became a professional iOS developer in 12 months

In this post I’m going to share my story with you. If you plan to change careers and go into IT, it might serve you as an example. I’m sure there are many ways to go into IT, and the way I did it might not be appropriate for you, but anyway…

My previous profession

So, let’s start from the beginning. After I graduated from university in my home city of Stavropol (Russia) I went to work as a civil engineer at a company located in the same city. The work was all about oil field development. My job was to design all sorts of structures that are needed on oil fields like foundations for different modular buildings, structures that support oil pipes and many others. It seemed like a cool job at first, but I soon realised that there was no place for creativity in that  job. After you learn the basics you just repeat the same process over and over again, copying the same stuff (with little modifications) from one AutoCad drawing to another. I worked there for 2 years. All this time I lived in my parents’ house.

Then I decided to move to Moscow. How I did it with just 50000 rubles in my pocket and what  misadventures I had to go through is a whole separate story. Let me just tell you it wasn’t as easy as I thought it would be. I couldn’t find a job for 4 months.

Finally I was able to get a job. Now my job was to design so called structural health monitoring systems. It was more interesting than my previous job, and I liked it at first. But after some time it became pretty much repetitive. It also didn’t pay well.

By the way, what I hated most about my two engineering jobs is that they were not intellectually demanding. I always felt that I wasn’t  realising my potential. I did the work that can be done by people who are not so bright as I was. And what’s irritating, those people got promoted all the time, not me. Because I don’t have people skills, I’m not talkative and so on. Basically, I felt that I was in the wrong place.

How I decided to go into IT

I have a friend in Moscow who works in IT. He’s a product manager. And he’s always  been telling  me that I could become a good programmer. He advised me to take courses on programming, which I did. The idea was simple: I would learn programming, find a job as a programmer and eventually start to make 2 or 3 times more money than I was making at that time, plus programming is more intellectually demanding activity than filling spreadsheets and editing Word files, so hopefully I wouldn’t be bored all the time.

So, for almost one year in 2011 – 2012 I attended a university on weekends. I was studying Java development. Actually the courses were more general than that. I would learn a little bit about everything in the IT field. As for the actual Java development, there wasn’t a lot of practical stuff in those courses.

Towards the end of that studying I caught a entrepreneurial disease. I watched some YouTube videos, read some books and was convinced that I needed to become a businessman. Immediately. I quit my courses even though I had only one month left to finish them properly and get my degree. I became what is called a wantrepreneur. At first I tried to do MLM. After four months I decided that was not a good idea. Then I tried to do infobusiness for several months. It went a little bit better, but still I couldn’t make money: I was paying more money for the ads than I was getting money from my customers. So eventually I quit that too. I did all this stuff as I was working at my day job.

Finally, after all my attempts to start a business failed, I found myself in a pretty nasty situation. At that point I’d been working at my job for 4 years. I had no new business ideas left. The initial plan to enter the IT was long forgotten. I remember that all I could think of at that time was how much I hated my job.

Luckily, at the very same time I had saved a large amount of money. Since I hated my job so much, for years I’ve been getting myself ready to quit it by saving money. Finally, I quit my job when I had enough money to live in Moscow unemployed for 2 years. I mean no buying stuff, no entertainment, just paying rent and buying food.

You might ask why save so much money in order to quit the job. The reason was that I didn’t just want to quit my job to immediately find another one. I needed to do something different. I didn’t know what, exactly. I needed time to think.

After one month of thinking (while living in Moscow, which is costly for an unemployed person) I still didn’t know what to do, so I started looking for a job. I really didn’t want to get another job as a civil engineer so I was kind of depressed at that time. Actually I didn’t really look for a job, I was just reading through job postings on the internet thinking to myself how sad it was that I’d learned to earn my living by doing things that I hate.

Just at that period of time I met with my friend I told you about a while ago. The IT guy. And while we were discussing my situation he reminded me of my intention to enter the IT. I’d totally forgotten about it, by the way. For some reason I didn’t remember about the IT thing during the whole month I was unemployed in Moscow. But as soon as my friend reminded me that I still had that option, I knew that moment that was exactly what I’d do.

It was the best thing I could do in that situation. I couldn’t stand a thought of just getting another job at that time. And I had plenty of money. So I could spent some time just learning to code. I decided to learn iOS development so I bought myself a MacBook Air. And I already had an iPad at that time. So that’s how I started. There was no reason to stay in Moscow while I was learning, so I moved back to Stavropol to live with my parents. There I only spent money on my food. I didn’t go out much. So I calculated that with that kind of living and with the amount of money that I had I could afford to be unemployed for about 4 years if I wanted to. But I figured that one year would be more than enough to learn programming.

How I learned the actual stuff

I started with the Stanford SC193P lectures on iOS development. I watched all those lectures in the first month of my studying while I was still in Moscow. Well, let me give you some timing.

I quit my job in the beginning of August 2014.

I decided to study iOS development in the beginning of September 2014.

I moved to Stavropol in the middle of October 2014.

I moved back to Moscow and got my first job as a programmer in the middle of August 2015.

So, for the first month I just watched lectures and did my homework. Then I did some tutorials. I released my first app to the App Store in November 2014, I believe. Then I spent several months till March 2015 making and releasing my other apps. Here are my apps, by the way, if you want to check them out:

At the beginning I planned to become a freelancer. I didn’t like the idea of working in the office. And I wanted to travel. I even seriously considered the option of moving to Thailand instead of my home city, to learn programming. Good thing I didn’t do that.

At the beginning of 2015 I registered at oDesk (now UpWork) to become a freelancer. I even got a Payoneer card to collect my money that I would make there. But I soon realised that I didn’t have enough experience to get any serious offers. And the easy tasks were hard to get, because too many people could do them. So, I decided that after my study is over I should return to the corporate world for at least several years before thinking about freelancing again.

After March 2015 I started looking at the job postings. I made a list of common requirements for the iOS development jobs. And I started to learn the required technologies one by one.

At about the same time my IT friend decided to start a business. He created a hotel booking site, took a leave of absence from his job and started to work on his business. He told me that I could create an app for his business if I wanted. That way I could practise on a real world business app, and later I’d be able to show this app off on a job interview. So, I spent about one month working on the hotel booking app for my friend’s business. I never finished it, though. And my friend’s business never took off. But I still used that unfinished app during my job interviews when I was looking for my first IT job. And I learned a lot while making this app, so working on this app was not a complete waste of time.

How I finally got my first IT job

Couple of months later, in the beginning of August 2015, I decided to look for a job for real. The first hurdle that came my way was that there were almost no job postings, appropriate for me. All the jobs had very high requirements. At that point I didn’t understand one simple thing. If your skills don’t match the requirements listed in a job posting, that doesn’t mean you can’t apply for that job. You always have a chance. But I didn’t know about it. So, looking through job postings I felt kind of depressed. I even started to doubt if I could ever enter the IT. What if my entire plan was a big mistake?

Then I tried another approach. I found a list of top 100 Russian mobile development companies. About 20 of them were located in Moscow. About 10 were in Saint-Petersburg. Others were in a bunch of other major Russian cities. My plan was simple. I would send my resume to all the Moscow companies first (at that point I was still in Stavropol, the South of Russia). Then when I get job interviews I’d go to Moscow and live in a hostel there temporarily. If I wasn’t lucky and nobody wanted to hire me, I would send my resume to the Saint-Petersburg companies, then move there and repeat the process. Then, if nobody wanted me there either, I’d do the same approach with other cities. I would visit those cities one by one until I finally find a job somewhere.

It turned out everything was much easier than I expected. I got a job on my very first interview. I had a couple more interviews after the first one, but I went there only out of curiosity, because I already knew that I had a job at that point.   

And that’s how I became a professional iOS developer in 12 months. Maybe later I will add some concluding thoughts here.


What kind of apps to create to make money

If you look at my apps in the App Store, you’ll find out that they (with the exception of my silly game Ugly Plants) are all related to productivity in some way or another. And they are all pretty basic. They are simple. They don’t have server side. They are journals and to-do lists. There is a reason for why it is that way.

Create only useful apps

My first app was Simple Q&A Diary. I had the idea for this app long before I started learning iOS development. I didn’t think it was going to be a mobile app at that time, though. I thought maybe someday I’d create a web app. But I wasn’t sure how I would do it as I lacked experience in coding.  Also I’d have to work on registration and sign in features, which was too complicated for someone who wasn’t even a newbie in programming. At that time I only dreamed that someday I’d learn programming. So it wasn’t a real plan.

Then, when I decided to learn iOS development and I needed to create my first app, I had the idea ready. And what was good about realising my idea in the form of a mobile app was that in a mobile app there was no need to register and log in the users. And the mobile device didn’t need to connect to the internet in order for the app to work. So I created this app. It was a huge success compared to my other apps. It makes me more then $100 a year.

Then I created a game called Ugly Plants. It is a total failure. Nobody likes it. And nobody can find it on the App Store, since nobody is looking for ugly plants. I don’t know what keywords to use to make the game more searchable (or should I say findable?). Anyway, I decided to never make games again, and instead only create useful apps.

Learn from your successes

Ok, let’s not go into the history of all my apps. Let me just tell you what I do to make money from my apps. Here are the guiding principles that I use. First of all, I try to learn from my successes. I know there is a ton of advice on how to promote your app. I don’t use most of it. I don’t have time for PR and I found out that social networks are mostly useless. I guess social networks might be useful if you take them seriously enough and dedicate a lot of time to them. But I don’t have time. I have a full time job. And I don’t take my apps that seriously. The real reason for creating apps is not money but honing my developer skills. And I create apps that I use myself, so even if nobody likes them I haven’t wasted my time creating them. More on that later.

Success for me is having an app that generates $100 a year. Then creating another app that generates $100 a year. Then improve one of my apps so that it starts generating $150 a year. And so on.

How to get an idea for an app? Create apps for yourself

I don’t try to figure out what other people might need. You can do a market research. There is nothing wrong about it. But if you go down that road it is so easy to get mistaken. I personally don’t do it. What I do instead is I create apps for myself. The way I look at it is this. I’m not a unique snowflake. If I need something there must be thousands of people who need the same thing. So, if I create an app for myself, somebody is going to buy it. And that’s what’s happening to my apps. I regularly use all of my apps except that silly game – Ugly Plants. And I see that people are using all of my apps except that silly game that I myself don’t play.

How I price my apps

When I first uploaded my very first app Simple Q&A Diary I made it free. The reason was that I didn’t have my banking account ready for receiving money from the App Store. So the app was free for several months. Then when my banking account was ready I priced the app at $1. It was at that price for quite some time. It was making about $5 a month. Then as an experiment I priced it at $2 for one month. The amount of downloads that month was the same. So by changing the price I doubled my income from this app. I thought maybe it was not the end, so I priced it at $3 for the next month. And the income was much smaller. So I returned it back to $2. That’s how I picked the right price for my first app.

I used the same approach to picking the price for my other apps ever since. I always start small and then increase the price by $1 every month. You need to wait for at least a month to gather enough statistics before changing the price.

One more thing. When I release a paid app I always release it as free first. I keep it free for several days and only after that I put a price on it. The reason for this is that I think there is a high probability that large amount of downloads at the beginning will improve the App Store ratings for the app later on. I always notice that right after release or an update of an app it is actively downloaded for several days and then the number of downloads decreases abruptly and stays low after that. I think that at the beginning the App Store shows your app to some large number of people and rates your app based on their behaviour. The more people from that first sample audience downloaded your app the higher the rating it is going to get. It is just a theory but it looks logical and it explains what I see in the stats of my apps.

Have free apps

I have a free app called Stream Journal. It is downloaded about 5 times a day. I put a button ‘Info’ into it that opens my site in Safari. According to the analytics of my site about 100% of people who downloaded my app visit my site. There they can see my other apps. I don’t know how many of them buy my paid apps. But I think it’s nice to have an audience of hundreds and thousands of people. Later on I’ll be able to promote my paid apps inside my free apps. I’ll be able to use Push Notifications to talk to my audience which is about 2000 people at the time of this writing.

Have a good design

A good design is important. So it is worth it to at least try to make your app look nice. Learning a little bit of Photoshop won’t hurt you, even if you don’t plan to become a designer. But sometimes you don’t even need Photoshop to make your app look a little better. Basically you just need to care about the looks of you app and make at least some effort. When I created my first couple of apps I didn’t think about good design at all. Then when I finally decided to do something about the ugliness of my apps my sales doubled. Take a look at this picture:

comparison of designs

And I didn’t even use Photoshop a lot. Most of the work was done in the Xcode’s Storyboard. The result doesn’t look great, but it looks much better than what was before. That’s the point. If you want your apps to sell, make sure that they at least don’t look like shit.

So, that’s about it. Now you know how I make money on App Store.


How to incorporate iCloud into an existing Core Data app

WARNING (Jan 26, 2017) . Starting with iOS 10 iCloud Core Data was deprecated. That makes this post pretty useless.

Suppose, you have an app that uses Core Data but doesn’t include iCloud sync, and that app is already in the App Store. Now you want to add iCloud sync to this app. How would you go about it?

If you just add an option NSPersistentStoreUbiquitousContentNameKey to your persistent store, the data that was in that store previously will be lost. You don’t want that.

The way you go about it is you create a new persistent store with option NSPersistentStoreUbiquitousContentNameKey and migrate the data from the old store to the new one. This option is what makes the persistent store support iCloud sync, by the way. 

You only need to do this migration once. How do you know when to do it? The best way to find this out it is to use the existence of the old store as an indicator that will tell you if you need to do the migration. At the application start up you check if the old store’s file exists . If it exists, that means the migration hasn’t been performed yet. So, you trigger the migration process. After migration is done you delete the old store.

Enough of theory. Lets see some code. This is an example of Core Data Stack class before we incorporated iCloud:

I got this piece of code from Apple’s Core Data Programming Guide.

The first thing you do is you use another file for the new persistent store. Let’s call it DataModelWithICloud.sqlite. And you need to add an option NSPersistentStoreUbiquitousContentNameKey to that store. I also added a couple of other useful options. So, you just change the code a little bit starting from line 24 in the previous snippet. Thats what you get (only the changed part is shown):

If you noticed, I also changed “Error migrating store” to “Error adding store”. I don’t know why the word ‘migrating’ was there in the first place, since we a not migrating anything at this point. OK, maybe some migration actually takes place at this point, but it must be a migration from an old version of data model to a new one. Not the migration from an old persistent store to a new one, that we are about to arrange.

But before we go further let’s just make a quick fix to the Apple code. Add this variable declaration to the CoreDataStack:

We will be using the Documents directory quite often so it makes sense to use this variable instead of putting couple lines of code here and there. Now you can go back to the first snippet and delete lines 19 and 20. Then find this line

and substitute aplicationDocumentsDirectory for docURL. So, you get this:

Now add these methods to CoreDataStack class:

Basically, this is it. You should call migrateToICloudIfNeeded() method from your appDelegate’s application:didFinishLaunchingWithOptions method. Now, when the user updates the app, the migration to the new persistent store will take place and the old store will be removed. 

PS. There is one more method that may be useful to you. While debugging you might want to delete all data on all devices and even in the iCloud container. So, use this one:

Only make sure not to ship your app with this method.

That’s it. I hope this post was useful to you. If you have any questions leave a comment below.



How I boosted my productivity with the Pomodoro Technique


There are three activities (apart from actually working on my programming job) that I believe are leading me towards success as a programmer. And I try to incorporate these activities into each day of my life. These activities are:

coding (here I’m talking about working on my side projects)

learning new stuff (this one includes reading and creating hello-world type of programs),

writing for this blog.

I started writing for this blog just a couple of days ago. And coding – I wasn’t doing it for quite some time. Out of these three things, what I ended up doing for the most part in the last couple of months, was learning new stuff. And, as I understand now, I’ve been doing it in not a very effective way. I was just reading and never coding. I read about Java and MySQL. I played around with Eclipse. I read a lot of stuff related to iOS development. This learning was taking me so much time that I had to give up working on my side-projects, even though I had previously set a goal for myself to release one simple app every two months.

But now everything’s changed, because several days ago I discovered the Pomodoro technique. It is a method where you work on a single task for 25 minutes (this period of time is called one Pomodoro) and then rest for 5 minutes. Well, actually there are different variations of this technique, but I have chosen to go with those numbers. The goal is to work on a task without being distracted for a certain period of time.

For monitoring my progress I use a tool called Kanbanflow. I created three tasks there. I never delete them or mark them as done, because I do those tasks every day. The tasks are: coding, learning and writing.

Every morning I do 1 or 2 Pomodoros worth of coding. During the day I do 2 to 4 Pomodoros of learning and in the evening I spend 1 or 2 Pomodoros writing for this blog. These numbers are not final, since I’ve been doing the Pomodoro technique for only several days. At the very beginning I set a goal to do only 3 Pomodoros a day: one for each activity. I think it is a good idea to start small. This way you don’t scare yourself away from the hard work, and you start building some good habits, even if you spending only 25 minutes a day on your task.

What I discovered

The main thing I discovered is that I can code! I actually have time for it. And I also discovered that I don’t need to spend much time coding every day. 25 minutes a day is enough.

When it comes to studying, Pomodoro technique is indispensable. Before I discovered the Pomodoro technique I used to keep a study journal. There I would make notes on all the things that I was learning. I also tracked time spent on every single learning session. But I’ve never had a goal of how much time I should spend studying every day. One day I would study for one hour, the next day I would study for 15 minutes. And also, depending on the topic, many times I had nothing to write down in my journal. So there were long sequences of entries which only had the name of the topic and time spent on studying that topic. Over time I lost interest in tracking my progress in this way. I didn’t give it up though, it’s just became burdensome to me. Because of it I would spend a lot of time procrastinating before starting each learning session. I mean, the need to open my journal and write down the date and the topic turned me away from learning altogether. 

And then I discovered Pomodoro technique. Now I will use it to track my progress. And I will still use my study journal. But I will only use it for taking notes when I really need to.

Over time I will try to increase the number of Pomodoros I do every day. By the way, I’m on vacation now, so I have a lot of free time. We’ll see how many Pomodoros I’ll be able to do when I return to my job. And I guess I will try to do the Pomodoro technique on my job too.