Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an extension to get all attributes on an NSAttributedString #333

Closed
SD10 opened this issue Dec 7, 2017 · 3 comments
Closed

Add an extension to get all attributes on an NSAttributedString #333

SD10 opened this issue Dec 7, 2017 · 3 comments

Comments

@SD10
Copy link
Member

SD10 commented Dec 7, 2017

Add an extension to get all attributes on an NSAttributedString:

extension NSAttributedString {
    var attributes: [NSAttributedStringKey: Any] {
        /// implementation ...
    }
}
@nathanbacon
Copy link
Contributor

Hey Steven, I'm running into trouble with this. There are two types of possible strings this could be applied to:

One where the attributed is applied across the whole string as in
NSAttributedString("Test").bolded

and another where there are multiple attributes of the same type across the string
NSAttributedString("Red").colored(with: UIColor.red) + NSAttributedString("Blue").colored(with: UIColor.blue)

The problem with the second type is that the returned dictionary could only contain one color because both portions have the same NSAtributedStringKey. Returning an Array<(NSAttributedStringKey, Any, NSRange)> would be better for this case.

If this extension is meant to work on homogenous strings, the solution is easy. Let me know what you think.

Thanks

@SD10
Copy link
Member Author

SD10 commented Dec 19, 2017

Hey @nathanbacon!
I was only thinking of homogenous Strings so it is indeed an easy extension. If you think you have a solution for strings with multiple attributes under a single key, I’d look at that too

Sent with GitHawk

SD10 pushed a commit that referenced this issue Dec 22, 2017
* added attributes property and updated tests

* added test

* modified test

* linting

* change log

* switched other tests back to original
@SD10
Copy link
Member Author

SD10 commented Dec 22, 2017

Closed by #340

@SD10 SD10 closed this as completed Dec 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants