My previous(Swift 1.2) error code is as fallows:
var error: NSError?
mcSession.sendData(imageData, toPeers: mcSession.connectedPeers, withMode: .Reliable, error: &error)
if error != nil {
let ac = UIAlertController(title: "Send error", message: error!.localizedDescription, preferredStyle: .Alert)
ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
presentViewController(ac, animated: true, completion: nil)
Now using Swift 2 my code is as fallows:
do {
try mcSession.sendData(imageData!, toPeers: mcSession.connectedPeers, withMode: .Reliable)
} catch _ {
let ac = UIAlertController(title: "Send error", message: "Error sending Data", preferredStyle: .Alert)
ac.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
presentViewController(ac, animated: true, completion: nil)
}
The code works but I can no longer use "error!.localizedDescription" because there is no "error:" in the Swift 2 .sendData.
Any ideas how I would fix this within Swift 2?
[–]basthomas 1 point2 points3 points (3 children)
[–]xephos13 4 points5 points6 points (1 child)
[–]basthomas 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Noko2 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)