Detect if build is triggered from SwiftUI Preview in Build Phases - Run Script

85 views Asked by At

Is there any way to detect if the build was triggered by the SwiftUI Preview from inside Build Phases - Run Script?

I'm using swiftlint with --fix --format, the problem is when I have the Preview open it sometimes triggers a build, which often changes the file while I'm typing, which then brings up the "keep changes/revert" dialog. Keeping the changes often leads Xcode to crash. Ideally, I'd like to do something like this:

if buildWasTriggeredBySwiftUIPreview then
    swiftlint
else 
    swiftlint --fix --format && swiftlint
fi
1

There are 1 answers

0
fer0n On BEST ANSWER

Thanks to Sweeper, this works:

if [ "${ENABLE_PREVIEWS}" = "YES" ]; then 
    swiftlint
else 
    swiftlint --fix --format && swiftlint  
fi