I have been using XCGLogger for a while now, but after converting my app to swift 3.0, I am having issues with it in my test target.
I have the following as part of my AppDelegate class file. This creates a global variable log
which I can use anywhere in my app by just calling log?.info("foo")
for example.
Prior to moving to swift 3 this worked in test target as well, but now I get a link error if I try to use log?.info("foo")
in my test target.
AppDelegate code
import XCGLogger
// USE_XCGLOGGER is set for debug but not for release
#if USE_XCGLOGGER
let log: XCGLogger? = {
// Setup XCGLogger
let log = XCGLogger.default
return log
}()
#else
let log: XCGLogger? = nil
#endif
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
...
}
Class in test target
import XCTest
@testable import OurLatitude
class ApiAccessTests: XCTestCase {
override func tearDown() {
super.tearDown()
log?.info("foo")
}
}
Link errors
undefined symbols for architecture x86_64:
"XCGLogger.XCGLogger.(info (@autoclosure () -> Any?, functionName : Swift.StaticString, fileName : Swift.StaticString, lineNumber : Swift.Int, userInfo : [Swift.String : Any]) -> ()).(default argument 4)", referenced from:
OurLatitudeTests.ApiAccessTests.tearDown () -> () in ApiAccessTests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)