Ads

Monday, 23 October 2017

NSAttributedString in Swift4

1. NSAttributedString

Until Swift 3 we were able to create NSAttributedString as follows:

let myMutableString = NSAttributedString(string: "My String", attributes: [NSForegroundColorAttributeName: UIColor.white])

which follows the below syntax as reference

let = NSAttributedString(string: "String Name", attributes: [< NSAttributeName>: ])

But it has been changed as follows:

let = NSAttributedString(string: "String Name", attributes: [< NSAttributedStringKey>: ])

So lets see what is NSAttributedStringKey

NSAtrributedStringKey

1. Initialise:

let attributedStringKey = NSAtrributedStringKey.init("")

or  we can use the raw values

let attributedStringKey = NSAtrributedStringKey.init(rawValue: "")

for reference you can go through this link.


No comments:

Post a Comment

SOLID Principles

SOLID principles are the basic essential thing to know for every developer before he/she starts coding in any IDE. Here is the full form S ...