Swift:填写AutoreleasingUnsafeMutablePointer <NSDictionary?>

Dep*_*o B 1 dtcoretext swift ios8

我是DTCoreText,将HTML转换为属性文本.因为我想在前面设置字体,而不是之后,因为它会覆盖所有粗体,斜体等标签我想在构造函数中设置文档属性.这个构造函数要我给一个或多或少似乎是NSDictionary的AutoreleasingUnsafeMutablePointer?和前面的.有点.只有它不允许我以任何方式设置它.我试过.memory,尝试以任何可能的方式投射字典,它只是不接受任何数据.

    let font = UIFont.systemFontOfSize(12)
    let data = info.desc?.dataUsingEncoding(NSUTF8StringEncoding)
    let attributes: NSMutableDictionary? = NSMutableDictionary()
    attributes!.setObject(font, forKey: NSFontAttributeName)
    var attributeRef: AutoreleasingUnsafeMutablePointer<NSDictionary?> = AutoreleasingUnsafeMutablePointer.null()
    NSMutableAttributedString(HTMLData: data, documentAttributes: nil)
    //attributeRef = *attributeDict
    let attributedString = NSMutableAttributedString(HTMLData: data, documentAttributes:attributeRef)
    let paragraphStyle: NSMutableParagraphStyle = NSMutableParagraphStyle()
    paragraphStyle.lineBreakMode = NSLineBreakMode.ByWordWrapping;
    let range = NSMakeRange(0, attributedString.length)
    attributedString.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: range)
    lblMessage.attributedText = attributedString
Run Code Online (Sandbox Code Playgroud)

mat*_*att 5

此时你不应该使用DTCoreText; iOS现在有本机调用.只说var dict = NSDictionary?()和通过&dict.这是示例代码:

let s = "<html><body><h1>Howdy</h1><p>Hello</p></body></html>"
let d = s.dataUsingEncoding(NSUTF16StringEncoding, allowLossyConversion: false)
var dict = NSDictionary?()
let att = NSAttributedString(data: d!, options: [
    NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType
    ], documentAttributes: &dict, error: nil)
println(att!)
println(dict!)
Run Code Online (Sandbox Code Playgroud)

你会发现这非常有效.这是dict:

BottomMargin = 72;
Converted = "-1";
DocumentType = NSHTML;
LeftMargin = 90;
PaperMargin = "UIEdgeInsets: {72, 90, 72, 90}";
PaperSize = "NSSize: {612, 792}";
RightMargin = 90;
TopMargin = 72;
UTI = "public.html";
Run Code Online (Sandbox Code Playgroud)

但是,我通常会通过,nil因为我真正关心的第二本字典中没有任何内容.