Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class extension inside a playground

I have a UIVIew subclass in my playground sources folder (its a Public class) and I'm trying to only put a portion of this class into my main playground file as an extension.

When I declare the following in my playground

public extension SortingAlgorithmView {

    public func typeTest() {
        print("dfasfndjasfasfdasfdasf test ")
    }
}

and then inside my subclass I call typeTest() it tells me there is no function with the name typeTest.

like image 520
LoganHenderson Avatar asked Mar 10 '23 12:03

LoganHenderson


1 Answers

The interactive pages do not run alongside the source files; the source files are compiled first and then imported into your playground pages (which is why you need to make everything public). This makes them much faster since they can be compiled just once instead of interpreted every time, but it also means they cannot reference the code in the playground pages.

If you want to access the extension from the source files, you'll have to put it in a source file. The source files cannot access the interactive content.

like image 127
NobodyNada Avatar answered Mar 27 '23 20:03

NobodyNada