1

I'm trying to build a iOS framework but at the moment I'm trying to import the framework I'm getting this error:

enter image description here

This is implementation of my framework:

public protocol myframeWorkDelegate{
    func doSomething(value:Int)
}
public class myframeWork{
    public var delegate:myframeWorkDelegate? = nil

    public func doingSomething(do:String){

    }
}

Any of you knows why I'm getting this error?

I'll really appreciate your help.

user2924482
  • 8,380
  • 23
  • 89
  • 173

2 Answers2

1

Change the name of your var. The error is because the name of the class is the same as the name of the variable. Additionally, this is why you should always capitalize class names ie class MyFramework versus var myFramework.

Connor Neville
  • 7,291
  • 4
  • 28
  • 44
  • I switch the name of my 'var' to 'var someframeWork = myframeWork()' but now I'm getting this error 'myframeWork initializer is inaccessible due to internal protection level' – user2924482 Oct 16 '17 at 20:47
1

This happens because you named your variable the name of your class. Swift compiler starts using the name of your variable right away, and decides that you are trying to read the value inside its own initializer, as in

var someVariable : String = someVariable

Of course, you are not doing this, so Swift compiler could distinguish between the two uses of myframeWork identifier in the declaration, at least theoretically. However, they decided it is not worth the trouble.

Renaming the variable or the class will fix this problem. You may also need to provide a public initializer for your class in order for the modified code to compile.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523