Skip to content

Instantly share code, notes, and snippets.

@jellybeansoup
Created January 23, 2018 05:39
Show Gist options
  • Save jellybeansoup/5fdf8e354bd7cdb19d4b057d292f83c6 to your computer and use it in GitHub Desktop.
Save jellybeansoup/5fdf8e354bd7cdb19d4b057d292f83c6 to your computer and use it in GitHub Desktop.
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