2017-09-07 4 views
1

J'essaie de souligner une chaîne avec une chaîne NSAttributed. Pour une raison quelconque, mes lignes font l'exception:La définition de NSUnderlineStyle provoque une exception de sélecteur non reconnue

-[_SwiftValue _getValue:forType:]: unrecognized selector sent to instance 

Le résultat est censé être utilisé pour un UILabel dans un UITableView et est créé au besoin.

Voici le code:

attributedString = NSMutableAttributedString(string: message) 

if let actor = event.actor { 
    let attributes = [NSUnderlineStyleAttributeName:NSUnderlineStyle.styleSingle] 
    var attributedActorString = NSMutableAttributedString(string: actor.shirtName, attributes: attributes) 
    attributedActorString.insert(NSAttributedString(string: " "), at: 0) 
    attributedActorString.append(NSAttributedString(string: ". "))        attributedActorString.append(attributedImageStringForUrl(event.actor!.portraitImageUrl, indexPath: indexPath)) 
    attributedString.append(attributedActorString) 
} 

Répondre

3

ligne de changement:

let attributes = [NSUnderlineStyleAttributeName:NSUnderlineStyle.styleSingle] 

à:

let attributes = [NSUnderlineStyleAttributeName:NSUnderlineStyle.styleSingle.rawValue] 
+0

qui a fait l'affaire pour moi! Je vous remercie. – ff10

+0

@ ff10, vous êtes les bienvenus;] –