How to prevent the use of a unique init method from the full source path in Xcode?

In a new Xcode project, I added a new class using a special init method like this:

import Cocoa

class NewClass: NSControl {

    override init(frame: CGRect) {
        super.init(frame: frame)
    }

    required init(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

However, if I create and archive the project, the absolute path to the source file is displayed in binary format:

/Users/my_username/my_path_to_xcode_projects/new_project/NewClass.swift

I plan to distribute my latest project over the Internet. How can I prevent Xcode from exposing my catalog layout to others? I learned from answers to similar questions that in the Xcode Build Settings you should set Deployment Prostprocessing to Yes to strip characters from binary, but this does not seem to work in my case.

+4
1

fatalError:

@noreturn public func fatalError(
    @autoclosure message: () -> String = default, 
    file: StaticString = #file, line: UInt = #line)

#file #line . .

, :

fatalError("Something went wrong", file: "", line: 0)

, .

#file , 4 , - assert assertionFailure, . 2 precondition preconditionFailure.

DEBUG/RELEASE: enter image description here

mocked fatalError .. , #file :

#if RELEASE
@inline(__always) @noreturn func fatalError(@autoclosure message: () -> String = "") {
    Swift.fatalError(message, file: "", line: 0)
}

@inline(__always) func preconditionAlt(@autoclosure condition: () -> Bool, @autoclosure _ message: () -> String = "") {
    Swift.precondition(condition, message, file: "", line: 0)
}

@inline(__always) @noreturn func preconditionFailureAlt(@autoclosure message: () -> String = "") {
    Swift.preconditionFailure(message, file: "", line: 0)
}
#else
@inline(__always) func preconditionAlt(@autoclosure condition: () -> Bool, @autoclosure _ message: () -> String = "", file: StaticString = #file, line: UInt = #line) {
    Swift.precondition(condition, message, file: file, line: line)
}

@inline(__always) @noreturn func preconditionFailureAlt(@autoclosure message: () -> String = "") {
    Swift.preconditionFailure(message, file: file, line: line)
}
#endif

, - , . , , . precondition[Failure] precondition[Failure]Alt, Swift . Shift - Alt - Cmd - F

, , , framework. , , .

- #file, , , , .

, .

+5

Source: https://habr.com/ru/post/1648836/


All Articles