Posts

MVVM in iOS

Image
MVVM in iOS Related: View Model Validation in iOS View Model and Networking Udemy Course — Mastering MVVM for iOS Lately there has been a lot of talk about MVVM in iOS applications and how it can help to tame the symptoms of massive view controllers. The default architecture pattern for building iOS applications is MVC (Model View Controller) and although there is nothing wrong with MVC pattern, but most of the time view controller becomes the point of code dumping ground. MVVM is not something new that just popped out of nowhere, it has been used for several years specially in the .NET community. I have worked on many large scale WPF (Windows Presentation Foundation) applications where MVVM was used successfully. Having said that comparing .NET WPF framework to iOS framework is not fair because WPF uses XAML and the power of “ Dependency Properties ” to perform two way seamless binding. In iOS we don’t have anything similar to dependency propert...

iOS swift — setNeedsLayout vs layoutIfNeeded vs layoutSubviews()

iOS swift — setNeedsLayout vs layoutIfNeeded vs layoutSubviews() I always wondered about these methods while coding in iOS. I tried to read more and this is what I understood. When an iOS app launches,  UIApplication  in iOS starts the main run loop for an app, which runs on the main thread. The main run loop processes events (such as user touches) and handles updates to view-based interfaces. As events occur, such as touch, location updates, motion, and multimedia control, the run loop finds the appropriate handler for the events, calling appropriate methods, which call other methods, and so on. At some moment in time, all events will have been handled and control will return to the run loop. Let’s label this point where control is returned to the run loop as the  update cycle. While the events are being processed, and some changes are requested to the view, these changes are not updated immediately. Instead the system wait for the existing process to finish ...

CoreData With Concurrency: Swift

Image
1.   CREATE & INSERT : Core Data Using CoreData with background queues is very important to avoid blocking the main one with heavy computations. For this reason, we should use concurrency most of the time. In this article we are going to see how to save some objects with CoreData in a background queue. CoreData received a major update with iOS 10. For this reason, in this series, I’ll explain how to achieve our goals in both pre and post iOS 10. Happy Reading! Contents Getting Started iOS 8+ iOS 10+ Getting Started Before starting our journey, we have to create a data model—which we will use for all the further examples. We can use a data model with just an entity  Dog  with a String attribute  name —I know you wanted  Cat . Not today, I prefer dogs  iOS 8+ If we want to be compatible with versions older than iOS 10, the first thing which we should do is creating the CoreData stack manually: 1 2 3 4 5 6 ...