我完全不知道出了什么问题: extension UserDefaults { static let shared = UserDefaults(suiteName: SharedGroupName)! static func set(object: Any, forKey key: String) { shared.set(object, forKey: key) shared.synchronize() }} 你应该
extension UserDefaults { static let shared = UserDefaults(suiteName: SharedGroupName)! static func set(object: Any, forKey key: String) { shared.set(object, forKey: key) shared.synchronize() } }你应该尝试省略静态变量,只需使用:
UserDefaults(suiteName: SharedGroupName)!.set(object, forKey: key)
它可能会有所作为.而且,如其中一条评论中所述,不需要“同步”.