[英]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.