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).
You might of forgotten to import your Swift Package into AppDelegate
. Try putting the equivalent for your package in the top of AppDelegate
.
import Foo
According to this Github Issue , (if you're using CocoaPods, which you haven't stated in your question.) You will have to make the class/struct in your package public.
You might also have to try like this:
Foo.bar()
Foo
being your package name, and bar
being the class or struct inside it.
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.
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.