Create PDF in Swift

后端 未结 1 1338
一个人的身影
一个人的身影 2021-01-14 19:03

I am following Apple\'s Docs to create a PDF file using Xcode6-Beta6 in Swift

var currentText:CFAttributedStringRef = CFAttributedStringCreate(nil, textView.         


        
相关标签:
1条回答
  • 2021-01-14 19:26

    First you have to give it an explicit optional type (using the ?):

    var currentText: CFAttributedStringRef? = ...
    

    Then you can compare it to nil:

    if currentText != nil {
        // good to go
    }
    

    Your code compiles at the moment, because Apple hasn't yet "swiftified" CoreFoundation to return properly annotated types.

    Be prepared that in the final release your code will not even compile, forcing you to use the optional type.

    0 讨论(0)
提交回复
热议问题