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”节。
总结以上是内存溢出为你收集整理的如何在默认情况下公开的成员明智的初始化结构在Swift?全部内容,希望文章能够帮你解决如何在默认情况下公开的成员明智的初始化结构在Swift?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)