Forcing NSPersistentContainer change Core Data
问题 I just added the option for a user to toggle Cloud sync inside my app where I save whether or not the user wants to use iCloud sync in UserDefaults under "useCloudSync". I load my persistentContainer when the app runs with: class CoreDataManager { static let sharedManager = CoreDataManager() private init() {} lazy var persistentContainer: NSPersistentContainer = { var useCloudSync = UserDefaults.standard.bool(forKey: "useCloudSync") let containerToUse: NSPersistentContainer? if useCloudSync {