Coder Social home page Coder Social logo

Comments (1)

srdanrasic avatar srdanrasic commented on August 23, 2024

Hi @rvangraan,

You should be able to do that yourself with extensions, like this:

protocol DynamicProtocol {}
extension Dynamic: DynamicProtocol {}

Then you can declare an array of Dynamics of any generic type:

var dynamicValues = [DynamicProtocol]()

dynamicValues.append(Dynamic<Int>(0))
dynamicValues.append(Dynamic<String>("hi"))

That being said, for whatever reason you might need this, I'm not sure it's good approach. First of all, type information will be lost, so you'll need to cast to right type before binding:

(dynamicValues[1] as! Dynamic<String>) ->> nameLabel

Additionally, if you replace a dynamic element in the array, the binding will be lost. For example, if you do:

dynamicValues[1] = Dynamic<String>("Tim")

Then updating that new dynamic would not propagate to name label because that new Dynamic is not bound to it.

I'd strongly recommend against doing all this.

Thanks

PS You should always declare your Dynamics as constants, using let keyword:

private let dynDescription = Dynamic(description)
private let dynNetAmount = Dynamic(Money())
private let dynVatAmount = Dynamic(Money())

from bond.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.