Instantly share code, notes, and snippets.

Embed
What would you like to do?
Preloading App Data for Screenshots
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
prepareForTestingUI()
// Handle the actual launch of your application
}
private func prepareForTestingUI() {
guard let contentsURL = Bundle.main.url(forResource: "UITests", withExtension: "xcappdata")?.appendingPathComponent("AppData") else {
return
}
guard let destinationRoot = FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).last?.deletingLastPathComponent() else {
return
}
guard let enumerator = Foundation.FileManager.default.enumerator(at: contentsURL, includingPropertiesForKeys: [.isDirectoryKey], options: [], errorHandler: nil) else {
return
}
while let sourceURL = enumerator.nextObject() as? URL {
guard let resourceValues = try? sourceURL.resourceValues(forKeys: [.isDirectoryKey]),
let isDirectory = resourceValues.isDirectory,
!isDirectory else { continue }
let path = sourceURL.standardizedFileURL.path.replacingOccurrences(of: contentsURL.standardizedFileURL.path, with: "")
let destinationURL = destinationRoot.appendingPathComponent(path)
do {
try Foundation.FileManager.default.createDirectory(at: destinationURL.deletingLastPathComponent(), withIntermediateDirectories: true, attributes: nil)
try Foundation.FileManager.default.copyItem(at: sourceURL, to: destinationURL)
}
catch {}
}
}
#!/bin/bash
if [[ ${CONFIGURATION} == "Debug" ]] && [[ ! -z ${FASTLANE_SNAPSHOT} ]]; then
bundlePath="${CONFIGURATION_BUILD_DIR}/${CONTENTS_FOLDER_PATH}"
cp -R "${SRCROOT}/AppData/UITests.xcappdata" $bundlePath
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment