- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
尝试设置 XCGLogger 并收到错误:
Ambiguous reference to member 'log'
我看到这个问题已经是raised但我不清楚解决方案..
根据安装指南将这个全局常量添加到 AppDelegate.swift:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let log = XCGLogger.defaultInstance()
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
log.setup(.Debug, showThreadName: true, showLogLevel: true, showFileNames: true, showLineNumbers: true, writeToFile: nil, fileLogLevel: .Debug)
return true
}
然后在各个源文件中:
import XCGLogger
log.debug("A debug message")
什么是正确的用法?
最佳答案
问题很简单。如果您在 AppDelegate
中声明 log
,您将创建一个实例变量。要访问它,您必须将它作为实例变量访问:
(UIApplication.sharedApplication().delegate as! AppDelegate).log.debug("test")
如果你想让 log
在任何地方都可以访问,你必须将它设为一个全局常量:
In your AppDelegate, declare a global constant to the default XCGLogger instance.
let log = XCGLogger.defaultInstance()
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
(不需要在AppDelegate
文件中声明,你基本上可以把它放在代码的任何地方)
或使其静态
:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
static let log = XCGLogger()
并使用以下方式访问它:
AppDelegate.log.debug(...)
为了解释引用不明确,有一个数学函数叫做log
,在malloc.h
中也有一个log
函数文件。由于您将 String
作为第一个参数传递,并且两个函数都不匹配,因此编译器会警告您它不知道您要使用这两个函数中的哪一个。
关于swift - XCGLogger:对成员 'log' 的引用不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36923620/
我在 linux 上工作。我对windows没有太多想法。 windows中文件的权限是如何组织的?我们在unix中是否有像chmod这样的api来更改权限? 最佳答案 对于 Windows,有一个名
应用程序编程接口(interface) (API) 是一组用于访问基于 Web 的软件应用程序的编程指令和标准。 如果出现 ,有人可以向我解释一下吗?谷歌地图 或 优酷 这是API哪个是softwar
我有两个应用程序,A 和 B,它们使用 android 库 C。B 有一个服务 A 想通过 C 使用,例如 在我的库中有一个类试图将它绑定(bind)到服务,
我正在正常或安全模式下启动相机应用程序,具体取决于使用我的应用程序执行的手势,但一旦用户选择应用程序并点击始终,则没有选项可以更改默认值,即使是从 Android 的设置菜单中也是如此. camera
我有一个数据集,本质上是一个稀疏二进制矩阵,表示两个集合的元素之间的关系。例如,让第一组是人(用他们的名字表示),例如像这样的东西: people = set(['john','jane','mike
何为pythonic? pythonic如果翻译成中文的话就是很python。很+名词结构的用法在中国不少,比如:很娘,很国足,很CCTV等等。 我的理解为,很+名词表达了一种特殊和强调的意味。
某些 Prolog 目标的确定性成功问题已经一次又一次地出现在 - 至少 - 以下问题: Reification of term equality/inequality Intersection an
我指的是 DateTime.TryParse(string s, out DateTime result) 重载,它尝试从字符串中解析 DateTime - 没有特定的格式正在指定。 我可以从http
2020 年 04 月 10 日,《中共中央国务院关于构建更加完善的要素市场化配置体制机制的意见》正式公布,将数据确立为五大生产要素(土地、资本、劳动力以及技术)之
有人可以解释一下 NSNotification 的 addObserver 函数中 notificationSender 的用途吗? 这是 Apple 文档的解释: notificationSende
我是一名优秀的程序员,十分优秀!