Skip to content

How to add -fobjc-arc-exceptions flag correctly into the XCode? #23

@yccheok

Description

@yccheok

I am using 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.

Does anyone has any idea, how I can add -fobjc-arc-exceptions flag correctly, into my XCode?

These are the steps I am trying to do

  1. Select the project at the top left of the project window.
  2. Select the target.
  3. Open the build phases pane.
  4. Select "Compile Sources"

Now, there are around 500+ source code files. I was wondering, should I

  1. Only add -fobjc-arc-exceptions flags, to files SwiftTryCatch.h and SwiftTryCatch.m ?
  2. Only add -fobjc-arc-exceptions flags, to files SwiftTryCatch.h, SwiftTryCatch.m and any *.swift files which is using SwiftTryCatch ?
  3. Add -fobjc-arc-exceptions flags to all 500+ files ?

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions