Duc Ninja

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

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