Shouldn’t NSUserDefault be clean slate for unit tests?

Using named suites like in this answer worked well for me. Removing the user defaults used for testing could also be done in func tearDown(). class MyTest : XCTestCase { var userDefaults: UserDefaults? let userDefaultsSuiteName = “TestDefaults” override func setUp() { super.setUp() UserDefaults().removePersistentDomain(forName: userDefaultsSuiteName) userDefaults = UserDefaults(suiteName: userDefaultsSuiteName) } }

AVURLAsset getting video size

Resolution in Swift 3: func resolutionSizeForLocalVideo(url:NSURL) -> CGSize? { guard let track = AVAsset(URL: url).tracksWithMediaType(AVMediaTypeVideo).first else { return nil } let size = CGSizeApplyAffineTransform(track.naturalSize, track.preferredTransform) return CGSize(width: fabs(size.width), height: fabs(size.height)) } For Swift 4: func resolutionSizeForLocalVideo(url:NSURL) -> CGSize? { guard let track = AVAsset(url: url as URL).tracks(withMediaType: AVMediaType.video).first else { return nil } let size …

Read more

Creating groups using a custom template xcode 8

In case this helps someone, here’s a project template that works with Xcode 12.4: <key>Nodes</key> <array> <string>ViewController.swift:comments</string> <string>ViewController.swift:imports:importCocoa</string> <string>ViewController.swift:implementation(___FILEBASENAME___: UIViewController)</string> <string>ViewController.swift:implementation:methods:viewDidLoad(override func viewDidLoad(\))</string> <string>ViewController.swift:implementation:methods:viewDidLoad:super</string> <string>Info.plist:UIMainStoryboardFile</string> <string>Info.plist:UIApplicationSceneManifest:UISceneStoryboardFile</string> <string>Some/MainCoordinator.swift</string> <string>Some/Other/TestClass.swift</string> </array> <key>Definitions</key> <dict> <key>Some/MainCoordinator.swift</key> <dict> <key>Group</key> <array> <string>Some</string> </array> <key>Path</key> <string>MainCoordinator.swift</string> </dict> <key>Some/Other/TestClass.swift</key> <dict> <key>Group</key> <array> <string>Some</string> <string>Other</string> </array> <key>Path</key> <string>TestClass.swift</string> </dict> </dict> The group is Some. …

Read more

‘Class FIFinderSyncExtensionHost is implemented in both …’ warning in Xcode since update to macOS High Sierra

There’s nothing you can do about this. It’s an Apple problem, but it’s probably harmless. Note: I’m not sure what other description could be given than what the warning says. It just means that the same class is defined in two modules. With Apple stuff, they’re often identical so it doesn’t matter which copy is …

Read more

How can I reset the package cache on just one package with Swift Package Manager

To reset the cache for a single package: Navigate to ~/Library/Caches/org.swift.swiftpm/repositories and deleting the folder and lock file related to the package Then, in Xcode, run File–>Swift Packages–>Reset Package Caches You can also try the solution recommended here to reset the entire cache (thanks @Bao Lei): https://stackoverflow.com/a/72838880/1099193