首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Swift中创建PDF

在Swift中创建PDF
EN

Stack Overflow用户
提问于 2014-09-04 19:16:11
回答 1查看 5.2K关注 0票数 3

我跟随苹果的Docs在Swift中使用Xcode6-Beta6创建一个PDF文件。

代码语言:javascript
复制
var currentText:CFAttributedStringRef = CFAttributedStringCreate(nil, textView.text as NSString, nil)

if (currentText) { // <-- This is the line XCode is not happy

   // More code here

}

编译器抛出Type 'CFAttributedStringRef' does not conform to protocol 'BooleanType'错误

如果我使用if(currentText != nil),我会得到'CFAttributedStringRef' is not convertible to 'UInt8'

从苹果的CFAttributedStringCreate文档

代码语言:javascript
复制
Return Value
An attributed string that contains the characters from str and the attributes specified by    attributes. The result is NULL if there was a problem in creating the attributed string. Ownership follows the Create Rule.

知道怎么解决这个问题吗?谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-04 19:19:55

首先,您必须给它一个显式的可选类型(使用?):

代码语言:javascript
复制
var currentText: CFAttributedStringRef? = ...

然后你可以把它和零比较:

代码语言:javascript
复制
if currentText != nil {
    // good to go
}

您的代码目前正在编译,因为苹果还没有“快速”的CoreFoundation来返回正确注释的类型。

做好准备,在最终版本中,您的代码甚至不会编译,这迫使您使用可选类型。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25673392

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档