Duc Ninja

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 ...

Customizing the file Header comment and text macros

Text macros Text macros are symbols that are expanded in-place to the specified text. They are used in files and other places in Xcode, such as the header text for a new file or the project name. You can customize existing macros and add your own macros in a project, for all users of a project, or for all of Xcode. Customizing a macro requires t...
Read more ...