Duc Ninja

What the hell is Swift 4 Access Control?

In object-oriented programming languages, access control is a part of the apparatus of achieving encapsulation, one of four fundamentals of object-oriented programming. The goal is to establish a clear separation between interface (visible and accessible parts of the class) and implementation (internal representation and helper methods). - Wikip...
Read more ...

@objc Warnings Upgrading To Swift 4

Open a Swift 3 project in Xcode 9 and it will warn you that you can upgrade to Swift 4. If you accept the invite you end up with another warning that Swift 4 mode deprecates the Swift 3 @objc inference rules. What is this scary sounding warning and how do you make it go away? What Is @objc Inference? I’ll confess that @objc inference was not s...
Read more ...

Injecting forEach into chained method calls

A few weeks ago a reader pointed out an error in Advanced Swift. We had written this about Swift’s forEach method: And it [forEach] really shines as part of a sequence of chained operations. For instance, imagine you’ve chained several calls to map and filter in a single statement, and during debugging you want to log the intermediate values...
Read more ...

Use didSet during initialling an object in Swift 4

By default didSet of a property don’t called during init, so we can use defer to fix that issue. class VideoPlayerController: UIViewController { enum State { case idle case loading(URL, Data) case playing(Video) } var state = State.idle { didSet { updateVideoView() } } init(state initialSta...
Read more ...

Convert Between UTC and Device Timezone in Swift 4

In this article we are going to convert UTC Date format to Current device date format. UTC is the time standard commonly used across the world. The world’s timing centers have agreed to keep their time scales closely synchronized - or coordinated - therefore the name Coordinated Universal Time. UTC to Local: Use the following method for conve...
Read more ...