I am working on a Swift framework which has majority of Swift files and very few Objective C files. Since I don't want my Objective-C files to be available outside the SDK and not even under headers folder, I gave them project access and now use them internally with a module map.
Here is how my modulemap file looks like:
module MySDKPrivate {
header "CardDetails.h"
export *
}
Now, in order to access this CardDetails file, I just need to import MySDKPrivate
module in the required Swift class. All good till here.
Now, let's say I have a public
class, named Payment.swift
. This class is responsible for executing SDK operations partially hidden to the user, hence it is under the project
access, so it does not show up in the headers when SDK is distributed.
There are some methods such as authenticate
and getSessionExpireDate
which are accessed by a PaymentDoor.swift
class, which is basically nothing but an extension to Payment
class for partial read & write injection, helping to get the minor info in/out of Payment
class. Here is the sample signature of PaymentDoor.swift
//Extension to inject data in and out of the Internal Payment.swift
public extension Payment{
}
And here is the Payment.Swift
class
import MySDKPrivate
public class Payment {
let username: String
let password: String
let cardDetails: CardDetails
public init(userName: String, password: String, cardNumber: String) {
self.username = userName
self.password = password
let cardDetails = CardDetails()
cardDetails.cardNumber = cardNumber
self.cardDetails = cardDetails
}
public func authenticate() -> Bool{
//Some logic
return true
}
private func generateAuthkey(){
//Should not be accessible with the extension
}
}
This is another reason why I want to keep this Payment
class as public
and inside project
access for headers, because If I make it available as public under headers, SDK user would see the name of my modulemap and all the code in Payment class and could use the objective-c files as well with importing the module map. Although now also the name of the module map comes up by Auto Help but at least it's not visible directly.
I still think there could be a better way to inject data in and out of a public class which hides my module name OR Hiding Objective-C files could be done in a better way may be. If yes, please help !
internal
the parts of the class you don't want exposed outside the sdk? – Ken