问题
I have a basic class named APIGroup
that exists for the sole purpose of subclassing (it is not [yet] used for anything but certain static
properties that are accessed by the subclasses). It looks somewhat like this:
public class APIGroup {
public static let someProperty : String = "I am a property!"
}
And I have a subclass, Track
, which defines a type method search
as follows:
public class Track : APIGroup {
public static func search(name: String) -> Void {
print("Track search initiated. Name: \(name)")
print("And the property is: \(someProperty)")
}
}
These two classes are defined in separate files in the same module. In another target, I import the module and try to call:
import MyModule
MyModule.Track.search("testing...")
But this throws: Type 'Track' has no member 'search'
. What am I doing wrong?
回答1:
Putting this code in a Playground works fine for me:
import Foundation
public class APIGroup {
public static let someProperty : String = "I am a property!"
}
public class Track : APIGroup {
public static func search(name: String) -> Void {
print("Track search initiated. Name: \(name)")
print("And the property is: \(someProperty)")
}
}
Track.search("testing...")
If they are in the same module you do not need to import or use the module name.
来源:https://stackoverflow.com/questions/37355179/swift-type-has-no-member