我在一个名为“MyFramework”的框架中有一个结构
public struct ShipmentPackage:Encodable {
let package_code:String
let weight:Float
}
然后当我尝试在另一个项目/框架中创建一个 ShipmentPackage
import MyFramework
let onePackage = ShipmentPackage(package_code:"BX",weight:100)
我收到一条错误消息“ShipmentPackage”初始化程序由于“内部”保护级别而无法访问我来到此链接https://forums.swift.org/t/public-struct-init-is-unexpectedly-internal/5028
我试图将我的代码更改为以下内容:
第一次尝试:
public struct ShipmentPackage:Encodable {
let package_code:String
let weight:Float
public init(package_code:String,weight:Float){
self.package_code = package_code
self.weight = weight
}
}
第二次尝试:
public struct ShipmentPackage:Encodable {
public let package_code:String
public let weight:Float
public init(package_code:String,weight:Float){
self.package_code = package_code
self.weight = weight
}
}
我也尝试将 package_code 和 weight 更改为 public,但以上都不起作用,编译时出现错误消息
<unknown>:0: error: 'init' is inaccessible due to 'internal' protection level
<unknown>:0: note: 'init' declared here
<unknown>:0: error: 'init' is inaccessible due to 'internal' protection level
任何提示将不胜感激!