Tuesday, March 7, 2017

Pass Data with NSNotification between ViewControllers in Swift 3

This article was originally published at iOS Geek Community.

Today, let’s talk about how and why we use NSNotification to pass data and communicate/notify between classes and structs. By the way, NSNotification, unlike its name, has nothing to do with Push Notification — rookie mistake 101 (me).

Yes, there are many ways to pass data in Swift: Delegate, Key-Value Observing, Segue, and NSNotification, Target-Action, Callbacks. However, each one has its own pros and cons. They are like dining utensils. For example, I wouldn’t use chopsticks — although it’s pretty darn good — to drink soup.

Since there are many, I’m only going to cover one at a time, and I will going to mention why you should spoons instead of chopsticks along the way. It doesn’t make sense to tell the differences between chopsticks and knives before I have used both.

Continue reading %Pass Data with NSNotification between ViewControllers in Swift 3%


by Bob Lee via SitePoint

No comments:

Post a Comment