Swift behaves differently on debug and release mode

て烟熏妆下的殇ゞ 提交于 2019-12-04 01:17:57

I've had some similar issues when building for release in a project similar to yours(Swift + Objective-C), in my case it was skipping a piece of code within a loop, but it was not skipping the loop itself. In order to solve this we changed at the Build Settings -> Apple LLVM 6.0 Code Generation -> Optimization Level the value of Debug to Fastest, Smallest [-Os], which was the same of Release and then we got the same bug on Debug. Then we tried to changing both to None [-O0] (Which is Debug default value) but it only made the bug disappear on Debug mode not in Release, so we had to workaround that code and change a little bit of the UI.

I would like to believe that it's something the compiler does in Release that can't be changed by us, so maybe it's an Xcode Bug.

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.

flatronka

The answer could be the previous one I gave to the question App crashes in Release build but not in debug.


Apple also describes a known issue. I describe it briefly in case someone is look for answer and the previous solution doesn't work.

Check your crashlog for errors like

Dyld Error Message:
  Library not loaded: @rpath/libswiftCore.dylib

or

[....] [deny-mmap] mapped file has no team identifier and is not a platform binary:
/private/var/mobile/Containers/Bundle/Application/5D8FB2F7-1083-4564-94B2-0CB7DC75C9D1/YourAppNameHere.app/Frameworks/libswiftCore.dylib

and follow apple guidance if you have similar crash output like the one above.

PS: You could check the log easily even under Window ->Device in XCode. click to the device and click view device logs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!