Dynamic Features in Swift

In this tutorial, you’ll learn to use dynamic features in Swift to write clean code, create code clarity and resolve unforeseen issues quickly. By Mike Finney.

Leave a rating/review
Download materials
Save for later
Share
You are currently viewing page 4 of 4 of this article. Click here to view the first page.

Where to Go From Here?

You can download the completed version of the project using the Download Materials button at the top or bottom of this tutorial.

In this tutorial, you harnessed the dynamic power that Swift offers in version 4.2. You learned about Swift’s introspective reflection powers such as Mirror, customizing console output, hooking into Key-Value Observing with KeyPaths and Dynamic Member Lookup.

With that dynamic smorgasbord, you can clearly see helpful information, have more readable code and hook into some powerful runtime capabilities for your app or general purpose framework and library.

Sniffing around Apple’s documentation about Mirror and related items is a worthy endeavor. For more about Key-Value Observing, have a look at Design Patterns on iOS using Swift. Be sure to check out the What’s New in Swift 4.2? to see more of what’s in Swift 4.2.

In regards to the Dynamic Member Lookup Swift 4.2 feature, it doesn’t hurt to look at the Swift proposal SE-0195: “Introduce User-defined ‘Dynamic Member Lookup’ Types” that introduces the dynamicMemberLookup type attribute and potential use cases. On a related note, a Swift proposal to keep an eye on is the close cousin of Dynamic Member Lookup called SE-216: “Introduce User-defined Dynamically ‘callable’ Types that introduces the dynamicCallable type attribute.

Have more to say or ask about the dynamic power of Swift? Join in on the forum discussion below!

Mike Finney

Contributors

Mike Finney

Author

Jayven Nhan

Tech Editor

Vladyslav Mytskaniuk

Illustrator

Morten Faarkrog

Final Pass Editor

Richard Critz

Team Lead

Over 300 content creators. Join our team.