I am using https://github.com/williamFalcon/SwiftTryCatch as a workaround for a rare NSInternalInconsistencyException incident.
Here's the code snippet.
private func safePerformBatchUpdates(_ updates: (() -> Void)?, completion: ((Bool) -> Void)? = nil) {
SwiftTryCatch.try({
collectionView.performBatchUpdates(updates, completion: completion)
}, catch: { (error) in
print("\(error)")
Crashlytics.crashlytics().record(error: error)
recoverFromPerformBatchUpdatesError()
}, finally: nil)
}
In https://github.com/williamFalcon/SwiftTryCatch, it is mentioning
It was pointed out that without -fobjc-arc-exceptions flag this will lead to memory leaks http://clang.llvm.org/docs/AutomaticReferenceCounting.html#exceptions Therefore, ARC-generated code leaks by default on exceptions, which is just fine if the process is going to be immediately terminated anyway. Programs which do care about recovering from exceptions should enable the option.
How can I add -fobjc-arc-exceptions flag correctly, into my Xcode?
These are the steps I am trying to do
Now, there are around 500+ source code files. I was wondering, should I
-fobjc-arc-exceptions flags, to files SwiftTryCatch.h and SwiftTryCatch.m?-fobjc-arc-exceptions flags, to files SwiftTryCatch.h, SwiftTryCatch.m and any *.swift files which is using SwiftTryCatch?-fobjc-arc-exceptions flags to all 500+ files?You need to compile the file that raises the exception with -fobjc-arc-exceptions. So you would need to recompile UIKit (or probably CoreData), which you cannot do.
Also note that -fobjc-arc-exceptions just helps prevent certain kinds of memory leaks. It does not make the call exception-safe. Exceptions can still leave the system in an undefined state, depending on how the code is writen. Sometimes this undefined state doesn't cause any actual problems, but in general it is not possible to recover from an exception.
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