ios_google_places_autocomplete icon indicating copy to clipboard operation
ios_google_places_autocomplete copied to clipboard

Conversion of swift 2.3 code to swift 3

Open shrivastavaharsh opened this issue 7 years ago • 15 comments

I am having issues related to conversion, whenever I am trying to open xib with button action I am getting this error found nil while unwrapping optional, another issue is related to response http code. If you can provide converted syntax of the code that will be great!

Thanks

shrivastavaharsh avatar Sep 14 '16 20:09 shrivastavaharsh

@shrivastavaharsh I've got a swift-3 branch on the go if you're interested. @watsonbox sorry but there's another massive pull request in the making there ;)

samscam avatar Sep 18 '16 09:09 samscam

@shrivastavaharsh I'd be happy to look at this for possible merging once it's ready, although there appears to be a fair amount of stuff on that branch that isn't swift-3 specific.. Also are there a lot of changes required? I haven't looked at it yet. Does the Travis CI env support Swift 3?

watsonbox avatar Sep 19 '16 07:09 watsonbox

I looks like to me that there is some syntax changes required, such as some response http code, plus xib file look different also, I am new to swift. I am getting error of usual found nil while unwrapping optional value, which I am unable to debug. Lot of changes is been made by xcode also which could be reason of error.

shrivastavaharsh avatar Sep 19 '16 07:09 shrivastavaharsh

@samscam I am getting this runtime exception partial apply forwarder for Swift.(_fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt, flags : Swift.UInt32) -> Swift.Never).(closure #2) And on debug console - fatal error: unexpectedly found nil while unwrapping an Optional value

I have already checked all the outlets everything is fine, is it something related to swift 3?

Thanks!

shrivastavaharsh avatar Sep 24 '16 05:09 shrivastavaharsh

@shrivastavaharsh that sounds like a standard unwrapped optional bug. Very sorry but I can't glean much without knowing which actual line of code it failed on and if it was coming from GPA (in which case we can help) or your own code (in which case we can't).

There are plenty of guides on how optionals work in swift out there which might help you.

samscam avatar Sep 26 '16 20:09 samscam

@samscam Thanks for your reply! the actual line code which is producing that bug is topConstraint.constant = topLayoutGuide.length

This line is present in GPA code in the viewWillLayoutSubviews func.

shrivastavaharsh avatar Sep 26 '16 20:09 shrivastavaharsh

Ok well that does sound like you've lost an outlet. In GooglePlacesAutocomplete.xib there should be a constraint between the top of the search bar and the view. That should be connected to the topConstraint outlet of the file's owner in IB. It's definitely hooked up in the one one provided here... and definitely not a result of swift 3 conversion!

samscam avatar Sep 26 '16 21:09 samscam

@samscam I can see the outlet defined @IBOutlet weak var topConstraint: NSLayoutConstraint! in my implementation also. It was working before update and I didnt connected anything.

shrivastavaharsh avatar Sep 26 '16 21:09 shrivastavaharsh

@watsonbox Yes it's got all my other changes in it too :)

  1. The PlaceDetail and LocationBias model have been somewhat extended to include CLLocation and CLRegion properties - this is non breaking but does add a dependency on CoreLocation. It's also very useful :)
  2. There's some refactoring and addition of a GooglePlacesAutocompleteService which performs the calling of the api and mapping of JSON to Place objects - previously this was embedded in the GooglePlacesAutocompleteContainer class. This way it's possible to make the api calls away from the bundled UI. I'd still like to make this separation cleaner, document it, and test the UI and API chunks in isolation.
  3. I added a few lines of code in the example app to substitute in the API_KEY from an environment variable. The tests use the substitution too (even though they don't make real network calls).
  4. Apart from that, it's all reasonable conversion stuff.

Travis does XCode 8 and after some head scratching (blinking cursors and api changes to FBSnapshotTestCase) as well as the inevitable re-do of the images because the OS looks different, the tests pass.

samscam avatar Sep 26 '16 23:09 samscam

@samscam I changed the top constraint force unwrap ! to optional ? then its working. I hope it wont effect functionality. btw thanks for your work!

shrivastavaharsh avatar Sep 27 '16 03:09 shrivastavaharsh

@watsonbox Any update here, with regards to supporting Swift 3?

irace avatar Oct 26 '16 15:10 irace

I updated the code for swift 3 http://github.com/varun-naharia/ios_google_places_autocomplete and created a pull request

varun-naharia avatar Jul 23 '17 07:07 varun-naharia

Hi @varun-naharia please find the attached screenshot. How we remove this error. screen shot 2017-10-25 at 11 59 58 pm

ErAshu avatar Oct 25 '17 18:10 ErAshu

@ErAshu are you using http://github.com/varun-naharia/ios_google_places_autocomplete this ?

varun-naharia avatar Oct 26 '17 08:10 varun-naharia

Yes, I am using this. Simple download and run demo.

ErAshu avatar Oct 27 '17 04:10 ErAshu