Nitish Nitish - 1 year ago 298
Swift Question

NSRangePointer error Swift

This is what I am trying to achieve:

var range : NSRange? = NSMakeRange(0, (attributedString?.length)!)
attributedString?.attribute(NSFontAttributeName: UIFont.fontNames(forFamilyName: "OpenSans-Regular"), at: 1, effectiveRange: &range)

In second line, I receive a compile time error:

Argument labels '(NSFontAttributeName:, at:, effectiveRange:)' do not match any available overloads

Answer Source

You need:

var range = NSRange(location: 0, length: attributedString?.length)
let font = attributedString?.attribute(NSFontAttributeName, at: 1, effectiveRange: &range)

The 1st parameter is just the attribute you wish to check for. You don't pass in a specific font. This method will tell you want font is found at the specified location.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download