Theo Strauss
Theo Strauss

Reputation: 1351

Access struct through class instance

In a class I created I have a struct called Image:

public struct Image {


 private(set) var url: String
 private(set) var crop: CGRect

    init(url: String, crop: CGRect) {
        self.url = url
        self.crop = crop
    }
}

I also have a function that usesImage as a parameter.

public func detectBoxes(image: Image) {
    //some code
}

What I want to do is access Image in another file to use it in a function. So, I create an instance of the class and try typing

instance.detectBoxes(image: ...)

BUT it won't let me create an instance of Image so I can use it, it just wants me to type Class.Image which doesn't make sense.

Does anyone know how to solve my issue? Any help would be much appreciated. Cheers, Theo

Upvotes: 0

Views: 271

Answers (1)

Shai Balassiano
Shai Balassiano

Reputation: 1007

You defined a nested struct inside of a class, meaning it's available from within the class context.

If you wish to just use an instance of type Image and not <ClassName>.Image you must move the declaration of the struct out side the scope of the class.

Upvotes: 1

Related Questions