Tuesday, August 2, 2016

5 Things Udacity Students Taught Me About iOS Development

"You can't learn something until you teach it." While the saying is not always true, there are some things you need to teach in order to learn well. When I was learning iOS development, I was fortunate to get the experience to teach other Udacity students. As they learned from me, I also learned many thingsfrom them. This article showcases five of these previously overlooked concepts that I learned thanks to the help of other students.

1. Completion Handler Pattern

When I first learned about making network requests, it became clear early on that keeping networking code inside the view controller was not ideal. It was not only unorganized and unmaintainable, but violated the basic tenets of MVC architecture. When dealing with multiple network requests, abstracting this code to a separate class is a must.

Doing so introduces a problem: how can the networking code communicate with the view controller? While quite laughable looking back, my inexperienced mind found the perfect solution: NSNotificationCenter.

It actually worked quite well at keeping the view controllers small and separate from the networking code, but there was no real way to pass multiple values (data, response codes, error messages) back to the view controller. It was only when I started teaching other students that I saw prevalent use closures to implement the completion handler pattern. This approach was far more elegant than NSNotificationCenter and made network requests much more straightforward. Since then, I've used the completion handle pattern in all my networking code and have gotten the opportunity to explain its advantages to countless students. It can be a difficult concept to learn and beginners may not immediately see the purpose, but mastering it has proved very useful.

2. The Singleton Pattern

Like completion handlers, singletons are another one of those "tricks" that can be befuddling to beginners. While virtually every iOS developer has experience working with the AppDelegate or NSUserDefaults, the idea of creating your own singleton class may not seem intuitive. They can be used for a variety of purposes, but data storage and networking classes are the most common. It was reviewing students' networking code in particular where I first saw use of the singleton. Although many consider it to be an "anti pattern", its widespread usage in Apple's own code earns the singleton a mention here, and it's something any intermediate developer should be aware of.

3. Making Collection Views Look Pretty

If you've ever had to display multiple images in a grid format, you've probably been using a collection view. Setting one up is simple: all you need is to create a subclass of UICollectionViewController, create a cell, implement the data source, and you're done. While the images should now be displayed, the implementation is not quite complete. Just try running the app on different simulators and you'll notice that that the spacing can vary considerably.

Not only is the spacing off, but we have no control over the cell size.
This is not the perfect grid seen in the built-in Photos app, but it turns out that Apple lets us do the same thing with UICollectionViewFlowLayout. I overlooked flow layouts when learning about collection views, but once again, it was fellow students who exposed me to this UX lifesaver.

Much better. The cell size and spacing is under control.
4. Xcode Time Profiler

While discussing with a student the pros and cons of different algorithms for a certain task (because that's what us nerds do), we inevitably got onto the topic of Big-O and algorithm running time. After I explained how one approach had a better best-case scenario, he mentioned there was run-time testing within Xcode. It doesn't appear to actually determine the Big-O time, but it does provide a lot of useful metrics.

It's definitely something to cover in a full-length tutorial in the future, but for now, you can feast your eyes on the glory. Looks fancy, eh?
A screenshot of Xcode's Time Profiler
5. The System Isn't Always Right

For continuity, Udacity project reviewers can communicate with each other to discuss best practices and recommendations. Early on, another reviewer's suggestion stood out as especially useful. According to them, custom keyboards can sometimes incorrectly report the UIKeyboardWillShowNotification, causing the callback to be invoked multiple times. For this reason, they discouraged usage of the += operator to adjust a view's coordinates, since doing so would cause the view to move further than intended.

In the vast reaches of the iOS SDK, this bug may not sound significant, but it can potentially wreak havoc on one's app if left unhandled by the programmer. I now point it out to any student who moves views in this way, so they can not only be aware of this particular bug, but the reality that even Apple's code isn't perfect, and sometimes us developers need to find workarounds.


That wraps up the 5 things Udacity students taught me about iOSdevelopment. It's just a sampling of the most significant topics, but each one was a great learning experience, both as the teacher and the student. On an added note, if you're learning iOS development and are interested in these topics, they're certainly worth further research. I wouldn't want anyone using NSNotifications as a substitute for completion handlers.


  1. Thanks for the nice blog. It was very useful for me. I'm happy I found this blog. Thank you for sharing with us,I too always learn something new from your post. WhatsApp Plus Latest APK Download

  2. Yes i am totally agreed with this article and i just want say that this article is very nice and very informative article.I will make sure to be reading your blog more. You made a good point but I can't help but wonder, what about the other side? !!!!!!THANKS!!!!!! Action Link Wireless

  3. Absolutely fantastic posting! Lots of useful information and inspiration, both of which we all need!Relay appreciate your work. iOS 11.3.1

  4. Thanks for the nice blog. It was very useful for me. I'm happy I found this blog. Thank you for sharing with us,I too always learn something new from your post. iphone screen recorder

  5. The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface. ipad cases manufacturer

  6. They would feel one step smarter to other readers because they have grasped new information that probably has not yet been read about. YL Amazon Appeal The design of a website is another important factor when it comes to improving the conversion rate of an e-commerce website.

  7. you help me a lot for posting such a useful information thank.
    Increase Amazon Sales

  8. The article was up to the point and described the information very effectively. Thanks to blog author for sharing an informative post. iphone app development denver

  9. I really want to thank the author for such a nice blog that helped me to understand why it is important. nidhi software

  10. I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. website development Melbourne

  11. Wow this is amazing blog and i am very happy to read your blog. for more information visit our website. SEO Service Company

  12. I'm really inspired together with your writing skills and also with the layout for your weblog. Thanks for sharing this blog here. Android App Developer Company Dubai

  13. This is excellent information which is shared by you. This information is meaningful and magnificent for us to increase our knowledge about it. Keep sharing this kind of information. Thank you. Read more info about Microsoft 365 Power Automate