Duc Ninja

Passing Data Using NotificationCenter in Swift 4

Passing data from one view controller to another view controller using Notification Center is an easy way when compared to delegate protocols. Here we need add observer or listeners for getting new data to load. First we need to send data using post notification method. Sending Data - Post Notification: let dataToSend = ["name" : "John", "age...
Read more ...

Save custom objects into UserDefaults(Swift 4)

We have many ways to store and retrieve persistent data in iOS but let try to store a custom object into UserDefaults with Codable in Swift 4. We have a custom object like this: struct User: Codable { var id: String var name: String var age: Int } And now, let define a object: let user = User(id: "abc123", name: "Tim can Cook", ...
Read more ...

Easy XIB and Storyboard Localization

Photo by freestocks.org on Unsplash Localization is a key part of an application. In order to make it easy, maintainable and extensible it deserves a bit of effort and care. But for iOS graphic interfaces made with Interface Builder, it becomes a bit tricky to accomplish those goals. Storyboard localization: what the heck! Say we have a Stor...
Read more ...

Dependency Injection examples with Swift 4

#TIL In software engineering, dependency injection is a technique whereby one object supplies the dependencies of another object. A dependency is an object that can be used (a service). An injection is the passing of a dependency to a dependent object (a client) that would use it. The service is made part of the client’s state.[1] Passing the s...
Read more ...