Type ‘NSAttributedStringKey’ (aka ‘NSString’) has no member ‘font’

Note: Ensure swift language version of your project. Here is how you can see/check your swift language version. You have two options as solution to your query: If your project has Swift versio 4.0 – You should choose/download POD compatible to your project’s swift language (Share me POD info and swift version, so I can …

Read more

Read JSON file with Swift 3

Your problem here is that you force unwrap the values and in case of an error you can’t know where it comes from. Instead, you should handle errors and safely unwrap your optionals. And as @vadian rightly notes in his comment, you should use Bundle.main.url. private func readJson() { do { if let file = …

Read more

Error Handling in Swift 3

One way you can do is throwing your own errors on finding nil. With having this sort of your own error: enum MyError: Error { case FoundNil(String) } You can write something like this: do{ let xmlString = try String(contentsOf: accessURL, encoding: String.Encoding.utf8) guard let xmlDict = XMLDictionaryParser.sharedInstance().dictionary(with: xmlString) else { throw MyError.FoundNil(“xmlDict”) } guard …

Read more

How to override localizedDescription for custom Error in Swift 3? [duplicate]

The documentation about new Error bridging feature is not clear enough still now, so this answer may need some updates in the near future, but according to SE-0112 and the latest Swift source code, you may need to use LocalizedError rather than Error and implement errorDescription. class MyError: NSObject, LocalizedError { var desc = “” …

Read more

Swift 3 Decimal, NSDecimal and NSDecimalNumber

I asked my question on the swift-users board and got a wonderful answer, check it out here: https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20161219/004220.html Text version of the response: Swift 3 introduced the Decimal class, which at first I thought was supposed to ‘replace’ NSDecimalNumber in Swift, like Error is the new NSError, etc. However, upon further investigation, it’s not clear …

Read more

Swift 3 – Check if WKWebView has loaded page

Answer (Big thanks to @paulvs ) To check if your WKWebView has loaded easily implement the following method: import WebKit import UIKit class ViewController: UIViewController, WKNavigationDelegate { let webView = WKWebView() func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { print(“loaded”) } override func viewDidLoad() { super.viewDidLoad() let url = URL(string: “https://www.yourwebsite.com/”) ! let request = …

Read more