标签: core-foundation

确定CFTypeRef是什么?

我有一个返回CFTypeRef的函数.我不知道它究竟是什么.我该如何确定?例如,它可能是CFStringRef.

objective-c core-foundation

9
推荐指数
2
解决办法
7988
查看次数

在GCD串行队列上安排和使NSTimers无效是否安全?

这样做的正确方法是什么?该NSTimer文件说,这样的:

特别注意事项

您必须从安装了计时器的线程发送此消息.如果从另一个线程发送此消息,则可能无法从其运行循环中删除与计时器关联的输入源,这可能会阻止线程正常退出.

既然GCD不能保证串行队列总是在同一个线程上运行块,那么确保NSTimer在同一个线程上调度和失效的正确方法是什么?

编辑:

根据以下答案的建议,我创建了MSWeakTimer(https://github.com/mindsnacks/MSWeakTimer),这是一个使用的自定义计时器实现GCD,可以在任何队列中使用.

objective-c core-foundation nstimer grand-central-dispatch ios

9
推荐指数
1
解决办法
2037
查看次数

AVAssetWriterInputPixelBufferAdaptor返回空像素缓冲池

我确定我的缓冲区属性出了问题,但是我不清楚它是什么 - 它没有很好地记录应该去那里的东西,所以我猜是基于CVPixelBufferPoolCreate- 而Core Foundation对我来说几乎是一本封闭的书.

    // "width" and "height" are const ints
    CFNumberRef cfWidth = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &width);
    CFNumberRef cfHeight = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &height);

    CFStringRef keys[] = {
        kCVPixelBufferWidthKey,
        kCVPixelBufferHeightKey,
        kCVPixelBufferCGImageCompatibilityKey
    };
    CFTypeRef values[] = {
        cfWidth,
        cfHeight,
        kCFBooleanTrue
    };
    int numValues = sizeof(keys) / sizeof(keys[0]);

    CFDictionaryRef bufferAttributes = CFDictionaryCreate(kCFAllocatorDefault, 
                                                          (const void **)&keys, 
                                                          (const void **)&values,
                                                          numValues,
                                                          &kCFTypeDictionaryKeyCallBacks,
                                                          &kCFTypeDictionaryValueCallBacks
                                                          );

    AVAssetWriterInputPixelBufferAdaptor *adaptor = [[AVAssetWriterInputPixelBufferAdaptor 
                                                      assetWriterInputPixelBufferAdaptorWithAssetWriterInput:writerInput
                                                      sourcePixelBufferAttributes:(NSDictionary*)bufferAttributes] retain];
    CVPixelBufferPoolRef bufferPool = adaptor.pixelBufferPool;
    NSParameterAssert(bufferPool != NULL); // fails
Run Code Online (Sandbox Code Playgroud)

core-foundation core-video ios avassetwriter

8
推荐指数
1
解决办法
6479
查看次数

使用IOHIDManager获取修饰键事件

我正在尝试使用IOHIDManager获取修饰键事件,因为Cocoa flagsChanged事件缺乏(难以区分按下/释放,左/右如果两者都关闭等)这里是我创建管理器并注册回调的代码.

IOHIDManagerRef hidManager = IOHIDManagerCreate(kCFAllocatorDefault,
        kIOHIDOptionsTypeNone);
if (CFGetTypeID(hidManager) != IOHIDManagerGetTypeID())
    return 1;

CFMutableDictionaryRef capsLock =
    myCreateDeviceMatchingDictionary(0x07, 0x39);
CFMutableDictionaryRef lctrl =
    myCreateDeviceMatchingDictionary(0x07, 0xE0);
CFMutableDictionaryRef lshift =
    myCreateDeviceMatchingDictionary(0x07, 0xE1);
CFMutableDictionaryRef lalt =
    myCreateDeviceMatchingDictionary(0x07, 0xE2);
CFMutableDictionaryRef lsuper =
    myCreateDeviceMatchingDictionary(0x07, 0xE3);
CFMutableDictionaryRef rctrl =
    myCreateDeviceMatchingDictionary(0x07, 0xE4);
CFMutableDictionaryRef rshift =
    myCreateDeviceMatchingDictionary(0x07, 0xE5);
CFMutableDictionaryRef ralt =
    myCreateDeviceMatchingDictionary(0x07, 0xE6);
CFMutableDictionaryRef rsuper =
    myCreateDeviceMatchingDictionary(0x07, 0xE7);

CFMutableDictionaryRef matchesList[] = {
    capsLock,
    lctrl,
    lshift,
    lalt,
    lsuper,
    rctrl,
    rshift,
    ralt,
    rsuper
};
CFArrayRef matches = CFArrayCreate(kCFAllocatorDefault,
        (const void **)matchesList, 9, …
Run Code Online (Sandbox Code Playgroud)

keyboard macos iokit core-foundation

8
推荐指数
2
解决办法
4515
查看次数

NSString与CFString完全相同?

O'Reilly的编程iOS 5说(可能更宽松),"NSString是一个CFString".但至少NSString *会指出一些内存块isa,而CFStringRef不是可能不是吗?

objective-c core-foundation

8
推荐指数
1
解决办法
1955
查看次数

Swift:CGPathRelease和ARC

刚刚更新到Xcode Beta 4,并注意到以下编译器错误,我的代码如下:

var path = CGPathCreateMutable()
...
CGPathRelease(path)
Run Code Online (Sandbox Code Playgroud)

'CGPathRelease'不可用:Core Foundation对象自动进行内存管理

所以,我只是删除我的发布电话,一切都应该没问题?还是有更多我想念的东西?ARC有什么特殊情况需要注意吗?

memory-management core-foundation ios automatic-ref-counting swift

8
推荐指数
1
解决办法
4115
查看次数

Xcode 7 Beta 6,dyld ___NSArray0__崩溃

我第一次能够在Xcode 7中编译我的应用程序(在测试版4和5中失败).所以,我猜这是个好进展.

但是,当我在iPhone 6,iOS 8.4.1上加载我的应用程序时,它在调试器中崩溃并显示以下消息:

dyld:未找到符号:_NSArray0 参考自:/private/var/mobile/Containers/Bundle/Application/0294DF62-AE80-485D-BB11-8C3A5D39777D/Boxtiq.app/Boxtiq预期在:/ System/Library/Frameworks/CoreFoundation. /private/var/mobile/Containers/Bundle/Application/0294DF62-AE80-485D-BB11-8C3A5D39777D/Boxtiq.app/Boxtiq中的框架/ CoreFoundation

这与链接的库的顺序有关吗?期待一些建议.

谢谢!

beta xcode core-foundation ios xcode7-beta6

8
推荐指数
4
解决办法
5917
查看次数

在Linux上桥接到CoreFoundation或从CoreFoundation桥接

我正在尝试在使用CoreFoundation和Foundation的Linux上编译一些代码,但Linux并没有像macOS和iOS那样实​​现桥接.

Objective-C和Swift工作之间的桥梁:

import Foundation
import CoreFoundation
import Glibc

func wantsNSString(_ string: NSString) {
        print(string)
}

let string = "Hello, world!"
wantsNSString(string._bridgeToObjectiveC())
Run Code Online (Sandbox Code Playgroud)

但我无法弄清楚如何桥接到CoreFoundation.我不能只是传递NSString给一个想要一个CFString:

import Foundation
import CoreFoundation
import Glibc

func wantsCFString(_ string: CFString) {
        print(string)
}

let string = "Hello, world!"
wantsCFString(string._bridgeToObjectiveC()) //error: cannot convert value of type 'String._ObjectType' (aka 'NSString') to expected argument type 'CFString'
Run Code Online (Sandbox Code Playgroud)

我不能像在macOS上那样投射它:

import Foundation
import CoreFoundation
import Glibc

func wantsCFString(_ string: CFString) {
        print(string)
}

let string = "Hello, world!"
wantsCFString(string._bridgeToObjectiveC() as …
Run Code Online (Sandbox Code Playgroud)

linux core-foundation foundation toll-free-bridging swift

8
推荐指数
1
解决办法
494
查看次数

为什么Apple之前是typedef引用(指针)类型但现在不是?

我一直想知道为什么Apple在Core Foundation中使用了类型为指针类型的数据类型,而在Cocoa中却没有.

作为一个例子,你会引用一个UIColor对象,就像UIColor *对CGColor对象的引用一样CGColorRef?还是NSURL *CFURLRef?为什么不总是使用CGColor *CFURL *?或者相反,为什么没有UIColorRefNSURLRef类型,因为你从来没有访问UIColorNSURL直接访问?

或者例如,它为什么id而不是id *,因为它实际上是一个指针,实际上可以强制转换为void *

具体来说,是否有一些原因让Apple习惯在旧框架中执行此操作,但是在Cocoa中停止了这样做?这只是风格问题吗?

cocoa macos-carbon objective-c core-foundation

7
推荐指数
1
解决办法
297
查看次数

这些if(0)条件有什么意义?

我发现它是开源的,我正在查看一些CFArray代码,我发现了一些奇怪的代码.这些"空" if (0)条件有什么意义?是否有一些疯狂的好处,或者这只是遗留下来的东西?此代码位于GitHub的CFArray.c的第957行.

if (0) {

} 
else if (NULL == array->_store) {
    if (0) {

    } 
    else if (0 <= futureCnt) {
           // blah blah
    }
}
Run Code Online (Sandbox Code Playgroud)

if-statement objective-c core-foundation

7
推荐指数
1
解决办法
1015
查看次数