Reputation: 961
I'm trying to access the return value from a Type Method in one file from another file. To wit:
file_1:
class LetterView: UIView {
class func testFunction() -> CGSize {
return CGSizeMake(100,200)
}
}
file_2:
class AnotherClass {
func callTestFunction() {
var result = LetterView.testFunction()
print("- breakpoint here - ")
}
}
I get an Unresolved Identifier error on var result
if I put a breakpoint in the debugger and do a po result
. However if I change the return type of testFunction()
to be an Int
(say 2) and return that instead, then the function call works as expected. Color me confused.
Upvotes: 0
Views: 147
Reputation: 521
Is the second file importing UIKit as well? Also, you should update your example from function
to func
. This all works in the playground which leads to UIKit missing.
Upvotes: 1
Reputation: 1567
There could be a few possible issues.
One of the classes has a Testing target and other one doesn't. You have to even include all of your classes in the testing target or none of them.
If it's Objective C class, check that the class is in ObjectiveC bridging header file.
If it's NSManagedObject subclass. Add @objc(className) before the class declaration.
If it's part of a different framework, make sure that the class or function is public
This is the original answer link : Swift Compiler Error: Use of unresolved identifier 'name'
Upvotes: 0