swift3
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 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 = …
Strange generic function appear in view controller after converting to swift 3
That is interesting. Before the latest Swift 3, you could compare optional values, for example let a: Int? = nil let b: Int? = 4 print(a < b) // true and nil was considered less than all non-optional values. This feature has been removed (SE-0121 – Remove Optional Comparison Operators) and the above code would …
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 …
What is the equivalent of a Java HashMap in Swift
I believe you can use a dictionary. Here are two ways to do the dictionary part. var someProtocol = [String : Int]() someProtocol[“one”] = 1 someProtocol[“two”] = 2 or try this which uses type inference var someProtocol = [ “one” : 1, “two” : 2 ] as for the for loop var index: Int for …
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 = “” …
How has the NSIndexPath initialization changed in Swift3? [closed]
NSIndexPath has been changed to IndexPath try IndexPath(row: Int, section: Int) API Reference : indexpath Swift 3.0 Developer Preview
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 …
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 = …