swiftswift-package-managerswiftpm

Files in Swift Package out of scope


I created a basic project with a swift package(let's call it "Foo") related to this project.

I tried printing "hello world" from Foo().text from AppDelegate and I get an error:

"Cannot call value of non-function type 'module<Foo>' "

I then tried to add a new struct or class to this package and I get an error: "Cannot find {ObjectName} in scope" Tests inside Foo all passed. It looks like I missing some step(s).


Solution

  • Don't confuse a module with a public class (or struct). That's what it sounds like you are doing here:

    I create a basic project with a swift package (let's call it "Foo") related to this project and try print "hello world" from Foo().text

    Saying Foo() implies there is a public class/struct called Foo. Is there? I don't think so. You might have a package called Foo, which you import. But that does not mean that the Foo package has a public class (or struct) called Foo.

    For example you might see this in your package:

    struct Foo {
        var text = "Hello, World!"
    }
    

    But that does not mean you can simply import Foo and then talk about Foo().text, because this Foo is not public.