dreamwieber / AttributedMarkdown

Native Markdown Parsing to NSAttributedString on iOS
Other
412 stars 71 forks source link

How do I use attributes with Swift #32

Open osrl opened 9 years ago

osrl commented 9 years ago
let attributes = [H1:[NSFontAttributeName:font],
            H1:[NSForegroundColorAttributeName:color]] 

this doesn't work. "Type NSString does not confrom to protocol 'Hashable' "

osrl commented 9 years ago

In case someone has this problem:

let attributes = [
            NSNumber(unsignedInt: H1.value):[NSFontAttributeName:font,
                                             NSForegroundColorAttributeName:color],
            NSNumber(unsignedInt: H2.value):[NSForegroundColorAttributeName:color]]
buscarini commented 8 years ago

.value didn't work for me, not sure if this has changed in some version of swift. I had to use .rawValue

let attributes = [
        NSNumber(unsignedInt: H1.rawValue):[NSFontAttributeName:font,
                                         NSForegroundColorAttributeName:color],
        NSNumber(unsignedInt: H2.rawValue):[NSForegroundColorAttributeName:color]]
arielelkin commented 8 years ago

@buscarini could you please post more of your code? I'm trying to write a complete Swift example. See https://github.com/dreamwieber/AttributedMarkdown/issues/38