Giter VIP home page Giter VIP logo

Comments (2)

aheze avatar aheze commented on August 25, 2024

Ah yeah. So what happens is that when you make a Swift Package or framework, you need to implement your own init() method. The default memberwise struct init isn't available — see this Stack Overflow question.

Thankfully, Xcode has a "Generate Memberwise Initializer" feature that auto-generates the default memberwise initializer. I've been using this, which is why you see the same values duplicated.

Generate Memberwise Initializer

from setting.

cedricbahirwe avatar cedricbahirwe commented on August 25, 2024

Yes, I'm aware of that Xcode generation feature, if we have the same values in the initializers, would it make sense to remove the default values of the properties and only keep the ones in the memberwise initializers?

For example, someone (I don't know who), might be tempted to update the property value directly instead of updating the default argument value from the initializer.

What I have in my mind is :

public struct PreviewConfiguration {
    public var icon: SettingIcon?
    public var indicator: String
    public var horizontalSpacing: CGFloat
    public var verticalPadding: CGFloat
    public var horizontalPadding: CGFloat

    public init(
        icon: SettingIcon? = nil,
        indicator: String = "chevron.forward",
        horizontalSpacing: CGFloat = CGFloat(12),
        verticalPadding: CGFloat = CGFloat(14),
        horizontalPadding: CGFloat = CGFloat(16)
    ) {
        self.icon = icon
        self.indicator = indicator
        self.horizontalSpacing = horizontalSpacing
        self.verticalPadding = verticalPadding
        self.horizontalPadding = horizontalPadding
    }
}

from setting.

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.