'init' is inaccessible due to 'internal' protection level

998 Views Asked by At
public class SelectedValue {
    static let sharedInstance = SelectedValue()
    public var reportPostId : Int? = nil
    public var report_GroupId : Int? = nil
    public var postType : String? = nil

}

'init' is inaccessible due to 'internal' protection level Please help me to solve this. Thanks

1

There are 1 best solutions below

3
On

As it says, the init method (that you probably called without it's name) is private. make it more public to access it.

Click on the gray lines that say 'init' declared here to jump to the source of the issue. enter image description here

Note that MyClass() is equal to MyClass.init(). that means you are calling the init method each time you build an object.

And also note that if you don't specify the access level, it will be internal by default.

So this:

class MyClass { }

is equal to:

internal class MyClass {}

So you should change it to:

public MyClass { }