如何在默认情况下公开的成员明智的初始化结构在Swift?

我有一个swift框架定义一个结构:
public struct CollectionTO {
    var index: Order
    var title: String
    var description: String
}

但是,我似乎不能使用隐式成员明智的初始化从另一个项目,导入库。错误是’CollectionTO’不能初始化,因为它没有可访问的初始化。即它不给认隐式成员明智的初始化公共关键字。

var collection1 = CollectionTO(index: 1,title: "New Releases",description: "All the new releases")

我必须添加我自己的init方法,如:

public struct CollectionTO {
    var index: Order
    var title: String
    var description: String

    public init(index: Order,title: String,description: String) {
        self.index = index;
        self.title = title;
        self.description = description;
    }

}

…但我宁愿不是有另一种方式任何人都知道吗?

我阅读手册:

“Default Memberwise Initializers for Structure Types
The default memberwise initializer for a structure type is considered private if any of the structure’s stored properties are private. Otherwise,the initializer has an access level of internal.

As with the default initializer above,if you want a public structure type to be initializable with a memberwise initializer when used in another module,you must provide a public memberwise initializer yourself as part of the type’s deFinition.”

摘录自“The Swift Programming Language”,第“Access Control”节。

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...