Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Value of type 'Data' has no member 'writeToURL'

Tags:

ios

swift

cordova

I am converting code into swift 3 syntax

if !data.writeToURL(manifestFileURL, atomically: false) {
      self.didFailWithError(WebAppError.fileSystemFailure(reason: "Could not write asset manifest to: \(manifestFileURL)", underlyingError: error))
      return
}

but I am getting the error

Value of type 'Data' has no member 'writeToURL'

I have converted the code to

if try!data.write(to: manifestFileURL, atomically: false) {
      self.didFailWithError(WebAppError.fileSystemFailure(reason: "Could not write asset manifest to: \(manifestFileURL)", underlyingError: error))
      return
}

following the swift 3 syntax and current methods (https://developer.apple.com/reference/foundation/nsdata/1415134-write) but I get errors saying that this is not the correct overload for the function. Please, what is the correct way to write this out in swift 3. Any information that can lead me in the right direction will be greatly appreciated.

Thanks

like image 251
Adim Avatar asked Jan 28 '26 04:01

Adim


2 Answers

atomically: false is equal to no options, you can omit the parameter.

So it's simply

do {
    try data.write(to: manifestFileURL)
} catch let error as NSError {
    self.didFailWithError(WebAppError.fileSystemFailure(reason: "Could not write asset manifest to: \(manifestFileURL)", underlyingError: error))
}

The catch clause handles the error.

like image 73
vadian Avatar answered Jan 29 '26 17:01

vadian


It has been rename to:

try! data.write(to: manifestFileURL, options: [.atomic])

like image 41
Tj3n Avatar answered Jan 29 '26 18:01

Tj3n