简体   繁体   中英

Swift: Creating iOS framework and importing the framework error : Variable used within its own initial value

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

在此处输入图片说明

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.

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM