NSURL is not implicitly convertible to URL ; did you mean to use as to explicitly convert?
In swift 3 you need to use URL
instead of NSURL
, so create url object like this.
if let url = URL(string: "https://www.google.com") {
webView.load(URLRequest(url: url))
}
“NSURL” is not implicitly convertible to “URL”; did you mean to use “as” to explicitly convert? in swift 3
In swift 3.0, the method signature for openURL
is:
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}
In method signature, NSURL
is changed to URL
.
Is swift 3 not compatible with NSURL classes on iOS 9?
Thanks to OOPer i can answer my own question:
the code works fine with the URL class but only when you set the Deplyoment Target to the same iOS Version as your simulator!
XCode 8 updated my iOS 9 SDK to version 10 and so I only had the choice to use the simulator on either iOS 10 or iOS 8.1. However the Deployment Target was set to iOS 9 (I was pretty sure that it was before the upgrade set to iOS 8.1).
So I run into the runtime error with an iOS 8.1 simulator and Deployment Target set to iOS 9.
But it does work with iOS 8.1 simulator and Deployment Target set to iOS 8.1!
Here is the Swift 3 Code working also with iOS 8.1:
class ServerCom: NSObject, URLSessionDownloadDelegate {
fileprivate var localFileURL: URL = URL(string: "dummy")!
[...]
guard let urlString: URL =
URL(string: params,
relativeTo: URL(string: dcParam.baseURL) ) else {
let failed = "Could not generate URL from: \(dcParam.baseURL)\(params)"
throw fetchAppXmlError.failed_URL_GENERATION(failed)
}
var request = URLRequest(url: urlString)
request.timeoutInterval = 10
request.httpMethod = "GET"
[...]
}
Thank you!
NSMutableSet' is not implicitly convertible to 'Set NSObject '
You should use native Swift types rather than Foundation collections when possible. This eliminates the need for casting.
var xAxisLabels = Set<CPTAxisLabel>()
var xMajorTickLocations = Set<NSNumber>()
Swift 3 WebView
For this exact situation, retype your line to:
yourWebView.loadRequest(URLRequest(url: URL(string: "http://hardwirestudios.com")!))
... and rename yourWebView
variable to one, that you actually use.
In Swift 3.0, use URL and URLRequest as almost all the NS
were dropped.
Swift 3 WKWebView 'URLRequest'; did you mean to use 'as' to explicitly convert? ( BUG )
Use URL and URLRequest instead:
let url = URL(string: "https://facebook.com")!
webView.load(URLRequest(url: url))
This is quite similar to https://stackoverflow.com/a/37812485/2227743: you either use NSURL and have to downcast it as URL, or you directly use the new Swift 3 structs.
If you follow the error message, your example would become:
let url = NSURL(string: "https://facebook.com")!
webView.load(URLRequest(url: url as URL))
It could be even worse:
let url = NSURL(string: "https://facebook.com")!
webView.load(NSURLRequest(url: url as URL) as URLRequest)
All this works but of course it's much better to start using URL and URLRequest in Swift 3, without using all this downcasting.
Related Topics
Swift: Function with Default Parameter Before Non-Default Parameter
How to Apply Shadow to Interior Views in Swiftui
Should Iboutlet Be Weak or Strong Var
How to Implement a Thread Safe Hashtable (Phonebook) Data Structure in Swift
Swiftui @Environmentobject Error: May Be Missing as an Ancestor of This View
How to Draw a Scnnode Always in Front of Others
What's the Best Approach to Prefill Core Data Store When Using Nspersistentcloudkitcontainer
Why Does an Optional in Fast Enumeration Cause an Infinite Loop
iOS 13.1 Uitextview Delegate Method Shouldinteract Called When Scrolling on Attachment
Swift Generics: Cannot Convert Value of Type to Expected Argument Type
Is Self Captured Within a Nested Function
Using Environmentobject in Watchos
Forcing Nspersistentcontainer Change Core Data
How to Remove Quotes from String on Swift
How to Retrieve the Type of an Object in Swift
How Safe Are Swift Collections When Used with Invalidated Iterators/Indices
What Is the Swift 3 Equivalent of Nsurl.Urlbyappendingpathcomponent()