小编Ess*_*dad的帖子

使用swift记录方法签名

我正在尝试重写我的日志类,我想知道如何在swift文件中替换PRETTY_FUNCTION或NSStringFromSelector(_cmd)以跟踪方法调用?

cmd ios swift ios8

49
推荐指数
5
解决办法
3万
查看次数

什么是Swift预处理器相当于iOS版本检查比较?

我正进入(状态

yld: Symbol not found: _OBJC_CLASS_$_UIUserNotificationSettings
Run Code Online (Sandbox Code Playgroud)

这是当应用程序在iOS7设备上运行时甚至根本没有在代码中调用该函数导致错误的函数.

func reigsterForRemoteUserNotifications(notificationTypes: UIUserNotificationType, categories: NSSet) {
        let userNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: categories)
        (UIApplication.sharedApplication()).registerUserNotificationSettings(userNotificationSettings)
        UIApplication.sharedApplication().registerForRemoteNotifications()
    }
Run Code Online (Sandbox Code Playgroud)

我不希望在iOS7设备上运行时可以访问此方法.我不希望在其中进行选择检查,因为这意味着该方法可用于开始.

我想要的是一个构建配置参数来检查版本:我无法找到一种方法来编写一个快速等效的预处理器宏来检查正确的iOS版本并忽略新的和未声明的iOS 8库函数.

#if giOS8OrGreater
// declare the functions that are iOS 8 specific
#else 
// declare the functions that are iOS 7 specific

#endif
Run Code Online (Sandbox Code Playgroud)

在文档中,apple建议使用函数和泛型来替换复杂的宏,但在这种情况下,我需要构建配置预编译检查以避免处理未声明的函数.有什么建议.

macros ios swift

18
推荐指数
3
解决办法
1万
查看次数

标签 统计

ios ×2

swift ×2

cmd ×1

ios8 ×1

macros ×1