简体   繁体   English

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

[英]How can I use XCGLogger in a mixed Xcode project (Objective-C and Swift)

I have a mixed Xcode project. 我有一个混合的Xcode项目。 My appDelegate is written in Objective-C and my Controller partly in Swift. 我的appDelegate是用Objective-C编写的,而我的控制器则是用Swift编写的。 Is it possible to use XCGLogger in that project? 可以在该项目中使用XCGLogger吗? If yes, how can I initialized the XCGLogger in the appDelegate (eg - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions )? 如果是,如何在appDelegate中初始化XCGLogger(例如- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions )?

I found and had the same issue too, wanting to incorporate in a mixed Swift+Objective-C project. 我也发现了同样的问题,想将其合并到Swift + Objective-C混合项目中。 Fortunately, I found this PR https://github.com/DaveWoodCom/XCGLogger/pull/122 that helps with a solution. 幸运的是,我发现了此PR https://github.com/DaveWoodCom/XCGLogger/pull/122 ,它有助于解决问题。

But in order to check out his PR we need to make some change: 但是要检查他的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) {}

notice the omission of level label argument. 注意省略了level标签参数。

=== ===

Explanation: 说明:

so from this static function of XCGLogWrapper : 因此,从XCGLogWrapper此静态函数XCGLogWrapper

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

will be translated to this in Objective-C: 将在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 有关更完整的答案,请查看我对PR的评论https://github.com/DaveWoodCom/XCGLogger/pull/122#issuecomment-468136786

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我应该在混合的Objective-C / Swift项目中使用Realm Objective-C或Realm Swift吗? - Should I use Realm Objective-C or Realm Swift in my mixed Objective-C / Swift project? Xcode 8与混合Swift和Objective-c项目生成的“ModuleName-Swift.h”标头未找到 - Xcode 8 with mixed Swift and Objective-c project generated “ModuleName-Swift.h” header not found 如何在Xcode Objective-C项目中的.mm类扩展中导入/使用快速静态库/框架 - How to import/use swift static library/framework in to .mm class extension in Xcode Objective-C Project 如何在Xcode项目中集成和使用Font Awesome与Objective-C或Swift? - How to integrate and use Font Awesome with Objective-C or Swift in an Xcode project? 混合Objective-C项目中的Swift“命名空间”无法正常工作 - Swift “namespaces” in mixed objective-c project not working 如何在 Swift 项目中使用 Objective-C 桥接头 - How to use Objective-C bridging header in a Swift project 如何在objective-c项目中使用swift类别? - How to use swift categories in objective-c project? Objective-C桥接问题。 如何在Swift项目中使用Obj-C框架? - Objective-C bridging issue. How do I use an Obj-C framework in a Swift project? 如何在Objective-C和Swift项目中使用RxSwift? - How to use RxSwift for Objective-C and Swift project? 如何在快速项目中使用Objective-C类合作伙伴 - how to use objective-c category cocoapods in swift project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM