Tag: iphone privateapi

在Swift中向C函数表示NULL函数指针

考虑一下私有但尚未记录的Cocoa C函数_NSLogCStringFunction()和_NSSetLogCStringFunction() 。 _NSLogCStringFunction()返回一个函数指针,指向NSLog()幕后的Objective-C运行时使用的C函数, _NSSetLogCStringFunction()允许开发人员指定自己的C函数进行日志记录。 有关这两个函数的更多信息可以在此Stack Overflow问题和此WebObjects支持文章中找到 。 在C中,我可以传入NULL函数指针到_NSSetLogCStringFunction() : extern void _NSSetLogCStringFunction(void(*)(const char*, unsigned, BOOL)); _NSSetLogCStringFunction(NULL); // valid 但是,当我尝试在纯Swift中执行此操作时,我遇到了一些问题: /// Represents the C function signature used under-the-hood by NSLog typealias NSLogCStringFunc = (UnsafePointer, UInt32, Bool) -> Void /// Sets the C function used by NSLog @_silgen_name(“_NSSetLogCStringFunction”) func _NSSetLogCStringFunction(_: NSLogCStringFunc) -> Void _NSSetLogCStringFunction(nil) // Error: […]