我想使用 OSLog 活动来构建我的日志,但我遇到了 Swift 上缺少所需活动常量的问题,例如OS_ACTIVITY_CURRENT
and OS_ACTIVITY_NONE
,当我尝试创建活动时出现错误:
let activity = _os_activity_create(dso, strdup(name),
OS_ACTIVITY_CURRENT, // Error: Static member 'OS_ACTIVITY_CURRENT' cannot be used on instance of type 'OSLogOutput'
OS_ACTIVITY_FLAG_DEFAULT)
os.activity
框架有没有任何定义的活动常量的描述(但定义了活动标志OS_ACTIVITY_FLAG_DEFAULT
, OS_ACTIVITY_FLAG_DETACHED
, OS_ACTIVITY_FLAG_IF_NONE_PRESENT
):
/*!
* @const OS_ACTIVITY_CURRENT
*
* @discussion
* Create activity and links to the current activity if one is present.
* If no activity is present it is treated as if it is detached.
*/
如果我们查看 ObjC 标头<os/activity.h>
,我们可以找到这些常量:
#define OS_ACTIVITY_NONE OS_OBJECT_GLOBAL_OBJECT(os_activity_t, _os_activity_none)
#define OS_ACTIVITY_CURRENT OS_OBJECT_GLOBAL_OBJECT(os_activity_t, _os_activity_current)
看起来 OSLog 在 Swift 上受到限制,那么如何使用 OSLog 活动或在哪里可以找到常量?