Dynamic Features in Swift | Ray Wenderlich

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


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5743-dynamic-features-in-swift

Missing code. There is no code about Kennel and Key Value Coding.

1 Like

@finneycanhelp Can you please help with this when you get a chance? Thank you - much appreciated! :]

Great question about where the code is located for the Kennel and Key Value Coding, @azamsharp :]

That code is available in the downloaded code. At the top and near the bottom of this tutorial is a green button titled “Download materials”

Click on that to get the code. In the downloaded code, there are the folders DynamicFeaturesInSwift-Starter and DynamicFeaturesInSwift-Final folders. Each folder contains a DynamicFeaturesInSwift.playground.

In the DynamicFeaturesInSwift-Final folder, open the DynamicFeaturesInSwift.playground in Xcode. The DynamicFeaturesInSwift.playground has a page called KennelsKeyPath.

To see this Playground page in Xcode, show the Project Navigator by choosing View â–¸ Navigators â–¸ Show Project Navigator and then you can see the KennelsKeyPath page. Click on the KennelsKeyPath page and there you can see the Key Path \Kennels.available stored in the variable keyPath. kennels is then set up to have changes observed to it using the keyPath and the observe method.

Thanks for asking and I hope that helps!

Thank you for this tutorial. I have one major question and i can’t seem to find really good answer for it at the moment. Seeing this tutorial is marked “iOS” as well, here is my problem:
How do i run Python code in my iOS app using dynamicMemberLookup?
I see how it works when you have Python installed in your operating system, but afaic, there is no Python interpreter in iOS out of the gate.

@finneycanhelp Can you please help with this when you get a chance? Thank you - much appreciated! :]

Thanks for the excellent question! It’s true that there is not a Python interpreter in iOS out of the gate, as you said. Getting Python to run on iOS is an interesting challenge by itself.

There are solutions out there for running Python on iOS. However, that doesn’t get us all the way. Although I could be wrong, I don’t believe Swift 4.2 interacting with Python on an iOS device is yet in existence.

Although dynamicMemberLookup offers great support for interoperability between Swift and Python, other pieces have to fall into place to make it all happen on iOS. One of them is a strong interest in the effort.

For example, interest in Swift / Python interoperability has been driven by Chris Lattner due to the energy around TensorFlow, an open-source software library used for machine learning.

However, that doesn’t get us what we want on an iOS device yet either. The emphasis there is on the server side as opposed to the client iOS devices.

Digging into StackOverflow reveals that at least one person had installed a Pythonista template on their iPhone and it satisfied their Swift / Python needs. Given other scraps of information I could glean from the Internet, I don’t believe Pythonista currently supports Swift 4.2.

So, we’re not quite there yet when it comes to Swift and Python working together on iOS. Until then server side Swift / Python interoperability will continue to grow. At least an iOS device can reach out to the server for whatever information it needs. That might fulfill whatever needs one has.

I hope this answers your question. Thank you for asking it. :]

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!