[SOLVED] Can i create a an iOS framework conforming to an inside protocol and also define the same protocol in my project?

Issue

i’m creating a framework the conforms to a certain protocol

MyTestFramework.framework

public protocol SBFProtocol {

    static var sharedInstance: SBFProtocol { get }
    func GetVersion() -> String
    func GetBuildNumber() -> String
}
public final class FrameworkBase : SBFProtocol {

   public static var sharedInstance: SBFProtocol = FrameworkBase()


   public func GetVersion() -> String {
       return "1.0"
   }

   public func GetBuildNumber() -> String {
       return "0"
   }
}

Then i redefine that same protocol in my class and i import the framework.

MyProject

import MyTestFramework

public protocol SBFProtocol {

    static var sharedInstance: SBFProtocol { get }
    func GetVersion() -> String
    func GetBuildNumber() -> String
}

var testInstance: SBFProtocol = MyTestFramework.FrameworkBase.sharedInstance

Is there a way to access that framework obj with my own protocol definition ?

i keep getting the error:

Value of type ‘MyTestFramework.SBFProtocol’ does not conform to specified type ‘MyProject.SBFProtocol’

Is there any way to do this?
the reason is i want to pass that framework instance to yet another framework (call it annonymousFramework) and i want it to know only the SBFProtocol and not the entire MyTestFramework

is that in any way possible?

Solution

Eventually i solved it this way:

i’ve wrapped the protocol inside it’s own framework project (Containing only one protocol.swift file with all the definitions in it)

And then i included that protocol.framework inside all the projects/frameworks that are using it.

This way the compiler recognises it as the same protocol and another benefit i get from this is that i can enforce a minimum iOS version, valid build architectures and more project setting within my protocol/framework hybrid.

Answered By – Boaz Saragossi

Answer Checked By – Willingham (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.