Reputation: 2300
I just used XCode 8 and let it convert my existing project. Now I face the error that there is no init function for new URL without parameters.
class fileObj : NSObject, NSCopying, Comparable {
var URL = NSURL() // initial
...
The new code looks like:
class fileObj : NSObject, NSCopying, Comparable {
var myUrl = Foundation.URL() // initial
...
How should I init the new URL var?
Upvotes: 4
Views: 4203
Reputation: 24041
it makes absolutely zero sense to do so, but currently (Swift3, Xcode Version 8.0 (8A218a)) it is working and gives you a totally blank URL
object with no purpose at all, as you just asked for.
var myURL: URL = NSURLComponents().url!
Upvotes: 4
Reputation: 722
Your observation is indeed correct, there is no empty initialiser because this would be an invalid URL, therefore they decided to disallow that.
What I recommend you doing is not initialising the variable at first and making it an optional (URL?
). Later in the code, you'll be able to initialise it.
Upvotes: 3