标签: cfstring

如何在OS X目标中创建CFDictionary?

根据文档 CFDictionaryCreate用于实例化CFDictionary swift.

func CFDictionaryCreate(_ allocator: CFAllocator!,
                  _ keys: UnsafeMutablePointer<UnsafePointer<Void>>,
                  _ values: UnsafeMutablePointer<UnsafePointer<Void>>,
                  _ numValues: CFIndex,
                  _ keyCallBacks: UnsafePointer<CFDictionaryKeyCallBacks>,
                  _ valueCallBacks: UnsafePointer<CFDictionaryValueCallBacks>) -> CFDictionary!
Run Code Online (Sandbox Code Playgroud)

我怎样才能创建keysvalues参数?到目前为止,我已尝试使用swift的String类型,希望它会自动转换为适当的类型:

import Foundation

var keys : [String] = ["key1", "key2"]
var values : [String] = ["value1", "value2"]
var keyCallbacks = kCFTypeDictionaryKeyCallBacks
var valueCallbacks = kCFTypeDictionaryValueCallBacks
var dict : CFDictionary = CFDictionaryCreate(kCFAllocatorDefault,
    &keys, &values, 2, &keyCallbacks, &valueCallbacks)
Run Code Online (Sandbox Code Playgroud)

不幸的是我收到一个错误,说String不是keysvalues数组元素的正确类型:

main.swift:41:2: error: 'String' is …
Run Code Online (Sandbox Code Playgroud)

macos core-foundation cfstring swift cfdictionary

4
推荐指数
1
解决办法
3316
查看次数

如何将Unmanaged <CFString>转换为NSString?

我的应用程序正在处理联系人数据.

电话标签检索如下

let locPhoneLabel : NSString = (ABMultiValueCopyLabelAtIndex(phones, numberIndex) != nil) ? ABMultiValueCopyLabelAtIndex(phones, numberIndex).takeUnretainedValue() as CFStringRef : ""

let phoneLabel:Unmanaged<CFString> = ABAddressBookCopyLocalizedLabel(locPhoneLabel)
Run Code Online (Sandbox Code Playgroud)

我不知道如何将phoneLabel转换为NSString?

cfstring ios swift

4
推荐指数
1
解决办法
2264
查看次数

是什么 - [NSURL _fastCharacterContents] :?

所以我在一个方法中调用它:

-(id)initWithContentURL:(NSString *)url {
if (self = [super init]) {
    NSLog(@"xSheetMusicViewController - %@",url);
    // Casting an NSString object pointer to a CFStringRef:
    CFStringRef cfString = (CFStringRef)url;        
    CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), cfString, NULL, NULL);
    pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)

哪一个在NSLog的标记处发生了崩溃:

CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), cfString, NULL, NULL);
Run Code Online (Sandbox Code Playgroud)

我从未见过这个奇妙的小错误.这是崩溃日志:

SheetMuse[83550:b603] -[NSURL _fastCharacterContents]: unrecognized selector sent to instance 0x4ec35f0
2011-09-22 17:36:22.921 SheetMuse[83550:b603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL _fastCharacterContents]: unrecognized selector sent to instance 0x4ec35f0'
*** Call …
Run Code Online (Sandbox Code Playgroud)

init nsstring cfstring ipad ios

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

将 CFStringRef 转换为 QString

跨平台 C++ 头文件。为每个平台创建单独的 C++ 文件:windows、linux、mac。处理枚举窗口的平台特定实现。

在 mac 端:我填充了一个 CFStringRef。头文件定义了一个 QString 对象。我需要将 CFStringRef 的内容传递给 QString。

如何做到这一点?

macos qt cfstring

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

发布CFString

我使用此代码获取ABPerson的姓氏

CFStringRef lastNameRef = ABRecordCopyValue((ABRecordRef)personRecordRef, kABPersonLastNameProperty);
NSString *friendLastName = (NSString*)lastNameRef;
CFRelease(lastNameRef);
Run Code Online (Sandbox Code Playgroud)

当姓氏值不等于NULL时它工作正常但当此值为NULL时,应用程序在第三行崩溃,因为我尝试释放NULL

问题是女巫是在这种情况下释放CFString而不会导致应用程序崩溃的最佳方式

iphone memory-management objective-c cfstring ios

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

从de AddressBook使用CFStrings时的内存管理

我正在使用Apple提供的API从AddressBook中读取记录.

我仍在考虑内存管理,所以CFStrings此刻让我感到困惑.

这就是我获取属性的方式:

//Get Basic properties
NSString* firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString* lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
NSNumber* record = [NSNumber numberWithInt:ABRecordGetRecordID(person)];

//Build Full Name
NSString* fullName=[self fullNameWith:firstName and:lastName];

//Get Phone number and Label
ABMultiValueRef phone = ABRecordCopyValue(person, property);
    //Turn identifier into index
CFIndex index = ABMultiValueGetIndexForIdentifier(phone, identifier);
    //Get the value and the label using the index
NSString *value =(NSString *)ABMultiValueCopyValueAtIndex(phone, index);
CFStringRef label = ABMultiValueCopyLabelAtIndex(phone, index);
    //Get the localized value of hte label
NSString * localizedLabel …
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch memory-management cfstring addressbook

0
推荐指数
1
解决办法
272
查看次数