Esri / arcgis-runtime-samples-ios

Swift samples demonstrating various capabilities of ArcGIS Runtime SDK for iOS
https://developers.arcgis.com/ios
Apache License 2.0
324 stars 396 forks source link

exportImageWithCompletion Not found when i used ArcGis Map in swift 3.0 #229

Closed shahchirag2110 closed 7 years ago

shahchirag2110 commented 7 years ago

I wrote code like this . I need this thing working urgently . Please help me

self.mapView.exportImageWithCompletion { [weak self] (image:UIImage?, error:NSError?) -> Void in
            if let error = error {
                UIAlertView(title: "Error", message: error.localizedDescription, delegate: nil, cancelButtonTitle: "Ok").show()
            }
            if let image = image {
                //on completion imitate flash

            }
        }

But in swift 3.0 this method not found see the screen shot screen shot 2016-11-19 at 7 49 15 pm

singhgag commented 7 years ago

Try removing the WithCompletion from method name. Or simply start fresh, see if you get the method in the intelli-sense when you do a mapView..

singhgag commented 7 years ago

I am including a snippet thats working for me.

self.mapView.exportImage { [weak self] (image:UIImage?, error:NSError?) -> Void in
            if let error = error {
                UIAlertView(title: "Error", message: error.localizedDescription, delegate: nil, cancelButtonTitle: "Ok").show()
            }
            if let image = image {
                //on completion imitate flash
                self?.imitateFlash(image)
            }
        }
shahchirag2110 commented 7 years ago

@singhgag Thank for reply but same error look the screenshot and if start fresh method not found i am not getting the method in intelli-sense of xcode

 self.mapView.exportImage { [weak self] (image:UIImage?, error:NSError?) -> Void in
            if error != nil{
                UIAlertView(title: "Error", message: error.localizedDescription, delegate: nil, cancelButtonTitle: "Ok").show()
            }
            if let image = image {
                //on completion imitate flash
//                self?.imitateFlash(image)
            }
        }

In intelli-sense below method i got screen shot 2016-11-22 at 5 08 52 pm And error something like below screen shot 2016-11-22 at 5 08 20 pm

shahchirag2110 commented 7 years ago

@singhgag did import any thing in file i import only ArcGIS and i am coding in Xcode 8 and swift 3.0

maryharvey commented 7 years ago

@shahchirag2110 Apologies if you have already tried this. So the problem is that intellisense (auto-complete) is not picking up the ArcGIS API. I experienced this a few times and solved it by closing all open projects and Quiting Xcode. On reopening the project auto-complete operated correctly. 2016-11-22_11-52-18

shahchirag2110 commented 7 years ago

@maryharvey I tried it 2 to 3 times but it is not working any how

maryharvey commented 7 years ago

@shahchirag2110 This sounds like a general problem with your auto-complete (not specific to the Samples)... if you agree you could transfer this query to the geonet channel? https://geonet.esri.com/community/developers/native-app-developers/arcgis-runtime-sdk-for-ios ? Please state the version of Xcode and Swift.

dlednik commented 7 years ago

Just a note on the original code. NSError has been replaced with Error class in Swift 3.x, that is why compiler is complaining.

I found it's best not to include type in blocks to avoid this issues in the future:

self.mapView.exportImageWithCompletion { [weak self] (image, error) -> Void in
            if let error = error {
                UIAlertView(title: "Error", message: error.localizedDescription, delegate: nil, cancelButtonTitle: "Ok").show()
            }
            if let image = image {
                //on completion imitate flash

            }
        }
dg0yal commented 7 years ago

Here is the swift 3 usage - https://github.com/Esri/arcgis-runtime-samples-ios/blob/18570eca866320d233b8e57cfc7136d1172f6d4a/arcgis-ios-sdk-samples/Maps/Take%20screenshot/MapViewScreenshotViewController.swift#L74