public struct in framework init is inaccessible due to 'internal' protection level in compiler
Lesson learned: all public struct need a public init
That's not quite exact. The documentation states:
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. Likewise, if any of the structure’s stored properties are file private, the initializer is file private. Otherwise, the initializer has an access level of internal.
So the build-in memberwise initializer is only available within the package. If you don't provide a public initializer, you won't be able to create your struct from outer space.
public struct YourFrameworkStruct {
let frameworkStructProperty: String!
/// Your public structs in your framework need a public init.
///
/// Don't forget to add your let properties initial values too.
public init(frameworkStructProperty: String) {
self.frameworkStructProperty = frameworkStructProperty
}
}
Thanks for all the comments, I finally figured out why it's giving me error. Both my 2 attempts should be fine.
And it turned out this struct wasn't causing issues
I have other struct use this struct and marked public, for example
public struct Shipment:Encodable {
let carrier_code:String
let packages:[ShipmentPackage]
}
was missing initializer, but for whatever reason XCode won't indicate the error for my workspace, but giving out error at compile time.
after giving an initializer to all public structs, the app pass the compiler.
public struct Shipment:Encodable {
let carrier_code:String
let packages:[ShipmentPackage]
public init(carrier_code:String,packages:[ShipmentPackage]){
self.carrier_code = carrier_code
self.packages = packages
}
}
My original post wasn't really good, since there was nothing wrong with the code I posted, but decide to not delete this post, it might help newbies like me in future
Lesson learned: all public struct need a public init