Not sure if that's an issue with Swift, XCode or Alamofire but I recognized strange behavior on different places within my mixed Swift/Objc app. It only happens in parts which are written in Swift and use closures/networking. Here's an example code where it happens:
Alamofire.request(.DELETE, "http://someUrl.com/user", parameters: nil)
.response { (request, response, data, error) in
// some cleanup code and an alert
}
When I run my app in Debug mode on my iPhone then it all just works, the cleanup code and the alert get presented like they should when I do the "delete account" action which runs the code above.
But when I send my app to users via Testflight or run my app on the same iPhone directly but using the Release build configuration then the cleanup code doesn't run and the alert doesn't show up. It looks like the whole closure doesn't get called.
Does anyone have experiences with such strange behaviors and knows how to prevent them? I'm not sure what's the issue here, therefore it is hard for me to figure out a solution that works on both Debug and Release modes.
Thank you for any help!
The environment: I'm using Alamofire 1.1.3 as an embedded framework integrated to my project as a git submodule. The app runs on iOS 8+ only, I have iOS 8.1.2 installed on my iPhone 6.
Debug Mode: When we are developing the application. Release Mode: When we are going to production mode or deploying the application to the server. Debug Mode: The debug mode code is not optimized. Release Mode: The release mode code is optimized.
You can now debug your release build application. To find a problem, step through the code (or use Just-In-Time debugging) until you find where the failure occurs, and then determine the incorrect parameters or code.
The Swift REPL can be used for debugging, to test and interact with your app. When code breaks, typing repl into LLDB will allow you to interactively test code. You can call methods with different arguments, and test new functions by adding them to your existing code.
It's not a real solution, but as a workaround it worked to just not put the code inside a completion handler. Instead it is now part of a method (all context variables need to be accessible within that method of course) and I save the type of request I make.
When the request
method from my above example runs and checks if it has a completion closure code to run I additionally added a check for the type and if it's the type where the bug happened then it simply calls that method where the completion code now is in.
This of course is very ugly but until Apple fixes this bug (I sent them a bug report with example code) I can't figure out any other solution. Maybe this workaround helps someone else as well. If my description is confusing just tell me and I will try to be clearer with some example code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With