如何在混合Xcode项目中使用XCGLogger(Objective-C和Swift)

时间:2015-11-16 13:14:24

标签: ios objective-c xcode swift xcglogger

我有一个混合的Xcode项目。我的appDelegate用Objective-C编写,我的Controller部分用Swift编写。 是否可以在该项目中使用XCGLogger?如果是,我如何在appDelegate中初始化XCGLogger(例如- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions)?

1 个答案:

答案 0 :(得分:0)

我也找到了同样的问题,想将其合并到Swift + Objective-C混合项目中。幸运的是,我发现此PR https://github.com/DaveWoodCom/XCGLogger/pull/122可为您提供解决方案。

但是为了进行check out his PR,我们需要进行一些更改:

@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) {}

注意省略level标签参数。

===

说明:

因此来自XCGLogWrapper的静态函数:

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

将在Objective-C中翻译为:

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

===

要获得更完整的答案,请查看我对PR https://github.com/DaveWoodCom/XCGLogger/pull/122#issuecomment-468136786的评论

希望有帮助!