我有一个属性文本,其中包含我之前插入的 NSTextAttachment。现在我需要将该图像和任何文本提取到各个变量中以分别保存它们。但是我收到一个错误,除了第一个块中的 EXC_BAD_ACCESS 之外,我没有提供更多信息。我错过了什么?任何信息都有帮助。先感谢您。
if composeView.textView.attributedText == nil{
println("no attributed text")
}else{
let range:NSRange = NSMakeRange(0, composeView.textView.attributedText.length)
self.composeView.textView.attributedText.enumerateAttributesInRange(range, options: nil, usingBlock: { (dic: [NSObject:AnyObject]?, rang:NSRange!, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
var attachement = dic as NSDictionary!
attachement.enumerateKeysAndObjectsUsingBlock({ (key:AnyObject?, obj:AnyObject?, stop:UnsafeMutablePointer<ObjCBool>) -> Void in
var stri = key as NSString!
println(stri)
if stri == "NSAttachment"{
var att:NSTextAttachment = obj as NSTextAttachment
if att.image == nil{
println("no image")
self.saveMessageToParse(text, image: nil)
}else{
var im:UIImage = att.image!
println("image exists")
self.saveMessageToParse(text, image: im)
}
}
})
})