如何正确对待CGPDFDocumentRef对象,以便将其添加到NSArray中,然后以CGPDFDocumentRef形式轻松地检索回来?
发布于 2014-01-14 20:28:53
只要在添加/访问时将CGPDFDocumentRef转换为适当的类型,就可以轻松地将它们添加到NSArray或NSMutableArray中。
下面是我测试过的示例代码:
CFStringRef path;
CFURLRef url;
CGPDFDocumentRef document;
NSString *nsstringPath = [[NSURL pathForDocumentsDirectory] stringByAppendingPathComponent:@"test.pdf"];
path = CFStringCreateWithCString (NULL, [nsstringPath cStringUsingEncoding:NSUTF8StringEncoding], kCFStringEncodingUTF8);
url = CFURLCreateWithFileSystemPath (NULL, path, kCFURLPOSIXPathStyle, 0);
CFRelease (path);
document = CGPDFDocumentCreateWithURL (url);
CFRelease(url);
count = CGPDFDocumentGetNumberOfPages (document);
NSMutableArray *testArray = [NSMutableArray array];
[test addObject:(__bridge id)(document)];
CGPDFDocumentRef testPdf = (__bridge CGPDFDocumentRef)([testArray objectAtIndex:0]); 这是一个链接到苹果的文档,包括免费桥接。虽然它涵盖了基金会框架,但应该给出一个想法。
希望这有帮助,干杯!
发布于 2014-01-14 20:27:18
它是今天早些时候用不同的对象发布的,但我目前找不到它。
可以创建要添加到数组中的NSValue对象。不确定它是如何工作的,只需在这里返回信息:
[NSValue valueForBytes:(pointer) objCType:@encode(CGPDFDocumentRef)];https://stackoverflow.com/questions/21122998
复制相似问题