我有一个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")
- 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.”