2

I have a mixed Xcode project. My appDelegate is written in Objective-C and my Controller partly in Swift. Is it possible to use XCGLogger in that project? If yes, how can I initialized the XCGLogger in the appDelegate (e.g. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions)?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Morpheus78
  • 870
  • 1
  • 9
  • 21

1 Answers1

0

I found and had the same issue too, wanting to incorporate in a mixed Swift+Objective-C project. Fortunately, I found this PR https://github.com/DaveWoodCom/XCGLogger/pull/122 that helps with a solution.

But in order to check out his PR we need to make some change:

@objc public class XCGLogWrapper: NSObject {
    @objc public static func log(_ level: LogLevel = LogLevel.debug, functionName: String = #function, fileName: String = #file, lineNumber: Int = #line, logMessage: String) {}

notice the omission of level label argument.

===

Explanation:

so from this static function of XCGLogWrapper:

static XCGLogWrapper.log(_:functionName:fileName:lineNumber:logMessage:)

will be translated to this in Objective-C:

[XCGLogWrapper log:level functionName: @(__PRETTY_FUNCTION__) fileName: @__FILE__ lineNumber: __LINE__ logMessage: message ]

===

For more complete answer, check my comment on the PR https://github.com/DaveWoodCom/XCGLogger/pull/122#issuecomment-468136786

Hope it helps!

Vinh Nguyen
  • 816
  • 1
  • 13
  • 27