From 33f6ace2e42a5cca93c9ea50b75454cbd8717d4d Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Fri, 17 Feb 2023 08:30:09 -0800 Subject: [PATCH] Fix new warnings introduced in Swift 5.8 --- CHANGELOG.md | 2 + Configuration/Base.xcconfig | 2 +- Realm.podspec | 5 +- Realm.xcodeproj/project.pbxproj | 13 +- .../xcschemes/Download BaaS.xcscheme | 2 +- .../xcschemes/Object Server Tests.xcscheme | 2 +- .../xcschemes/Realm iOS static.xcscheme | 2 +- .../xcshareddata/xcschemes/Realm.xcscheme | 2 +- .../xcschemes/RealmSwift.xcscheme | 2 +- .../xcshareddata/xcschemes/SwiftLint.xcscheme | 2 +- .../xcschemes/SwiftUISyncTestHost.xcscheme | 2 +- .../xcschemes/SwiftUITestHost.xcscheme | 2 +- .../xcschemes/TestHost static.xcscheme | 2 +- .../xcshareddata/xcschemes/TestHost.xcscheme | 2 +- Realm/ObjectServerTests/EventTests.swift | 4 +- Realm/ObjectServerTests/RealmServer.swift | 77 ++++++---- .../SwiftAsymmetricSyncServerTests.swift | 17 +-- .../SwiftObjectServerTests.swift | 8 +- .../SwiftServerObjects.swift | 2 +- .../ObjectServerTests/SwiftSyncTestCase.swift | 1 + Realm/RLMAsymmetricObject.h | 2 +- Realm/RLMBSON_Private.hpp | 6 +- Realm/RLMObjectBase.h | 123 --------------- Realm/RLMObject_Private.h | 2 +- Realm/RLMObject_Private.hpp | 1 + Realm/RLMSwiftObject.h | 142 ++++++++++++++++++ Realm/RLMUser.mm | 2 +- Realm/Realm.modulemap | 51 ++++++- Realm/TestUtils/RLMTestCase.m | 10 +- Realm/Tests/ArrayPropertyTests.m | 2 +- Realm/Tests/DictionaryPropertyTests.m | 2 +- .../Tests/Swift/SwiftArrayPropertyTests.swift | 34 ++++- .../Swift/SwiftObjectInterfaceTests.swift | 16 +- .../Tests/Swift/SwiftRLMDictionaryTests.swift | 25 ++- Realm/Tests/Swift/SwiftRealmTests.swift | 1 + Realm/Tests/Swift/SwiftSchemaTests.swift | 4 +- Realm/Tests/Swift/SwiftSetPropertyTests.swift | 12 +- RealmSwift/Aliases.swift | 2 +- RealmSwift/App.swift | 1 + RealmSwift/Migration.swift | 2 +- RealmSwift/Realm.swift | 20 +-- RealmSwift/Tests/CombineTests.swift | 36 ++--- RealmSwift/Tests/CustomColumnNameTests.swift | 6 +- .../Tests/CustomObjectCreationTests.swift | 2 +- RealmSwift/Tests/ListTests.swift | 8 +- RealmSwift/Tests/MapTests.swift | 8 +- RealmSwift/Tests/MigrationTests.swift | 4 +- .../Tests/ModernObjectCreationTests.swift | 10 +- RealmSwift/Tests/MutableSetTests.swift | 4 +- RealmSwift/Tests/ObjectCreationTests.swift | 123 ++++++++------- RealmSwift/Tests/ObjectTests.swift | 18 +-- RealmSwift/Tests/PerformanceTests.swift | 12 +- RealmSwift/Tests/ProjectionTests.swift | 6 +- .../Tests/RealmCollectionTypeTests.swift | 4 +- RealmSwift/Tests/SwiftTestObjects.swift | 5 +- RealmSwift/Tests/TestCase.swift | 32 ++++ .../Tests/ThreadSafeReferenceTests.swift | 4 +- .../project.pbxproj | 2 +- .../project.pbxproj | 2 +- .../project.pbxproj | 2 +- .../CarthageExample.xcodeproj/project.pbxproj | 2 +- .../xcschemes/CarthageExample.xcscheme | 2 +- .../project.pbxproj | 2 +- .../CocoaPodsDynamicExample.xcscheme | 2 +- .../project.pbxproj | 2 +- .../xcschemes/CocoaPodsExample.xcscheme | 2 +- .../DynamicExample.xcodeproj/project.pbxproj | 2 +- .../xcschemes/DynamicExample.xcscheme | 2 +- .../StaticExample.xcodeproj/project.pbxproj | 2 +- .../xcschemes/StaticExample.xcscheme | 2 +- .../project.pbxproj | 2 +- .../xcschemes/XCFrameworkExample.xcscheme | 2 +- .../CarthageExample.xcodeproj/project.pbxproj | 2 +- .../xcschemes/CarthageExample.xcscheme | 2 +- .../project.pbxproj | 2 +- .../xcschemes/CocoaPodsExample.xcscheme | 2 +- .../DynamicExample.xcodeproj/project.pbxproj | 2 +- .../xcschemes/DynamicExample.xcscheme | 2 +- .../project.pbxproj | 2 +- .../project.pbxproj | 2 +- .../xcschemes/XCFrameworkExample.xcscheme | 2 +- .../CarthageExample.xcodeproj/project.pbxproj | 2 +- .../xcschemes/CarthageExample.xcscheme | 2 +- .../project.pbxproj | 2 +- .../xcschemes/CocoaPodsExample.xcscheme | 2 +- .../DynamicExample.xcodeproj/project.pbxproj | 2 +- .../xcschemes/DynamicExample.xcscheme | 2 +- .../project.pbxproj | 2 +- .../xcschemes/XCFrameworkExample.xcscheme | 2 +- .../CarthageExample.xcodeproj/project.pbxproj | 2 +- .../xcschemes/CarthageExample.xcscheme | 2 +- .../project.pbxproj | 2 +- .../xcschemes/CocoaPodsExample.xcscheme | 2 +- .../DynamicExample.xcodeproj/project.pbxproj | 2 +- .../xcschemes/DynamicExample.xcscheme | 2 +- .../project.pbxproj | 2 +- .../xcschemes/XCFrameworkExample.xcscheme | 2 +- .../CarthageExample.xcodeproj/project.pbxproj | 2 +- .../xcschemes/CarthageExample.xcscheme | 2 +- .../xcshareddata/xcschemes/iOS.xcscheme | 2 +- .../project.pbxproj | 2 +- .../xcschemes/CocoaPodsExample.xcscheme | 2 +- .../xcshareddata/xcschemes/iOS.xcscheme | 2 +- .../DynamicExample.xcodeproj/project.pbxproj | 2 +- .../xcschemes/DynamicExample.xcscheme | 2 +- .../xcshareddata/xcschemes/iOS.xcscheme | 2 +- .../project.pbxproj | 2 +- .../xcschemes/XCFrameworkExample.xcscheme | 2 +- .../xcshareddata/xcschemes/iOS.xcscheme | 2 +- .../CarthageExample.xcodeproj/project.pbxproj | 2 +- .../xcschemes/CarthageExample.xcscheme | 2 +- .../xcshareddata/xcschemes/iOS.xcscheme | 2 +- .../project.pbxproj | 2 +- .../xcschemes/CocoaPodsExample.xcscheme | 2 +- .../xcshareddata/xcschemes/iOS.xcscheme | 2 +- .../DynamicExample.xcodeproj/project.pbxproj | 2 +- .../xcschemes/DynamicExample.xcscheme | 2 +- .../xcshareddata/xcschemes/iOS.xcscheme | 2 +- .../project.pbxproj | 2 +- .../xcschemes/XCFrameworkExample.xcscheme | 2 +- .../xcshareddata/xcschemes/iOS.xcscheme | 2 +- .../RealmExamples.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/xcschemes/Backlink.xcscheme | 6 +- .../xcshareddata/xcschemes/Draw.xcscheme | 6 +- .../xcschemes/Encryption.xcscheme | 6 +- .../xcshareddata/xcschemes/Extension.xcscheme | 6 +- .../xcschemes/GroupedTableView.xcscheme | 6 +- .../xcshareddata/xcschemes/Migration.xcscheme | 6 +- .../xcschemes/RACTableView.xcscheme | 4 +- .../xcshareddata/xcschemes/REST.xcscheme | 6 +- .../xcshareddata/xcschemes/Simple.xcscheme | 6 +- .../xcshareddata/xcschemes/TableView.xcscheme | 6 +- .../xcschemes/TodayExtension.xcscheme | 6 +- .../RealmExamples.xcodeproj/project.pbxproj | 2 +- .../xcshareddata/xcschemes/AppClip.xcscheme | 2 +- .../xcshareddata/xcschemes/Backlink.xcscheme | 6 +- .../xcschemes/Encryption.xcscheme | 6 +- .../xcschemes/GroupedTableView.xcscheme | 6 +- .../xcshareddata/xcschemes/Migration.xcscheme | 6 +- .../xcshareddata/xcschemes/Simple.xcscheme | 6 +- .../xcshareddata/xcschemes/TableView.xcscheme | 6 +- .../RealmExamples.xcodeproj/project.pbxproj | 11 +- .../xcschemes/JSONImport.xcscheme | 6 +- .../RealmExamples.xcodeproj/project.pbxproj | 2 +- .../xcschemes/DownloadCache.xcscheme | 6 +- .../xcschemes/PreloadedData.xcscheme | 6 +- .../RealmExamples.xcodeproj/project.pbxproj | 2 +- .../xcschemes/DownloadCache.xcscheme | 6 +- .../xcschemes/PreloadedData.xcscheme | 6 +- include/Realm/RLMSwiftObject.h | 1 + include/module.modulemap | 7 +- plugin/RealmPlugin.xcodeproj/project.pbxproj | 2 +- scripts/download-core.sh | 3 + 153 files changed, 671 insertions(+), 514 deletions(-) create mode 100644 Realm/RLMSwiftObject.h create mode 120000 include/Realm/RLMSwiftObject.h diff --git a/CHANGELOG.md b/CHANGELOG.md index b39a6403f8..8f4fb269b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ x.y.z Release notes (yyyy-MM-dd) * `UserPublisher` incorrectly bounced all notifications to the main thread instead of setting up the Combine publisher to correctly receive on the main thread. ([#8132](https://github.com/realm/realm-swift/issues/8132), since 10.21.0) +* Fix warnings when building with Xcode 14.3 beta 1. + ### Compatibility diff --git a/Configuration/Base.xcconfig b/Configuration/Base.xcconfig index 0a7d886e05..6a4910b71b 100644 --- a/Configuration/Base.xcconfig +++ b/Configuration/Base.xcconfig @@ -12,7 +12,6 @@ CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; -CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; // This is Xcode's typo CLANG_WARN_DUPLICATE_METHOD_MATCH = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; @@ -28,6 +27,7 @@ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; +CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; // This is Xcode's typo COMBINE_HIDPI_IMAGES = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; diff --git a/Realm.podspec b/Realm.podspec index f9a6658888..c9e23506df 100644 --- a/Realm.podspec +++ b/Realm.podspec @@ -75,7 +75,10 @@ Pod::Spec.new do |s| # Realm.Dynamic module 'include/RLMRealm_Dynamic.h', - 'include/RLMObjectBase_Dynamic.h' + 'include/RLMObjectBase_Dynamic.h', + + # Realm.Swift module + 'include/RLMSwiftObject.h' # Realm.Private module private_header_files = 'include/RLMAccessor.h', diff --git a/Realm.xcodeproj/project.pbxproj b/Realm.xcodeproj/project.pbxproj index a8e46d340c..8730ab76f5 100644 --- a/Realm.xcodeproj/project.pbxproj +++ b/Realm.xcodeproj/project.pbxproj @@ -240,6 +240,8 @@ 3FCB1A7522A9B0A2003807FB /* CodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FCB1A7422A9B0A2003807FB /* CodableTests.swift */; }; 3FD0D7CE2967CA1E0031C196 /* RLMMongoCollection_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = CF76F7D224816AAA00890DD2 /* RLMMongoCollection_Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; 3FD0D7CF2967CA1F0031C196 /* RLMMongoCollection_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = CF76F7D224816AAA00890DD2 /* RLMMongoCollection_Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 3FCC56E429A55607004C5057 /* RLMSwiftObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 3FCC56E329A55607004C5057 /* RLMSwiftObject.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 3FCC56E529A55607004C5057 /* RLMSwiftObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 3FCC56E329A55607004C5057 /* RLMSwiftObject.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3FDCFEB619F6A8D3005E414A /* RLMSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = E88C36FF19745E5500C9963D /* RLMSupport.swift */; }; 3FDE338D19C39A87003B7DBA /* RLMSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = E88C36FF19745E5500C9963D /* RLMSupport.swift */; }; 3FE267D5264308680030F83C /* CollectionAccess.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FE267CF264308670030F83C /* CollectionAccess.swift */; }; @@ -932,6 +934,7 @@ 3FC3F911241808B300E27322 /* RLMEmbeddedObject.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RLMEmbeddedObject.mm; sourceTree = ""; }; 3FC3F9162419B63100E27322 /* EmbeddedObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmbeddedObject.swift; sourceTree = ""; }; 3FCB1A7422A9B0A2003807FB /* CodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodableTests.swift; sourceTree = ""; }; + 3FCC56E329A55607004C5057 /* RLMSwiftObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RLMSwiftObject.h; sourceTree = ""; }; 3FE267CF264308670030F83C /* CollectionAccess.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionAccess.swift; sourceTree = ""; }; 3FE267D0264308680030F83C /* ComplexTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComplexTypes.swift; sourceTree = ""; }; 3FE267D1264308680030F83C /* BasicTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicTypes.swift; sourceTree = ""; }; @@ -1198,8 +1201,8 @@ E81A1FD11955FE0100FDED82 /* TransactionTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TransactionTests.m; sourceTree = ""; }; E8267FED1D90B79000E001C7 /* ObjectServerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ObjectServerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; E8267FF01D90B8E700E001C7 /* RLMObjectServerTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; name = RLMObjectServerTests.mm; path = Realm/ObjectServerTests/RLMObjectServerTests.mm; sourceTree = ""; }; - E82FA60A195632F20043A3C3 /* SwiftArrayPropertyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = SwiftArrayPropertyTests.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; - E82FA60B195632F20043A3C3 /* SwiftArrayTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = SwiftArrayTests.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + E82FA60A195632F20043A3C3 /* SwiftArrayPropertyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = SwiftArrayPropertyTests.swift; sourceTree = ""; }; + E82FA60B195632F20043A3C3 /* SwiftArrayTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = SwiftArrayTests.swift; sourceTree = ""; }; E82FA60D195632F20043A3C3 /* SwiftLinkTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = SwiftLinkTests.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; E82FA60F195632F20043A3C3 /* SwiftObjectInterfaceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = SwiftObjectInterfaceTests.swift; sourceTree = ""; }; E83591931B3DF05C0035F2F3 /* RLMAnalytics.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RLMAnalytics.mm; sourceTree = ""; }; @@ -1949,6 +1952,7 @@ CF986D1C25AE3B090039D287 /* RLMSet_Private.hpp */, 023B19551A3BA90D0067FB81 /* RLMSwiftCollectionBase.h */, 023B19561A3BA90D0067FB81 /* RLMSwiftCollectionBase.mm */, + 3FCC56E329A55607004C5057 /* RLMSwiftObject.h */, 3F83E9A22630A14800FC9623 /* RLMSwiftProperty.h */, 3FE79FF719BA6A5900780C9A /* RLMSwiftSupport.h */, 3F452EC519C2279800AFC154 /* RLMSwiftSupport.m */, @@ -2069,6 +2073,7 @@ CF986D2425AE3B090039D287 /* RLMSet.h in Headers */, CF986D1E25AE3B090039D287 /* RLMSet_Private.h in Headers */, 5D659EAE1BE04556006515A0 /* RLMSwiftCollectionBase.h in Headers */, + 3FCC56E429A55607004C5057 /* RLMSwiftObject.h in Headers */, 3F83E9A42630A14800FC9623 /* RLMSwiftProperty.h in Headers */, 5D659EC91BE04556006515A0 /* RLMSwiftSupport.h in Headers */, 3F1D9092265C07A600593ABA /* RLMSwiftValueStorage.h in Headers */, @@ -2158,6 +2163,7 @@ CF986D2525AE3B090039D287 /* RLMSet.h in Headers */, CF986D1F25AE3B090039D287 /* RLMSet_Private.h in Headers */, 5DD755AC1BE056DE002800DA /* RLMSwiftCollectionBase.h in Headers */, + 3FCC56E529A55607004C5057 /* RLMSwiftObject.h in Headers */, 3F34EC53268698BD000087A4 /* RLMSwiftProperty.h in Headers */, 5DD755C71BE056DE002800DA /* RLMSwiftSupport.h in Headers */, 3F1D9093265C07A700593ABA /* RLMSwiftValueStorage.h in Headers */, @@ -2437,10 +2443,11 @@ E8D89B8F1955FC6D00CF2B9A /* Project object */ = { isa = PBXProject; attributes = { + BuildIndependentTargetsInParallel = YES; CLASSPREFIX = RLM; LastSwiftUpdateCheck = 1230; LastTestingUpgradeCheck = 0510; - LastUpgradeCheck = 1410; + LastUpgradeCheck = 1430; ORGANIZATIONNAME = Realm; TargetAttributes = { 3F1A5E711992EB7400F45F4C = { diff --git a/Realm.xcodeproj/xcshareddata/xcschemes/Download BaaS.xcscheme b/Realm.xcodeproj/xcshareddata/xcschemes/Download BaaS.xcscheme index 0282b1e2ff..6464a60fee 100644 --- a/Realm.xcodeproj/xcshareddata/xcschemes/Download BaaS.xcscheme +++ b/Realm.xcodeproj/xcshareddata/xcschemes/Download BaaS.xcscheme @@ -1,6 +1,6 @@ String { } private extension Property { - func stitchRule(_ objectSchema: ObjectSchema) -> [String: Any] { + func stitchRule(_ objectSchema: ObjectSchema) -> [String: Json] { let type: String if self.type == .object { type = bsonType(objectSchema.primaryKeyProperty!.type) @@ -125,9 +125,26 @@ private extension Property { } } +// Swift 5.8 complains if collections are inferred as having type Any and adding +// explicit types everywhere makes things awful, but this doesn't quite work on +// older versions of Swift +#if swift(>=5.8) +internal protocol Json {} +extension Bool: Json {} +extension Int: Json {} +extension Int64: Json {} +extension String: Json {} +extension Double: Json {} +extension Dictionary: Json where Key == String, Value == Json {} +extension Array: Json where Element == Json {} +extension Optional: Json where Wrapped: Json {} +#else +typealias Json = Any +#endif + private extension ObjectSchema { - func stitchRule(_ partitionKeyType: String?, id: String? = nil) -> [String: Any] { - var stitchProperties: [String: Any] = [:] + func stitchRule(_ partitionKeyType: String?, id: String? = nil) -> [String: Json] { + var stitchProperties: [String: Json] = [:] // We only add a partition property for pbs if let partitionKeyType = partitionKeyType { @@ -136,7 +153,7 @@ private extension ObjectSchema { ] } - var relationships: [String: Any] = [:] + var relationships: [String: Json] = [:] // First pass we only add the properties to the schema as we can't add // links until the targets of the links exist. @@ -156,7 +173,7 @@ private extension ObjectSchema { } return [ - "_id": id as Any, + "_id": id as Json, "schema": [ "properties": stitchProperties, // The server currently only supports non-optional collections @@ -332,16 +349,16 @@ class AdminSession { request(httpMethod: "GET") } - func post(_ data: Any, _ completionHandler: @escaping Completion) { + func post(_ data: [String: Json], _ completionHandler: @escaping Completion) { request(httpMethod: "POST", data: data, completionHandler: completionHandler) } - func post(on group: DispatchGroup, _ data: Any, + func post(on group: DispatchGroup, _ data: [String: Json], _ completionHandler: @escaping Completion) { request(on: group, httpMethod: "POST", data: data, completionHandler) } - func post(_ data: Any) -> Result { + func post(_ data: [String: Json]) -> Result { request(httpMethod: "POST", data: data) } @@ -349,16 +366,16 @@ class AdminSession { request(httpMethod: "PUT", completionHandler: completionHandler) } - func put(on group: DispatchGroup, data: Any? = nil, + func put(on group: DispatchGroup, data: Json? = nil, _ completionHandler: @escaping Completion) { request(on: group, httpMethod: "PUT", data: data, completionHandler) } - func put(data: Any? = nil, _ completionHandler: @escaping Completion) { + func put(data: [String: Json]? = nil, _ completionHandler: @escaping Completion) { request(httpMethod: "PUT", data: data, completionHandler: completionHandler) } - func put(_ data: Any) -> Result { + func put(_ data: [String: Json]) -> Result { request(httpMethod: "PUT", data: data) } @@ -374,7 +391,7 @@ class AdminSession { request(httpMethod: "DELETE") } - func patch(on group: DispatchGroup, _ data: Any, + func patch(on group: DispatchGroup, _ data: [String: Json], _ completionHandler: @escaping Completion) { request(on: group, httpMethod: "PATCH", data: data, completionHandler) } @@ -383,7 +400,7 @@ class AdminSession { request(httpMethod: "PATCH", data: data) } - func patch(_ data: Any, _ completionHandler: @escaping Completion) { + func patch(_ data: [String: Json], _ completionHandler: @escaping Completion) { request(httpMethod: "PATCH", data: data, completionHandler: completionHandler) } } @@ -800,7 +817,7 @@ public class RealmServer: NSObject { "value": "mongodb://localhost:26000" ]) - let appService: [String: Any] = [ + let appService: [String: Json] = [ "name": "mongodb1", "type": "mongodb", "config": [ @@ -861,7 +878,7 @@ public class RealmServer: NSObject { } } - let serviceConfig: Any + let serviceConfig: [String: Json] switch syncMode { case .pbs(let bsonType): serviceConfig = [ @@ -884,8 +901,17 @@ public class RealmServer: NSObject { "flexible_sync": [ "state": "enabled", "database_name": "test_data", - "queryable_fields_names": fields, - "asymmetric_tables": asymmetricTables, + "queryable_fields_names": fields as [Json], + "asymmetric_tables": asymmetricTables as [Json], + "permissions": [ + "rules": [String: Json](), + "defaultRoles": [[ + "name": "all", + "applyWhen": [String: Json](), + "read": true, + "write": true + ]] + ] ] ] } @@ -895,10 +921,10 @@ public class RealmServer: NSObject { } if case .flx = syncMode { - let defaultRule = [ + let rulesConfigResponse = app.services[serviceId].default_rule.post([ "roles": [[ "name": "all", - "apply_when": [:], + "apply_when": [String: Json](), "document_filters": [ "read": true, "write": true @@ -908,8 +934,7 @@ public class RealmServer: NSObject { "insert": true, "delete": true ]] - ] - let rulesConfigResponse = app.services[serviceId].default_rule.post(defaultRule) + ]) guard case .success = rulesConfigResponse else { throw URLError(.badServerResponse) } @@ -950,7 +975,7 @@ public class RealmServer: NSObject { ], failOnError) let rules = app.services[serviceId].rules - let userDataRule: [String: Any] = [ + let userDataRule: [String: Json] = [ "database": "test_data", "collection": "UserData", "roles": [[ @@ -1081,7 +1106,7 @@ public class RealmServer: NSObject { } let app = session.apps[appServerId] let response = try app.services[syncServiceId].config.get().get() as? [String: Any] - guard let syncInfo = response?[configOption] as? [String: Any] else { + guard let syncInfo = response?[configOption] as? [String: Json] else { return false } return (syncInfo["state"] as? String == "enabled") @@ -1143,7 +1168,7 @@ public class RealmServer: NSObject { var syncConfig = syncServiceConfiguration return app.services[syncServiceId].config.get() .map { response in - guard let config = response as? [String: Any] else { return false } + guard let config = response as? [String: Json] else { return false } guard let syncInfo = config[configOption] as? [String: Any] else { return false } return syncInfo["is_recovery_mode_disabled"] as? Bool ?? false } @@ -1188,12 +1213,12 @@ public class RealmServer: NSObject { guard let schemasList = try? session.apps[appServerId].schemas.get().get(), let schemas = schemasList as? [[String: Any]], let schemaSelected = schemas.first(where: { ($0["metadata"] as? [String: String])?["collection"] == className }) else { - completion(.failure(URLError.unknown as! Error)) + completion(.failure(URLError(.unknown))) return } guard let schema = try? session.apps[appServerId].schemas[schemaSelected["_id"] as! String].get().get(), - let schemaProperties = ((schema as? [String: Any])?["schema"] as? [String: Any])?["properties"] as? [String: Any] else { + let schemaProperties = ((schema as? [String: Json])?["schema"] as? [String: Any])?["properties"] as? [String: Json] else { completion(.failure(URLError.unknown as! Error)) return } diff --git a/Realm/ObjectServerTests/SwiftAsymmetricSyncServerTests.swift b/Realm/ObjectServerTests/SwiftAsymmetricSyncServerTests.swift index 7ad790fb90..04a8eb4998 100644 --- a/Realm/ObjectServerTests/SwiftAsymmetricSyncServerTests.swift +++ b/Realm/ObjectServerTests/SwiftAsymmetricSyncServerTests.swift @@ -84,9 +84,8 @@ class SwiftObjectAsymmetric: AsymmetricObject { return true } - convenience init(id: ObjectId, string: String, int: Int, bool: Bool) { + convenience init(string: String, int: Int, bool: Bool) { self.init() - self._id = id self.string = string self.int = int self.bool = bool @@ -237,10 +236,9 @@ extension SwiftAsymmetricSyncTests { // Create Asymmetric Objects try realm.write { for i in 1...15 { - realm.create(SwiftObjectAsymmetric.self, value: ["id": ObjectId.generate(), - "string": "name_\(#function)_\(i)", - "int": i, - "bool": Bool.random()]) + realm.create(SwiftObjectAsymmetric.self, + value: SwiftObjectAsymmetric(string: "name_\(#function)_\(i)", + int: i, bool: Bool.random())) } } waitForUploads(for: realm) @@ -258,10 +256,9 @@ extension SwiftAsymmetricSyncTests { // Create Asymmetric Objects try realm.write { - realm.create(SwiftObjectAsymmetric.self, value: ["id": ObjectId.generate(), - "string": "name_\(#function)", - "int": 15, - "bool": true]) + realm.create(SwiftObjectAsymmetric.self, + value: SwiftObjectAsymmetric(string: "name_\(#function)", + int: 15, bool: true)) } waitForUploads(for: realm) diff --git a/Realm/ObjectServerTests/SwiftObjectServerTests.swift b/Realm/ObjectServerTests/SwiftObjectServerTests.swift index d3eb5acef0..072e40221f 100644 --- a/Realm/ObjectServerTests/SwiftObjectServerTests.swift +++ b/Realm/ObjectServerTests/SwiftObjectServerTests.swift @@ -2088,8 +2088,8 @@ class SwiftObjectServerTests: SwiftSyncTestCase { // Make sure objects with confliciting primary keys sync ok. let conflictingObjectId = ObjectId.generate() - let person = SwiftPerson(value: ["_id": conflictingObjectId, - "firstName": "Foo", "lastName": "Bar"]) + let person = SwiftPerson(firstName: "Foo", lastName: "Bar") + person._id = conflictingObjectId let initialRealm = try Realm(configuration: initialSyncConfig) try initialRealm.write { initialRealm.add(person) @@ -2107,8 +2107,8 @@ class SwiftObjectServerTests: SwiftSyncTestCase { let localRealm = try Realm(configuration: localConfig) // `person2` will override what was previously stored on the server. - let person2 = SwiftPerson(value: ["_id": conflictingObjectId, - "firstName": "John", "lastName": "Doe"]) + let person2 = SwiftPerson(firstName: "John", lastName: "Doe") + person2._id = conflictingObjectId try localRealm.write { localRealm.add(person2) localRealm.add(SwiftPerson(firstName: "Foo3", lastName: "Bar3")) diff --git a/Realm/ObjectServerTests/SwiftServerObjects.swift b/Realm/ObjectServerTests/SwiftServerObjects.swift index 0cf988691f..60dbc4a7e2 100644 --- a/Realm/ObjectServerTests/SwiftServerObjects.swift +++ b/Realm/ObjectServerTests/SwiftServerObjects.swift @@ -40,7 +40,7 @@ public class LinkToSwiftPerson: Object { @Persisted public var peopleByName: Map } -@available(OSX 10.15, watchOS 6.0, iOS 13.0, iOSApplicationExtension 13.0, OSXApplicationExtension 10.15, tvOS 13.0, *) +@available(macOS 10.15, *) extension SwiftPerson: ObjectKeyIdentifiable {} public class SwiftTypesSyncObject: Object { diff --git a/Realm/ObjectServerTests/SwiftSyncTestCase.swift b/Realm/ObjectServerTests/SwiftSyncTestCase.swift index dc852f6537..ad078e60cc 100644 --- a/Realm/ObjectServerTests/SwiftSyncTestCase.swift +++ b/Realm/ObjectServerTests/SwiftSyncTestCase.swift @@ -54,6 +54,7 @@ public enum ProcessKind { } } +@available(macOS 10.15, *) @MainActor open class SwiftSyncTestCase: RLMSyncTestCase { public func executeChild(file: StaticString = #file, line: UInt = #line) { diff --git a/Realm/RLMAsymmetricObject.h b/Realm/RLMAsymmetricObject.h index e2b4e7210a..09deb787e1 100644 --- a/Realm/RLMAsymmetricObject.h +++ b/Realm/RLMAsymmetricObject.h @@ -20,7 +20,7 @@ RLM_HEADER_AUDIT_BEGIN(nullability, sendability) -@class RLMObjectSchema, RLMPropertyDescriptor; +@class RLMObjectSchema, RLMPropertyDescriptor, RLMRealm; /** `RLMAsymmetricObject` is a base class used to define asymmetric Realm objects. diff --git a/Realm/RLMBSON_Private.hpp b/Realm/RLMBSON_Private.hpp index c0638124ce..daa9065713 100644 --- a/Realm/RLMBSON_Private.hpp +++ b/Realm/RLMBSON_Private.hpp @@ -16,16 +16,14 @@ // //////////////////////////////////////////////////////////////////////////// -#import "RLMBSON.h" +#import #import -namespace realm { -namespace bson { +namespace realm::bson { class Bson; template class IndexedMap; using BsonDocument = IndexedMap; } -} realm::bson::Bson RLMConvertRLMBSONToBson(id b); id RLMConvertBsonToRLMBSON(const realm::bson::Bson& b); diff --git a/Realm/RLMObjectBase.h b/Realm/RLMObjectBase.h index afbc6768d9..7e9c83c8fe 100644 --- a/Realm/RLMObjectBase.h +++ b/Realm/RLMObjectBase.h @@ -20,10 +20,6 @@ RLM_HEADER_AUDIT_BEGIN(nullability, sendability) -@class RLMRealm; -@class RLMSchema; -@class RLMObjectSchema; - /// :nodoc: @interface RLMObjectBase : NSObject @@ -41,123 +37,4 @@ RLM_HEADER_AUDIT_BEGIN(nullability, sendability) @end -/** - `Object` is a class used to define Realm model objects. - - In Realm you define your model classes by subclassing `Object` and adding properties to be managed. - You then instantiate and use your custom subclasses instead of using the `Object` class directly. - - ```swift - class Dog: Object { - @objc dynamic var name: String = "" - @objc dynamic var adopted: Bool = false - let siblings = List() - } - ``` - - ### Supported property types - - - `String`, `NSString` - - `Int` - - `Int8`, `Int16`, `Int32`, `Int64` - - `Float` - - `Double` - - `Bool` - - `Date`, `NSDate` - - `Data`, `NSData` - - `Decimal128` - - `ObjectId` - - `@objc enum` which has been delcared as conforming to `RealmEnum`. - - `RealmOptional` for optional numeric properties - - `Object` subclasses, to model many-to-one relationships - - `EmbeddedObject` subclasses, to model owning one-to-one relationships - - `List`, to model many-to-many relationships - - `String`, `NSString`, `Date`, `NSDate`, `Data`, `NSData`, `Decimal128`, and `ObjectId` properties - can be declared as optional. `Object` and `EmbeddedObject` subclasses *must* be declared as optional. - `Int`, `Int8`, `Int16`, `Int32`, `Int64`, `Float`, `Double`, `Bool`, enum, and `List` properties cannot. - To store an optional number, use `RealmOptional`, `RealmOptional`, `RealmOptional`, or - `RealmOptional` instead, which wraps an optional numeric value. Lists cannot be optional at all. - - All property types except for `List` and `RealmOptional` *must* be declared as `@objc dynamic var`. `List` and - `RealmOptional` properties must be declared as non-dynamic `let` properties. Swift `lazy` properties are not allowed. - - Note that none of the restrictions listed above apply to properties that are configured to be ignored by Realm. - - ### Querying - - You can retrieve all objects of a given type from a Realm by calling the `objects(_:)` instance method. - - ### Relationships - - See our [Objective-C guide](https://docs.mongodb.com/realm/sdk/swift/fundamentals/relationships/) for more details. - */ -@interface RealmSwiftObject : RLMObjectBase -@end - -/** - `EmbeddedObject` is a base class used to define embedded Realm model objects. - - Embedded objects work similarly to normal objects, but are owned by a single - parent Object (which itself may be embedded). Unlike normal top-level objects, - embedded objects cannot be directly created in or added to a Realm. Instead, - they can only be created as part of a parent object, or by assigning an - unmanaged object to a parent object's property. Embedded objects are - automatically deleted when the parent object is deleted or when the parent is - modified to no longer point at the embedded object, either by reassigning an - Object property or by removing the embedded object from the List containing it. - - Embedded objects can only ever have a single parent object which links to - them, and attempting to link to an existing managed embedded object will throw - an exception. - - The property types supported on `EmbeddedObject` are the same as for `Object`, - except for that embedded objects cannot link to top-level objects, so `Object` - and `List` properties are not supported (`EmbeddedObject` and - `List` *are*). - - Embedded objects cannot have primary keys or indexed properties. - - ```swift - class Owner: Object { - @objc dynamic var name: String = "" - let dogs = List() - } - class Dog: EmbeddedObject { - @objc dynamic var name: String = "" - @objc dynamic var adopted: Bool = false - let owner = LinkingObjects(fromType: Owner.self, property: "dogs") - } - ``` - */ -@interface RealmSwiftEmbeddedObject : RLMObjectBase -@end - -/** - `AsymmetricObject` is a base class used to define asymmetric Realm objects. - - Asymmetric objects can only be created using the `create(_ object:)` - function, and cannot be added, removed or queried. - When created, asymmetric objects will be synced unidirectionally to the MongoDB - database and cannot be accessed locally. - - Incoming links from any asymmetric table are not allowed, meaning embedding - an asymmetric object within an `Object` will throw an error. - - The property types supported on `AsymmetricObject` are the same as for `Object`, - except for that asymmetric objects can only link to embedded objects, so `Object` - and `List` properties are not supported (`EmbeddedObject` and - `List` *are*). - - ```swift - class Person: AsymmetricObject { - @Persisted(primaryKey: true) var _id: ObjectId = ObjectId.generate() - @Persisted var name: String - @Persisted var age: Int - } - ``` - */ -@interface RealmSwiftAsymmetricObject : RLMObjectBase -@end - RLM_HEADER_AUDIT_END(nullability, sendability) diff --git a/Realm/RLMObject_Private.h b/Realm/RLMObject_Private.h index 6ca5a6e4b0..72a624b20e 100644 --- a/Realm/RLMObject_Private.h +++ b/Realm/RLMObject_Private.h @@ -20,7 +20,7 @@ RLM_HEADER_AUDIT_BEGIN(nullability, sendability) -@class RLMProperty, RLMArray; +@class RLMProperty, RLMArray, RLMSchema; typedef NS_ENUM(int32_t, RLMPropertyType); FOUNDATION_EXTERN void RLMInitializeWithValue(RLMObjectBase *, id, RLMSchema *); diff --git a/Realm/RLMObject_Private.hpp b/Realm/RLMObject_Private.hpp index 3e22b1e018..42dea96950 100644 --- a/Realm/RLMObject_Private.hpp +++ b/Realm/RLMObject_Private.hpp @@ -18,6 +18,7 @@ #import "RLMObject_Private.h" +#import "RLMSwiftObject.h" #import "RLMRealm_Private.hpp" #import "RLMUtil.hpp" diff --git a/Realm/RLMSwiftObject.h b/Realm/RLMSwiftObject.h new file mode 100644 index 0000000000..7ea764016c --- /dev/null +++ b/Realm/RLMSwiftObject.h @@ -0,0 +1,142 @@ +//////////////////////////////////////////////////////////////////////////// +// +// Copyright 2023 Realm Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////// + +#import + +RLM_HEADER_AUDIT_BEGIN(nullability, sendability) +/** + `Object` is a class used to define Realm model objects. + + In Realm you define your model classes by subclassing `Object` and adding properties to be managed. + You then instantiate and use your custom subclasses instead of using the `Object` class directly. + + ```swift + class Dog: Object { + @objc dynamic var name: String = "" + @objc dynamic var adopted: Bool = false + let siblings = List() + } + ``` + + ### Supported property types + + - `String`, `NSString` + - `Int` + - `Int8`, `Int16`, `Int32`, `Int64` + - `Float` + - `Double` + - `Bool` + - `Date`, `NSDate` + - `Data`, `NSData` + - `Decimal128` + - `ObjectId` + - `@objc enum` which has been delcared as conforming to `RealmEnum`. + - `RealmOptional` for optional numeric properties + - `Object` subclasses, to model many-to-one relationships + - `EmbeddedObject` subclasses, to model owning one-to-one relationships + - `List`, to model many-to-many relationships + + `String`, `NSString`, `Date`, `NSDate`, `Data`, `NSData`, `Decimal128`, and `ObjectId` properties + can be declared as optional. `Object` and `EmbeddedObject` subclasses *must* be declared as optional. + `Int`, `Int8`, `Int16`, `Int32`, `Int64`, `Float`, `Double`, `Bool`, enum, and `List` properties cannot. + To store an optional number, use `RealmOptional`, `RealmOptional`, `RealmOptional`, or + `RealmOptional` instead, which wraps an optional numeric value. Lists cannot be optional at all. + + All property types except for `List` and `RealmOptional` *must* be declared as `@objc dynamic var`. `List` and + `RealmOptional` properties must be declared as non-dynamic `let` properties. Swift `lazy` properties are not allowed. + + Note that none of the restrictions listed above apply to properties that are configured to be ignored by Realm. + + ### Querying + + You can retrieve all objects of a given type from a Realm by calling the `objects(_:)` instance method. + + ### Relationships + + See our [Objective-C guide](https://docs.mongodb.com/realm/sdk/swift/fundamentals/relationships/) for more details. + */ +@interface RealmSwiftObject : RLMObjectBase +@end + +/** + `EmbeddedObject` is a base class used to define embedded Realm model objects. + + Embedded objects work similarly to normal objects, but are owned by a single + parent Object (which itself may be embedded). Unlike normal top-level objects, + embedded objects cannot be directly created in or added to a Realm. Instead, + they can only be created as part of a parent object, or by assigning an + unmanaged object to a parent object's property. Embedded objects are + automatically deleted when the parent object is deleted or when the parent is + modified to no longer point at the embedded object, either by reassigning an + Object property or by removing the embedded object from the List containing it. + + Embedded objects can only ever have a single parent object which links to + them, and attempting to link to an existing managed embedded object will throw + an exception. + + The property types supported on `EmbeddedObject` are the same as for `Object`, + except for that embedded objects cannot link to top-level objects, so `Object` + and `List` properties are not supported (`EmbeddedObject` and + `List` *are*). + + Embedded objects cannot have primary keys or indexed properties. + + ```swift + class Owner: Object { + @objc dynamic var name: String = "" + let dogs = List() + } + class Dog: EmbeddedObject { + @objc dynamic var name: String = "" + @objc dynamic var adopted: Bool = false + let owner = LinkingObjects(fromType: Owner.self, property: "dogs") + } + ``` + */ +@interface RealmSwiftEmbeddedObject : RLMObjectBase +@end + +/** + `AsymmetricObject` is a base class used to define asymmetric Realm objects. + + Asymmetric objects can only be created using the `create(_ object:)` + function, and cannot be added, removed or queried. + When created, asymmetric objects will be synced unidirectionally to the MongoDB + database and cannot be accessed locally. + + Incoming links from any asymmetric table are not allowed, meaning embedding + an asymmetric object within an `Object` will throw an error. + + The property types supported on `AsymmetricObject` are the same as for `Object`, + except for that asymmetric objects can only link to embedded objects, so `Object` + and `List` properties are not supported (`EmbeddedObject` and + `List` *are*). + + ```swift + class Person: AsymmetricObject { + @Persisted(primaryKey: true) var _id: ObjectId = ObjectId.generate() + @Persisted var name: String + @Persisted var age: Int + } + ``` + */ +@interface RealmSwiftAsymmetricObject : RLMObjectBase +@end + +RLM_HEADER_AUDIT_END(nullability, sendability) + diff --git a/Realm/RLMUser.mm b/Realm/RLMUser.mm index 5bcdafcfc3..3fa20a1734 100644 --- a/Realm/RLMUser.mm +++ b/Realm/RLMUser.mm @@ -418,7 +418,7 @@ - (RLMUserProfile *)profile { return _user; } -- (RLMUserSubscriptionToken *)subscribe:(RLMUserNotificationBlock) block { +- (RLMUserSubscriptionToken *)subscribe:(RLMUserNotificationBlock)block { return [[RLMUserSubscriptionToken alloc] initWithToken:_user->subscribe([block, self] (auto&) { block(self); })]; diff --git a/Realm/Realm.modulemap b/Realm/Realm.modulemap index 20ab298d14..117f1c537b 100644 --- a/Realm/Realm.modulemap +++ b/Realm/Realm.modulemap @@ -1,8 +1,51 @@ framework module Realm { + export Foundation + umbrella header "Realm.h" - export * - module * { export * } + header "RLMArray.h" + header "RLMAsymmetricObject.h" + header "RLMDecimal128.h" + header "RLMDictionary.h" + header "RLMEmbeddedObject.h" + header "RLMMigration.h" + header "RLMObject.h" + header "RLMObjectId.h" + header "RLMObjectSchema.h" + header "RLMPlatform.h" + header "RLMProperty.h" + header "RLMProviderClient.h" + header "RLMRealm+Sync.h" + header "RLMRealm.h" + header "RLMRealmConfiguration.h" + header "RLMResults.h" + header "RLMSchema.h" + header "RLMSectionedResults.h" + header "RLMSet.h" + header "RLMValue.h" + + header "RLMApp.h" + header "RLMCredentials.h" + header "RLMNetworkTransport.h" + header "RLMPushClient.h" + header "RLMRealm+Sync.h" + header "RLMSyncConfiguration.h" + header "RLMSyncManager.h" + header "RLMSyncSession.h" + header "RLMUser.h" + header "RLMSyncUtil.h" + header "RLMUserAPIKey.h" + header "RLMAPIKeyAuth.h" + header "RLMEmailPasswordAuth.h" + header "NSError+RLMSync.h" + header "RLMBSON.h" + header "RLMMongoClient.h" + header "RLMMongoDatabase.h" + header "RLMMongoCollection.h" + header "RLMUpdateResult.h" + header "RLMFindOptions.h" + header "RLMFindOneAndModifyOptions.h" + header "RLMSyncSubscription.h" explicit module Private { header "RLMAccessor.h" @@ -37,4 +80,8 @@ framework module Realm { header "RLMRealm_Dynamic.h" header "RLMObjectBase_Dynamic.h" } + + explicit module Swift { + header "RLMSwiftObject.h" + } } diff --git a/Realm/TestUtils/RLMTestCase.m b/Realm/TestUtils/RLMTestCase.m index 1095748de9..d3da8c0d51 100644 --- a/Realm/TestUtils/RLMTestCase.m +++ b/Realm/TestUtils/RLMTestCase.m @@ -23,7 +23,7 @@ #import #import -static NSString *parentProcessBundleIdentifier() +static NSString *parentProcessBundleIdentifier(void) { static BOOL hasInitializedIdentifier; static NSString *identifier; @@ -35,11 +35,11 @@ return identifier; } -NSURL *RLMDefaultRealmURL() { +NSURL *RLMDefaultRealmURL(void) { return [NSURL fileURLWithPath:RLMRealmPathForFileAndBundleIdentifier(@"default.realm", parentProcessBundleIdentifier())]; } -NSURL *RLMTestRealmURL() { +NSURL *RLMTestRealmURL(void) { return [NSURL fileURLWithPath:RLMRealmPathForFileAndBundleIdentifier(@"test.realm", parentProcessBundleIdentifier())]; } @@ -54,13 +54,13 @@ static void deleteOrThrow(NSURL *fileURL) { } } -NSData *RLMGenerateKey() { +NSData *RLMGenerateKey(void) { uint8_t buffer[64]; (void)SecRandomCopyBytes(kSecRandomDefault, 64, buffer); return [[NSData alloc] initWithBytes:buffer length:sizeof(buffer)]; } -static BOOL encryptTests() { +static BOOL encryptTests(void) { static BOOL encryptAll = NO; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ diff --git a/Realm/Tests/ArrayPropertyTests.m b/Realm/Tests/ArrayPropertyTests.m index 4acdf17534..f371e84502 100644 --- a/Realm/Tests/ArrayPropertyTests.m +++ b/Realm/Tests/ArrayPropertyTests.m @@ -1403,7 +1403,7 @@ - (void)testDeletingObjectWithNotificationsRegistered { [(RLMNotificationToken *)token invalidate]; } -static RLMArray *managedTestArray() { +static RLMArray *managedTestArray(void) { RLMRealm *realm = [RLMRealm defaultRealm]; __block RLMArray *array; [realm transactionWithBlock:^{ diff --git a/Realm/Tests/DictionaryPropertyTests.m b/Realm/Tests/DictionaryPropertyTests.m index fb2e39919f..23a7b3144f 100644 --- a/Realm/Tests/DictionaryPropertyTests.m +++ b/Realm/Tests/DictionaryPropertyTests.m @@ -1330,7 +1330,7 @@ - (void)testDeletingObjectWithNotificationsRegistered { [(RLMNotificationToken *)token invalidate]; } -static RLMDictionary *managedTestDictionary() { +static RLMDictionary *managedTestDictionary(void) { RLMRealm *realm = [RLMRealm defaultRealm]; RLMDictionary *dict; [realm beginWriteTransaction]; diff --git a/Realm/Tests/Swift/SwiftArrayPropertyTests.swift b/Realm/Tests/Swift/SwiftArrayPropertyTests.swift index cbd5cf3a14..b3fac60f76 100644 --- a/Realm/Tests/Swift/SwiftArrayPropertyTests.swift +++ b/Realm/Tests/Swift/SwiftArrayPropertyTests.swift @@ -23,6 +23,28 @@ import Realm import RealmTestSupport #endif +extension RLMObject { + @discardableResult + class func create(in realm: RLMRealm, withValue value: [Any]) -> Self { + create(in: realm, withValue: value as Any) + } + + @discardableResult + class func createInDefaultRealm(withValue value: [Any]) -> Self { + createInDefaultRealm(withValue: value as Any) + } + + @discardableResult + class func createOrUpdate(in realm: RLMRealm, withValue value: [Any]) -> Self { + create(in: realm, withValue: value as Any) + } + + @discardableResult + class func createOrUpdateInDefaultRealm(withValue value: [Any]) -> Self { + createOrUpdateInDefaultRealm(withValue: value as Any) + } +} + class SwiftRLMArrayPropertyTests: RLMTestCase { // Swift models @@ -60,7 +82,7 @@ class SwiftRLMArrayPropertyTests: RLMTestCase { let realm = realmWithTestPath() realm.beginWriteTransaction() - let array = SwiftRLMArrayPropertyObject.create(in: realm, withValue: ["arrayObject", [], []]) + let array = SwiftRLMArrayPropertyObject.create(in: realm, withValue: ["arrayObject"]) XCTAssertNotNil(array.array, "Should be able to get an empty array") XCTAssertEqual(array.array.count, UInt(0), "Should start with no array elements") @@ -84,7 +106,7 @@ class SwiftRLMArrayPropertyTests: RLMTestCase { func testModifyDetatchedArray() { let realm = realmWithTestPath() realm.beginWriteTransaction() - let arObj = SwiftRLMArrayPropertyObject.create(in: realm, withValue: ["arrayObject", [], []]) + let arObj = SwiftRLMArrayPropertyObject.create(in: realm, withValue: ["arrayObject"]) XCTAssertNotNil(arObj.array, "Should be able to get an empty array") XCTAssertEqual(arObj.array.count, UInt(0), "Should start with no array elements") @@ -105,7 +127,7 @@ class SwiftRLMArrayPropertyTests: RLMTestCase { realm.beginWriteTransaction() - let obj = SwiftRLMArrayPropertyObject.create(in: realm, withValue: ["arrayObject", [], []]) + let obj = SwiftRLMArrayPropertyObject.create(in: realm, withValue: ["arrayObject"]) let child1 = SwiftRLMStringObject.create(in: realm, withValue: ["a"]) let child2 = SwiftRLMStringObject() child2.stringCol = "b" @@ -171,7 +193,7 @@ class SwiftRLMArrayPropertyTests: RLMTestCase { let realm = realmWithTestPath() realm.beginWriteTransaction() - let array = ArrayPropertyObject.create(in: realm, withValue: ["arrayObject", [], []]) + let array = ArrayPropertyObject.create(in: realm, withValue: ["arrayObject"]) XCTAssertNotNil(array.array, "Should be able to get an empty array") XCTAssertEqual(array.array.count, UInt(0), "Should start with no array elements") @@ -195,7 +217,7 @@ class SwiftRLMArrayPropertyTests: RLMTestCase { func testModifyDetatchedArray_objc() { let realm = realmWithTestPath() realm.beginWriteTransaction() - let arObj = ArrayPropertyObject.create(in: realm, withValue: ["arrayObject", [], []]) + let arObj = ArrayPropertyObject.create(in: realm, withValue: ["arrayObject"]) XCTAssertNotNil(arObj.array, "Should be able to get an empty array") XCTAssertEqual(arObj.array.count, UInt(0), "Should start with no array elements") @@ -216,7 +238,7 @@ class SwiftRLMArrayPropertyTests: RLMTestCase { realm.beginWriteTransaction() - let obj = ArrayPropertyObject.create(in: realm, withValue: ["arrayObject", [], []]) + let obj = ArrayPropertyObject.create(in: realm, withValue: ["arrayObject"]) let child1 = StringObject.create(in: realm, withValue: ["a"]) let child2 = StringObject() child2.stringCol = "b" diff --git a/Realm/Tests/Swift/SwiftObjectInterfaceTests.swift b/Realm/Tests/Swift/SwiftObjectInterfaceTests.swift index 349418e197..a9c1723c50 100644 --- a/Realm/Tests/Swift/SwiftObjectInterfaceTests.swift +++ b/Realm/Tests/Swift/SwiftObjectInterfaceTests.swift @@ -154,7 +154,7 @@ class SwiftRLMObjectInterfaceTests: RLMTestCase { try! realm.transaction { // create self referencing subclass - let sub = SwiftRLMSelfRefrencingSubclass.createInDefaultRealm(withValue: ["string", []]) + let sub = SwiftRLMSelfRefrencingSubclass.createInDefaultRealm(withValue: ["string"]) let sub2 = SwiftRLMSelfRefrencingSubclass() sub.objects.add(sub2) sub.objectSet.add(sub2) @@ -384,17 +384,17 @@ class SwiftRLMObjectInterfaceTests: RLMTestCase { func testCreateOrUpdate() { let realm = RLMRealm.default() realm.beginWriteTransaction() - _ = SwiftRLMPrimaryStringObject.createOrUpdateInDefaultRealm(withValue: ["string", 1]) - let objects = SwiftRLMPrimaryStringObject.allObjects() + SwiftRLMPrimaryStringObject.createOrUpdateInDefaultRealm(withValue: ["string", 1]) + let objects = SwiftRLMPrimaryStringObject.allObjects() as! RLMResults XCTAssertEqual(objects.count, UInt(1), "Should have 1 object") - XCTAssertEqual((objects[0] as! SwiftRLMPrimaryStringObject).intCol, 1, "Value should be 1") + XCTAssertEqual(objects[0].intCol, 1, "Value should be 1") - _ = SwiftRLMPrimaryStringObject.createOrUpdateInDefaultRealm(withValue: ["stringCol": "string2", "intCol": 2]) + SwiftRLMPrimaryStringObject.createOrUpdateInDefaultRealm(withValue: ["string2", 2]) XCTAssertEqual(objects.count, UInt(2), "Should have 2 objects") - _ = SwiftRLMPrimaryStringObject.createOrUpdateInDefaultRealm(withValue: ["string", 3]) + SwiftRLMPrimaryStringObject.createOrUpdateInDefaultRealm(withValue: ["string", 3]) XCTAssertEqual(objects.count, UInt(2), "Should have 2 objects") - XCTAssertEqual((objects[0] as! SwiftRLMPrimaryStringObject).intCol, 3, "Value should be 3") + XCTAssertEqual(objects[0].intCol, 3, "Value should be 3") try! realm.commitWriteTransaction() } @@ -402,7 +402,7 @@ class SwiftRLMObjectInterfaceTests: RLMTestCase { func testObjectForPrimaryKey() { let realm = RLMRealm.default() realm.beginWriteTransaction() - _ = SwiftRLMPrimaryStringObject.createOrUpdateInDefaultRealm(withValue: ["string", 1]) + SwiftRLMPrimaryStringObject.createOrUpdateInDefaultRealm(withValue: ["string", 1]) let obj = SwiftRLMPrimaryStringObject.object(forPrimaryKey: "string") XCTAssertNotNil(obj!) diff --git a/Realm/Tests/Swift/SwiftRLMDictionaryTests.swift b/Realm/Tests/Swift/SwiftRLMDictionaryTests.swift index ea1c950c05..06bfcecf9c 100644 --- a/Realm/Tests/Swift/SwiftRLMDictionaryTests.swift +++ b/Realm/Tests/Swift/SwiftRLMDictionaryTests.swift @@ -91,7 +91,7 @@ class SwiftRLMDictionaryTests: RLMTestCase { "7": [1, 0 as Float, 2.5 as Double, false, dateMaxInput], "8": [0, 1.2 as Float, 0 as Double, true, dateMinInput], "9": [0, 1.2 as Float, 0 as Double, true, dateMinInput] - ]]) + ] as [String: [Any]]]) try! realm.commitWriteTransaction() XCTAssertEqual(dObj.dict.count, UInt(10), "10 objects added") @@ -266,7 +266,7 @@ class SwiftRLMDictionaryTests: RLMTestCase { "7": [10, 0 as Float, 2.5 as Double, false, dateMaxInput], "8": [10, 1.2 as Float, 0 as Double, true, dateMinInput], "9": [10, 1.2 as Float, 0 as Double, true, dateMinInput] - ]]) + ] as [String: [Any]]]) try! realm.commitWriteTransaction() XCTAssertEqual(dObj.dictionary!.count, UInt(10), "10 objects added") @@ -297,7 +297,7 @@ class SwiftRLMDictionaryTests: RLMTestCase { "7": [1, 0 as Float, 2.5 as Double, false, dateMaxInput], "8": [0, 1.2 as Float, 0 as Double, true, dateMinInput], "9": [0, 1.2 as Float, 0 as Double, true, dateMinInput] - ]]) + ] as [String: [Any]]]) try! realm.commitWriteTransaction() XCTAssertEqual(dObj.dictionary!.count, UInt(10), "10 objects added") @@ -403,17 +403,12 @@ class SwiftRLMDictionaryTests: RLMTestCase { } func makeRlmEmployee(_ realm: RLMRealm, _ age: Int32, _ name: String, _ hired: Bool) -> SwiftRLMEmployeeObject { - let employee = SwiftRLMEmployeeObject.create(in: realm, withValue: ["age": age, - "name": name, - "hired": hired]) - return employee + return SwiftRLMEmployeeObject.create(in: realm, withValue: [name, age, hired]) } func makeEmployee(_ realm: RLMRealm, _ age: Int32, _ name: String, _ hired: Bool) -> EmployeeObject { - let employee = EmployeeObject.create(in: realm, withValue: ["age": age, - "name": name, - "hired": hired]) - return employee + return EmployeeObject.create(in: realm, + withValue: ["age": age, "name": name, "hired": hired] as [String: Any]) } func testDeleteLinksAndObjectsInDictionary_objc() { @@ -423,10 +418,10 @@ class SwiftRLMDictionaryTests: RLMTestCase { let po1 = makeEmployee(realm, 40, "Joe", true) let po2 = makeEmployee(realm, 30, "John", false) let po3 = makeEmployee(realm, 25, "Jill", true) - let company = CompanyObject.create(in: realm, withValue: ["employeeDict": - ["Joe": po1, - "John": po2, - "Jill": po3]]) + let company = CompanyObject.create(in: realm, withValue: ["employeeDict": [ + "Joe": po1, + "John": po2, + "Jill": po3]]) try! realm.commitWriteTransaction() let peopleInCompany = company.employeeDict! diff --git a/Realm/Tests/Swift/SwiftRealmTests.swift b/Realm/Tests/Swift/SwiftRealmTests.swift index cf7bbf1064..2d80aa7a06 100644 --- a/Realm/Tests/Swift/SwiftRealmTests.swift +++ b/Realm/Tests/Swift/SwiftRealmTests.swift @@ -23,6 +23,7 @@ import Realm import RealmTestSupport #endif +@available(iOS 13.0, *) // For @MainActor @MainActor class SwiftRLMRealmTests: RLMTestCase { diff --git a/Realm/Tests/Swift/SwiftSchemaTests.swift b/Realm/Tests/Swift/SwiftSchemaTests.swift index 1a8af03774..dbb8474899 100644 --- a/Realm/Tests/Swift/SwiftSchemaTests.swift +++ b/Realm/Tests/Swift/SwiftSchemaTests.swift @@ -190,7 +190,7 @@ class SwiftRLMSchemaTests: RLMMultiProcessTestCase { _ = SwiftRLMLinkedNonDefaultObject(value: [[1]]) _ = SwiftRLMNonDefaultArrayObject(value: [[[1]]]) _ = SwiftRLMNonDefaultSetObject(value: [[[1]]]) - _ = SwiftRLMMutualLink1Object(value: [[[:]]]) + _ = SwiftRLMMutualLink1Object() } func testCreateUnmanagedObjectWhichCreatesAnotherClassViaInitWithValueDuringSchemaInit() { @@ -200,7 +200,7 @@ class SwiftRLMSchemaTests: RLMMultiProcessTestCase { } _ = InitLinkedToClass(value: [[0]]) - _ = SwiftRLMCompanyObject(value: [[["Jaden", 20, false]]]) + _ = SwiftRLMCompanyObject(value: [[["Jaden", 20, false] as [Any]]]) } func testInitUnmanagedObjectNotInClassSubsetDuringSchemaInit() { diff --git a/Realm/Tests/Swift/SwiftSetPropertyTests.swift b/Realm/Tests/Swift/SwiftSetPropertyTests.swift index 2b738d6f24..2b39e47d25 100644 --- a/Realm/Tests/Swift/SwiftSetPropertyTests.swift +++ b/Realm/Tests/Swift/SwiftSetPropertyTests.swift @@ -60,7 +60,7 @@ class SwiftRLMSetPropertyTests: RLMTestCase { let realm = realmWithTestPath() realm.beginWriteTransaction() - let set = SwiftRLMSetPropertyObject.create(in: realm, withValue: ["setObject", [], []]) + let set = SwiftRLMSetPropertyObject.create(in: realm, withValue: ["setObject"]) XCTAssertNotNil(set.set, "Should be able to get an empty set") XCTAssertEqual(set.set.count, UInt(0), "Should start with no set elements") @@ -90,7 +90,7 @@ class SwiftRLMSetPropertyTests: RLMTestCase { func testModifyDetatchedSet() { let realm = realmWithTestPath() realm.beginWriteTransaction() - let setObj = SwiftRLMSetPropertyObject.create(in: realm, withValue: ["setObject", [], []]) + let setObj = SwiftRLMSetPropertyObject.create(in: realm, withValue: ["setObject"]) XCTAssertNotNil(setObj.set, "Should be able to get an empty set") XCTAssertEqual(setObj.set.count, UInt(0), "Should start with no set elements") @@ -118,7 +118,7 @@ class SwiftRLMSetPropertyTests: RLMTestCase { realm.beginWriteTransaction() - let obj = SwiftRLMSetPropertyObject.create(in: realm, withValue: ["setObject", [], []]) + let obj = SwiftRLMSetPropertyObject.create(in: realm, withValue: ["setObject"]) let child1 = SwiftRLMStringObject.create(in: realm, withValue: ["a"]) let child2 = SwiftRLMStringObject() child2.stringCol = "b" @@ -190,7 +190,7 @@ class SwiftRLMSetPropertyTests: RLMTestCase { let realm = realmWithTestPath() realm.beginWriteTransaction() - let set = SetPropertyObject.create(in: realm, withValue: ["setObject", [], []]) + let set = SetPropertyObject.create(in: realm, withValue: ["setObject"]) XCTAssertNotNil(set.set, "Should be able to get an empty set") XCTAssertEqual(set.set.count, UInt(0), "Should start with no set elements") @@ -219,7 +219,7 @@ class SwiftRLMSetPropertyTests: RLMTestCase { func testModifyDetatchedSet_objc() { let realm = realmWithTestPath() realm.beginWriteTransaction() - let setObj = SetPropertyObject.create(in: realm, withValue: ["setObject", [], []]) + let setObj = SetPropertyObject.create(in: realm, withValue: ["setObject"]) XCTAssertNotNil(setObj.set, "Should be able to get an empty set") XCTAssertEqual(setObj.set.count, UInt(0), "Should start with no set elements") @@ -247,7 +247,7 @@ class SwiftRLMSetPropertyTests: RLMTestCase { realm.beginWriteTransaction() - let obj = SetPropertyObject.create(in: realm, withValue: ["setObject", [], []]) + let obj = SetPropertyObject.create(in: realm, withValue: ["setObject"]) let child1 = StringObject.create(in: realm, withValue: ["a"]) let child2 = StringObject() child2.stringCol = "b" diff --git a/RealmSwift/Aliases.swift b/RealmSwift/Aliases.swift index ee826a15e9..0cc144ace7 100644 --- a/RealmSwift/Aliases.swift +++ b/RealmSwift/Aliases.swift @@ -17,7 +17,7 @@ //////////////////////////////////////////////////////////////////////////// import Foundation -import Realm +import Realm.Swift // These types don't change when wrapping in Swift // so we just typealias them to remove the 'RLM' prefix diff --git a/RealmSwift/App.swift b/RealmSwift/App.swift index 39a8ed1577..593d4bb72a 100644 --- a/RealmSwift/App.swift +++ b/RealmSwift/App.swift @@ -16,6 +16,7 @@ // //////////////////////////////////////////////////////////////////////////// +import AuthenticationServices import Foundation import Realm import Realm.Private diff --git a/RealmSwift/Migration.swift b/RealmSwift/Migration.swift index 200d14d578..9a13a0f728 100644 --- a/RealmSwift/Migration.swift +++ b/RealmSwift/Migration.swift @@ -123,7 +123,7 @@ extension Migration { - returns: The newly created object. */ @discardableResult - public func create(_ typeName: String, value: Any = [:]) -> MigrationObject { + public func create(_ typeName: String, value: Any = [Any]()) -> MigrationObject { return unsafeBitCast(__createObject(typeName, withValue: value), to: MigrationObject.self) } diff --git a/RealmSwift/Realm.swift b/RealmSwift/Realm.swift index 4ac5b3095a..553074af95 100644 --- a/RealmSwift/Realm.swift +++ b/RealmSwift/Realm.swift @@ -563,13 +563,6 @@ public typealias AsyncTransactionId = RLMAsyncTransactionId } } - /// :nodoc: - @discardableResult - @available(*, unavailable, message: "Pass .error, .modified or .all rather than a boolean. .error is equivalent to false and .all is equivalent to true.") - public func create(_ type: T.Type, value: Any = [:], update: Bool) -> T { - fatalError() - } - /** Creates a Realm object with a given value, adding it to the Realm and returning it. @@ -601,7 +594,7 @@ public typealias AsyncTransactionId = RLMAsyncTransactionId - returns: The newly created object. */ @discardableResult - public func create(_ type: T.Type, value: Any = [:], update: UpdatePolicy = .error) -> T { + public func create(_ type: T.Type, value: Any = [String: Any](), update: UpdatePolicy = .error) -> T { if update != .error { RLMVerifyHasPrimaryKey(type) } @@ -610,13 +603,6 @@ public typealias AsyncTransactionId = RLMAsyncTransactionId RLMUpdatePolicy(rawValue: UInt(update.rawValue))!), to: type) } - /// :nodoc: - @discardableResult - @available(*, unavailable, message: "Pass .error, .modified or .all rather than a boolean. .error is equivalent to false and .all is equivalent to true.") - public func dynamicCreate(_ typeName: String, value: Any = [:], update: Bool) -> DynamicObject { - fatalError() - } - /** This method is useful only in specialized circumstances, for example, when building components that integrate with Realm. If you are simply building an app on Realm, it is @@ -656,7 +642,7 @@ public typealias AsyncTransactionId = RLMAsyncTransactionId :nodoc: */ @discardableResult - public func dynamicCreate(_ typeName: String, value: Any = [:], update: UpdatePolicy = .error) -> DynamicObject { + public func dynamicCreate(_ typeName: String, value: Any = [String: Any](), update: UpdatePolicy = .error) -> DynamicObject { if update != .error && schema[typeName]?.primaryKeyProperty == nil { throwRealmException("'\(typeName)' does not have a primary key and can not be updated") } @@ -1114,7 +1100,7 @@ extension Realm { - parameter type: The type of the object to create. - parameter value: The value used to populate the object. */ - public func create(_ type: T.Type, value: Any = [:]) { + public func create(_ type: T.Type, value: Any = [String: Any]()) { let typeName = (type as AsymmetricObject.Type).className() RLMCreateAsymmetricObjectInRealm(rlmRealm, typeName, value) } diff --git a/RealmSwift/Tests/CombineTests.swift b/RealmSwift/Tests/CombineTests.swift index 07b51354d5..356d245f9a 100644 --- a/RealmSwift/Tests/CombineTests.swift +++ b/RealmSwift/Tests/CombineTests.swift @@ -85,8 +85,8 @@ class ObjectIdentifiableTests: TestCase { let realm = try! Realm() let (obj1, obj2) = try! realm.write { return ( - realm.create(CombineIdentifiableObject.self, value: [1, [1]]), - realm.create(CombineIdentifiableObject.self, value: [2, [2]]) + realm.create(CombineIdentifiableObject.self, value: [1, [1]] as [Any]), + realm.create(CombineIdentifiableObject.self, value: [2, [2]] as [Any]) ) } XCTAssertEqual(obj1.child!.id, obj1.child!.id) @@ -155,7 +155,7 @@ class CombineRealmTests: CombinePublisherTestCase { } try! realm.write { - realm.create(SwiftIntObject.self, value: []) + realm.create(SwiftIntObject.self) } XCTAssertTrue(called) } @@ -171,7 +171,7 @@ class CombineRealmTests: CombinePublisherTestCase { } try! realm.write { - realm.create(SwiftIntObject.self, value: []) + realm.create(SwiftIntObject.self) } XCTAssertNotNil(notificationToken) XCTAssertTrue(called) @@ -189,7 +189,7 @@ class CombineRealmTests: CombinePublisherTestCase { XCTAssertNotNil(notificationToken) for _ in 0..<10 { try! realm.write(withoutNotifying: [notificationToken!]) { - realm.create(SwiftIntObject.self, value: []) + realm.create(SwiftIntObject.self) } XCTAssertFalse(called) } @@ -203,7 +203,7 @@ class CombineRealmTests: CombinePublisherTestCase { subscribeOnQueue.async { let backgroundRealm = try! Realm(configuration: self.realm.configuration) try! backgroundRealm.write { - backgroundRealm.create(SwiftIntObject.self, value: []) + backgroundRealm.create(SwiftIntObject.self) } } wait(for: [exp], timeout: 1) @@ -218,7 +218,7 @@ class CombineObjectPublisherTests: CombinePublisherTestCase { override func setUp() { super.setUp() - obj = try! realm.write { realm.create(SwiftIntObject.self, value: []) } + obj = try! realm.write { realm.create(SwiftIntObject.self) } } func testWillChange() { @@ -1398,7 +1398,7 @@ extension Results: CombineTestCollection where Element == ModernAllTypesObject { } func appendObject() { - realm?.create(Element.self, value: []) + realm?.create(Element.self) } func modifyObject() { @@ -1423,11 +1423,11 @@ class ResultsPublisherTests: TestCase { extension List: CombineTestCollection where Element == ModernAllTypesObject { static func getCollection(_ realm: Realm) -> List { - return try! realm.write { realm.create(ModernAllTypesObject.self, value: []).arrayCol } + return try! realm.write { realm.create(ModernAllTypesObject.self).arrayCol } } func appendObject() { - append(realm!.create(Element.self, value: [])) + append(realm!.create(Element.self)) } func modifyObject() { @@ -1453,11 +1453,11 @@ class ManagedListPublisherTests: TestCase { extension MutableSet: CombineTestCollection where Element == ModernAllTypesObject { static func getCollection(_ realm: Realm) -> MutableSet { - return try! realm.write { realm.create(ModernAllTypesObject.self, value: []).setCol } + return try! realm.write { realm.create(ModernAllTypesObject.self).setCol } } func appendObject() { - insert(realm!.create(Element.self, value: [])) + insert(realm!.create(Element.self)) } func modifyObject() { @@ -1482,7 +1482,7 @@ class ManagedMutableSetPublisherTests: TestCase { extension LinkingObjects: CombineTestCollection where Element == ModernAllTypesObject { static func getCollection(_ realm: Realm) -> LinkingObjects { - return try! realm.write { realm.create(ModernAllTypesObject.self, value: []).linkingObjects } + return try! realm.write { realm.create(ModernAllTypesObject.self).linkingObjects } } func appendObject() { @@ -1518,7 +1518,7 @@ extension AnyRealmCollection: CombineTestCollection where Element == ModernAllTy } func appendObject() { - realm?.create(Element.self, value: []) + realm?.create(Element.self) } func modifyObject() { @@ -2150,12 +2150,12 @@ private class CombineMapPublisherTests: Combin extension Map: CombineTestCollection where Key == String, Value == SwiftObject? { static func getCollection(_ realm: Realm) -> Map { - return try! realm.write { realm.create(SwiftMapPropertyObject.self, value: []).swiftObjectMap } + return try! realm.write { realm.create(SwiftMapPropertyObject.self).swiftObjectMap } } func appendObject() { let key = UUID().uuidString - self[key] = realm!.create(SwiftObject.self, value: []) + self[key] = realm!.create(SwiftObject.self) } func modifyObject() { @@ -4089,7 +4089,7 @@ class CombineAsyncRealmTests: CombinePublisherTestCase { } realm.writeAsync { - self.realm.create(SwiftIntObject.self, value: []) + self.realm.create(SwiftIntObject.self) } waitForExpectations(timeout: 1, handler: nil) } @@ -4102,7 +4102,7 @@ class CombineAsyncRealmTests: CombinePublisherTestCase { queue.async { let realm = try! Realm(configuration: self.realm.configuration, queue: self.queue) realm.writeAsync { - realm.create(SwiftIntObject.self, value: []) + realm.create(SwiftIntObject.self) } } wait(for: [exp], timeout: 3) diff --git a/RealmSwift/Tests/CustomColumnNameTests.swift b/RealmSwift/Tests/CustomColumnNameTests.swift index febfb2ce43..f3c9f6898c 100644 --- a/RealmSwift/Tests/CustomColumnNameTests.swift +++ b/RealmSwift/Tests/CustomColumnNameTests.swift @@ -25,7 +25,7 @@ protocol CustomColumnObjectFactory { associatedtype Root: Object static func create(primaryKey: ObjectId, nestedObject: Root?) -> Root - static func createValues(primaryKey: ObjectId) -> Any + static func createValues(primaryKey: ObjectId) -> [String: Any] } // MARK: - Models @@ -101,7 +101,7 @@ extension ModernCustomObject: CustomColumnObjectFactory { return object } - static func createValues(primaryKey: ObjectId) -> Any { + static func createValues(primaryKey: ObjectId) -> [String: Any] { return [ "pk": primaryKey, "intCol": 123, @@ -180,7 +180,7 @@ extension OldCustomObject: CustomColumnObjectFactory { return object } - static func createValues(primaryKey: ObjectId) -> Any { + static func createValues(primaryKey: ObjectId) -> [String: Any] { return [ "pk": primaryKey, "intCol": 123, diff --git a/RealmSwift/Tests/CustomObjectCreationTests.swift b/RealmSwift/Tests/CustomObjectCreationTests.swift index 20fbe8086f..0ff5f19767 100644 --- a/RealmSwift/Tests/CustomObjectCreationTests.swift +++ b/RealmSwift/Tests/CustomObjectCreationTests.swift @@ -809,7 +809,7 @@ class CustomObjectCreationTests: TestCase { } func testInitFailable() { - _ = FailableCustomObject(value: []) + _ = FailableCustomObject() assertThrows(FailableCustomObject(value: ["int": 1]), reason: "Could not convert value '1' to type 'IntFailableWrapper'.") let obj = FailableCustomObject(value: ["optInt": 1, diff --git a/RealmSwift/Tests/ListTests.swift b/RealmSwift/Tests/ListTests.swift index 8095dd366f..e15bf7eb03 100644 --- a/RealmSwift/Tests/ListTests.swift +++ b/RealmSwift/Tests/ListTests.swift @@ -712,7 +712,7 @@ class ListNewlyCreatedTests: ListTests { override func createArray() -> SwiftArrayPropertyObject { let realm = realmWithTestPath() realm.beginWrite() - let array = realm.create(SwiftArrayPropertyObject.self, value: ["name", [], []]) + let array = realm.create(SwiftArrayPropertyObject.self, value: ["name"]) try! realm.commitWrite() XCTAssertNotNil(array.realm) @@ -732,7 +732,7 @@ class ListNewlyCreatedTests: ListTests { override func createEmbeddedArray() -> List { let realm = try! Realm() return try! realm.write { - realm.create(EmbeddedParentObject.self, value: []).array + realm.create(EmbeddedParentObject.self).array } } } @@ -741,7 +741,7 @@ class ListRetrievedTests: ListTests { override func createArray() -> SwiftArrayPropertyObject { let realm = realmWithTestPath() realm.beginWrite() - realm.create(SwiftArrayPropertyObject.self, value: ["name", [], []]) + realm.create(SwiftArrayPropertyObject.self, value: ["name"]) try! realm.commitWrite() let array = realm.objects(SwiftArrayPropertyObject.self).first! @@ -763,7 +763,7 @@ class ListRetrievedTests: ListTests { override func createEmbeddedArray() -> List { let realm = try! Realm() try! realm.write { - realm.create(EmbeddedParentObject.self, value: []) + realm.create(EmbeddedParentObject.self) } return realm.objects(EmbeddedParentObject.self).first!.array } diff --git a/RealmSwift/Tests/MapTests.swift b/RealmSwift/Tests/MapTests.swift index 8fc8d004fc..928736f4ab 100644 --- a/RealmSwift/Tests/MapTests.swift +++ b/RealmSwift/Tests/MapTests.swift @@ -1048,7 +1048,7 @@ class MapNewlyAddedTests: MapTests { class MapNewlyCreatedTests: MapTests { override func createMap() -> Map { - let mapObj = realm.create(SwiftMapPropertyObject.self, value: ["name", [], []]) + let mapObj = realm.create(SwiftMapPropertyObject.self, value: ["name"]) try! realm.commitWrite() realm.beginWrite() XCTAssertNotNil(mapObj.realm) @@ -1064,13 +1064,13 @@ class MapNewlyCreatedTests: MapTests { } override func createEmbeddedMap() -> Map { - return realm.create(EmbeddedParentObject.self, value: []).map + return realm.create(EmbeddedParentObject.self).map } } class MapRetrievedTests: MapTests { override func createMap() -> Map { - realm.create(SwiftMapPropertyObject.self, value: ["name", [:], [:]]) + realm.create(SwiftMapPropertyObject.self, value: ["name"]) try! realm.commitWrite() let mapObj = realm.objects(SwiftMapPropertyObject.self).first! @@ -1091,7 +1091,7 @@ class MapRetrievedTests: MapTests { } override func createEmbeddedMap() -> Map { - realm.create(EmbeddedParentObject.self, value: []) + realm.create(EmbeddedParentObject.self) return realm.objects(EmbeddedParentObject.self).first!.map } } diff --git a/RealmSwift/Tests/MigrationTests.swift b/RealmSwift/Tests/MigrationTests.swift index 6dfb01d8d9..3c0f42d0eb 100644 --- a/RealmSwift/Tests/MigrationTests.swift +++ b/RealmSwift/Tests/MigrationTests.swift @@ -202,7 +202,7 @@ class MigrationTests: TestCase { try! Realm().write { try! Realm().create(SwiftArrayPropertyObject.self, value: ["string", [["array"]], [[2]]]) try! Realm().create(SwiftMutableSetPropertyObject.self, value: ["string", [["set"]], [[2]]]) - try! Realm().create(SwiftMapPropertyObject.self, value: ["string", ["key": ["value"]], [:]]) + try! Realm().create(SwiftMapPropertyObject.self, value: ["string", ["key": ["value"]]]) } } @@ -732,7 +732,7 @@ class MigrationTests: TestCase { migration.create("SwiftStringObject", value: ["stringCol": StringWrapper(persistedValue: "string3")]) migration.create("SwiftStringObject") - self.assertThrows(migration.create("NoSuchObject", value: [])) + self.assertThrows(migration.create("NoSuchObject")) } let objects = try! Realm().objects(SwiftStringObject.self) diff --git a/RealmSwift/Tests/ModernObjectCreationTests.swift b/RealmSwift/Tests/ModernObjectCreationTests.swift index 5c3bb8c729..e75bc0af51 100644 --- a/RealmSwift/Tests/ModernObjectCreationTests.swift +++ b/RealmSwift/Tests/ModernObjectCreationTests.swift @@ -671,7 +671,7 @@ class ModernObjectCreationTests: TestCase { let realm = try! Realm() realm.beginWrite() let parent = realm.create(ModernEmbeddedParentObject.self, value: [ - "object": ["value": 5, "child": ["value": 6], "children": [[7], [8]]], + "object": ["value": 5, "child": ["value": 6], "children": [[7], [8]]] as [String: Any], "array": [[9], [10]] ]) XCTAssertEqual(parent.object!.value, 5) @@ -721,7 +721,7 @@ class ModernObjectCreationTests: TestCase { let realm = try! Realm() realm.beginWrite() let parent = realm.create(ModernEmbeddedParentObject.self, value: [ - "object": ["value": 5, "child": ["value": 6], "children": [[7], [8]]], + "object": ["value": 5, "child": ["value": 6], "children": [[7], [8]]] as [String: Any], "array": [[9], [10]] ]) let copy = realm.create(ModernEmbeddedParentObject.self, value: parent) @@ -742,7 +742,7 @@ class ModernObjectCreationTests: TestCase { let realmB = try! Realm() realmA.beginWrite() let parent = realmA.create(ModernEmbeddedParentObject.self, value: [ - "object": ["value": 5, "child": ["value": 6], "children": [[7], [8]]], + "object": ["value": 5, "child": ["value": 6], "children": [[7], [8]]] as [String: Any], "array": [[9], [10]] ]) try! realmA.commitWrite() @@ -854,7 +854,7 @@ class ModernObjectCreationTests: TestCase { try! Realm().commitWrite() try! Realm().beginWrite() - let object = SwiftLinkToPrimaryStringObject(value: ["primary", ["primary", 2], []]) + let object = SwiftLinkToPrimaryStringObject(value: ["primary", ["primary", 2] as [Any]]) try! Realm().add(object, update: .modified) try! Realm().commitWrite() @@ -907,7 +907,7 @@ class ModernObjectCreationTests: TestCase { weak var weakObj1: ModernCircleObject?, weakObj2: ModernCircleObject? autoreleasepool { - let obj1 = ModernCircleObject(value: []) + let obj1 = ModernCircleObject() let obj2 = ModernCircleObject(value: [obj1, [obj1]]) obj1.obj = obj2 obj1.array.append(obj2) diff --git a/RealmSwift/Tests/MutableSetTests.swift b/RealmSwift/Tests/MutableSetTests.swift index fdcd095b7d..03845ce3ee 100644 --- a/RealmSwift/Tests/MutableSetTests.swift +++ b/RealmSwift/Tests/MutableSetTests.swift @@ -524,7 +524,7 @@ class MutableSetNewlyCreatedTests: MutableSetTests { override func createSet() -> SwiftMutableSetPropertyObject { let realm = realmWithTestPath() realm.beginWrite() - let set = realm.create(SwiftMutableSetPropertyObject.self, value: ["name", [], []]) + let set = realm.create(SwiftMutableSetPropertyObject.self, value: ["name"]) try! realm.commitWrite() XCTAssertNotNil(set.realm) @@ -546,7 +546,7 @@ class MutableSetRetrievedTests: MutableSetTests { override func createSet() -> SwiftMutableSetPropertyObject { let realm = realmWithTestPath() realm.beginWrite() - realm.create(SwiftMutableSetPropertyObject.self, value: ["name", [], []]) + realm.create(SwiftMutableSetPropertyObject.self, value: ["name"]) try! realm.commitWrite() let set = realm.objects(SwiftMutableSetPropertyObject.self).last! diff --git a/RealmSwift/Tests/ObjectCreationTests.swift b/RealmSwift/Tests/ObjectCreationTests.swift index cec6af61a2..492c20b495 100644 --- a/RealmSwift/Tests/ObjectCreationTests.swift +++ b/RealmSwift/Tests/ObjectCreationTests.swift @@ -354,14 +354,13 @@ class ObjectCreationTests: TestCase { XCTAssertEqual(try! Realm().objects(SwiftObject.self).count, 2, "Object should have been copied") } - func testCreateWithNestedObjects() { + func testCreateWithNestedObjects() throws { let standalone = SwiftPrimaryStringObject(value: ["p0", 11]) - let realm = try! Realm() - - realm.beginWrite() - let objectWithNestedObjects = try! Realm().create(SwiftLinkToPrimaryStringObject.self, value: ["p1", ["p1", 12], - [standalone]]) - try! realm.commitWrite() + let realm = try Realm() + let objectWithNestedObjects = try realm.write { + realm.create(SwiftLinkToPrimaryStringObject.self, value: ["p1", ["p1", 12] as [Any], + [standalone]]) + } let stringObjects = realm.objects(SwiftPrimaryStringObject.self) XCTAssertEqual(stringObjects.count, 2) @@ -376,19 +375,21 @@ class ObjectCreationTests: TestCase { let standalone1 = SwiftPrimaryStringObject(value: ["p3", 11]) realm.beginWrite() - assertThrows(realm.create(SwiftLinkToPrimaryStringObject.self, value: ["p3", ["p3", 11], [standalone1]]), + assertThrows(realm.create(SwiftLinkToPrimaryStringObject.self, value: ["p3", ["p3", 11] as [Any], [standalone1]]), "Should throw with duplicate primary key") - try! realm.commitWrite() + realm.cancelWrite() } - func testUpdateWithNestedObjects() { + func testUpdateWithNestedObjects() throws { let standalone = SwiftPrimaryStringObject(value: ["primary", 11]) - try! Realm().beginWrite() - let object = try! Realm().create(SwiftLinkToPrimaryStringObject.self, value: ["otherPrimary", ["primary", 12], - [["primary", 12]]], update: .all) - try! Realm().commitWrite() + let realm = try Realm() + let object = try realm.write { + realm.create(SwiftLinkToPrimaryStringObject.self, + value: ["otherPrimary", ["primary", 12] as [Any], + [["primary", 12] as [Any]]], update: .all) + } - let stringObjects = try! Realm().objects(SwiftPrimaryStringObject.self) + let stringObjects = realm.objects(SwiftPrimaryStringObject.self) XCTAssertEqual(stringObjects.count, 1) let persistedObject = object.object! @@ -398,14 +399,16 @@ class ObjectCreationTests: TestCase { XCTAssertEqual(object.objects.first!, persistedObject) } - func testUpdateChangedWithNestedObjects() { + func testUpdateChangedWithNestedObjects() throws { let standalone = SwiftPrimaryStringObject(value: ["primary", 11]) - try! Realm().beginWrite() - let object = try! Realm().create(SwiftLinkToPrimaryStringObject.self, value: ["otherPrimary", ["primary", 12], - [["primary", 12]]], update: .modified) - try! Realm().commitWrite() + let realm = try Realm() + let object = try realm.write { + realm.create(SwiftLinkToPrimaryStringObject.self, + value: ["otherPrimary", ["primary", 12] as [Any], + [["primary", 12] as [Any]]], update: .modified) + } - let stringObjects = try! Realm().objects(SwiftPrimaryStringObject.self) + let stringObjects = realm.objects(SwiftPrimaryStringObject.self) XCTAssertEqual(stringObjects.count, 1) let persistedObject = object.object! @@ -510,32 +513,38 @@ class ObjectCreationTests: TestCase { } } - func testUpdateWithObjectsFromAnotherRealm() { - realmWithTestPath().beginWrite() - let otherRealmObject = realmWithTestPath().create(SwiftLinkToPrimaryStringObject.self, - value: ["primary", NSNull(), [["2", 2], ["4", 4]]]) - try! realmWithTestPath().commitWrite() + func testUpdateWithObjectsFromAnotherRealm() throws { + let testRealm = realmWithTestPath() + let otherRealmObject = try testRealm.write { + testRealm.create(SwiftLinkToPrimaryStringObject.self, + value: ["primary", NSNull(), [["2", 2] as [Any], ["4", 4]]]) + } - try! Realm().beginWrite() - try! Realm().create(SwiftLinkToPrimaryStringObject.self, value: ["primary", ["10", 10], [["11", 11]]]) - let object = try! Realm().create(SwiftLinkToPrimaryStringObject.self, value: otherRealmObject, update: .all) - try! Realm().commitWrite() + let realm = try Realm() + let object = try realm.write { () -> SwiftLinkToPrimaryStringObject in + realm.create(SwiftLinkToPrimaryStringObject.self, + value: ["primary", ["10", 10] as [Any], [["11", 11] as [Any]]]) + return realm.create(SwiftLinkToPrimaryStringObject.self, value: otherRealmObject, update: .all) + } XCTAssertNotEqual(otherRealmObject, object) // the object from the other realm should be copied into this realm XCTAssertEqual(try! Realm().objects(SwiftLinkToPrimaryStringObject.self).count, 1) XCTAssertEqual(try! Realm().objects(SwiftPrimaryStringObject.self).count, 4) } - func testUpdateChangedWithObjectsFromAnotherRealm() { - realmWithTestPath().beginWrite() - let otherRealmObject = realmWithTestPath().create(SwiftLinkToPrimaryStringObject.self, - value: ["primary", NSNull(), [["2", 2], ["4", 4]]]) - try! realmWithTestPath().commitWrite() + func testUpdateChangedWithObjectsFromAnotherRealm() throws { + let testRealm = realmWithTestPath() + let otherRealmObject = try testRealm.write { + testRealm.create(SwiftLinkToPrimaryStringObject.self, + value: ["primary", NSNull(), [["2", 2] as [Any], ["4", 4]]]) + } - try! Realm().beginWrite() - try! Realm().create(SwiftLinkToPrimaryStringObject.self, value: ["primary", ["10", 10], [["11", 11]]]) - let object = try! Realm().create(SwiftLinkToPrimaryStringObject.self, value: otherRealmObject, update: .modified) - try! Realm().commitWrite() + let realm = try Realm() + let object = try realm.write { () -> SwiftLinkToPrimaryStringObject in + realm.create(SwiftLinkToPrimaryStringObject.self, + value: ["primary", ["10", 10] as [Any], [["11", 11] as [Any]]]) + return realm.create(SwiftLinkToPrimaryStringObject.self, value: otherRealmObject, update: .modified) + } XCTAssertNotEqual(otherRealmObject, object) // the object from the other realm should be copied into this realm XCTAssertEqual(try! Realm().objects(SwiftLinkToPrimaryStringObject.self).count, 1) @@ -794,7 +803,7 @@ class ObjectCreationTests: TestCase { func testDynamicCreateEmbeddedDirectly() { let realm = try! Realm() realm.beginWrite() - assertThrows(realm.dynamicCreate("EmbeddedTreeObject1", value: []), + assertThrows(realm.dynamicCreate("EmbeddedTreeObject1"), reasonMatching: "Embedded objects cannot be created directly") realm.cancelWrite() } @@ -803,7 +812,7 @@ class ObjectCreationTests: TestCase { let realm = try! Realm() realm.beginWrite() let parent = realm.create(EmbeddedParentObject.self, value: [ - "object": ["value": 5, "child": ["value": 6], "children": [[7], [8]]], + "object": ["value": 5, "child": ["value": 6], "children": [[7], [8]]] as [String: Any], "array": [[9], [10]] ]) XCTAssertEqual(parent.object!.value, 5) @@ -853,7 +862,7 @@ class ObjectCreationTests: TestCase { let realm = try! Realm() realm.beginWrite() let parent = realm.create(EmbeddedParentObject.self, value: [ - "object": ["value": 5, "child": ["value": 6], "children": [[7], [8]]], + "object": ["value": 5, "child": ["value": 6], "children": [[7], [8]]] as [String: Any], "array": [[9], [10]] ]) let copy = realm.create(EmbeddedParentObject.self, value: parent) @@ -874,7 +883,7 @@ class ObjectCreationTests: TestCase { let realmB = try! Realm() realmA.beginWrite() let parent = realmA.create(EmbeddedParentObject.self, value: [ - "object": ["value": 5, "child": ["value": 6], "children": [[7], [8]]], + "object": ["value": 5, "child": ["value": 6], "children": [[7], [8]]] as [String: Any], "array": [[9], [10]] ]) try! realmA.commitWrite() @@ -953,15 +962,17 @@ class ObjectCreationTests: TestCase { realm.cancelWrite() } - func testAddAndUpdateWithExisingNestedObjects() { - try! Realm().beginWrite() - let existingObject = try! Realm().create(SwiftPrimaryStringObject.self, value: ["primary", 1]) - try! Realm().commitWrite() + func testAddAndUpdateWithExisingNestedObjects() throws { + let realm = try Realm() + let existingObject = try realm.write { + realm.create(SwiftPrimaryStringObject.self, value: ["primary", 1]) + } - try! Realm().beginWrite() - let object = SwiftLinkToPrimaryStringObject(value: ["primary", ["primary", 2], []]) - try! Realm().add(object, update: .all) - try! Realm().commitWrite() + let object = try realm.write { () -> SwiftLinkToPrimaryStringObject in + let object = SwiftLinkToPrimaryStringObject(value: ["primary", ["primary", 2] as [Any]]) + realm.add(object, update: .all) + return object + } XCTAssertNotNil(object.realm) XCTAssertEqual(object.object!, existingObject) // the existing object should be updated @@ -1018,7 +1029,7 @@ class ObjectCreationTests: TestCase { try! Realm().commitWrite() try! Realm().beginWrite() - let object = SwiftLinkToPrimaryStringObject(value: ["primary", ["primary", 2], []]) + let object = SwiftLinkToPrimaryStringObject(value: ["primary", ["primary", 2] as [Any]]) try! Realm().add(object, update: .modified) try! Realm().commitWrite() @@ -1399,7 +1410,7 @@ class ObjectCreationTests: TestCase { return [ ["trueVal": ["boolCol": true], "falseVal": ["boolCol": false]], ["trueVal": SwiftBoolObject(value: [true]), "falseVal": SwiftBoolObject(value: [false])], - ["trueVal": persistedObject, "falseVal": [false]] + ["trueVal": persistedObject, "falseVal": [false]] as [String: Any] ] } if array { @@ -1407,7 +1418,7 @@ class ObjectCreationTests: TestCase { [[true], [false]], [["boolCol": true], ["boolCol": false]], [SwiftBoolObject(value: [true]), SwiftBoolObject(value: [false])], - [persistedObject, [false]] + [persistedObject, [false]] as [Any] ] } switch type { @@ -1433,8 +1444,8 @@ class ObjectCreationTests: TestCase { try! Realm().commitWrite() if map { return [ - ["trueVal": ["boolCol": "invalid"], "falseVal": ["boolCol": false]], - ["trueVal": "invalid", "falseVal": SwiftBoolObject(value: [false])] + ["trueVal": ["boolCol": "invalid"] as [String: Any], "falseVal": ["boolCol": false]], + ["trueVal": "invalid", "falseVal": SwiftBoolObject(value: [false])] as [String: Any] ] } if array { diff --git a/RealmSwift/Tests/ObjectTests.swift b/RealmSwift/Tests/ObjectTests.swift index 82e81981ac..aa08df989e 100644 --- a/RealmSwift/Tests/ObjectTests.swift +++ b/RealmSwift/Tests/ObjectTests.swift @@ -55,7 +55,7 @@ class ObjectTests: TestCase { let realm = try! Realm() var persisted: SwiftStringObject! try! realm.write { - persisted = realm.create(SwiftStringObject.self, value: [:]) + persisted = realm.create(SwiftStringObject.self) XCTAssertNotNil(persisted.realm) XCTAssertEqual(realm, persisted.realm!) } @@ -326,7 +326,7 @@ class ObjectTests: TestCase { test(SwiftObject()) let realm = try! Realm() try! realm.write { - test(realm.create(SwiftObject.self, value: [:])) + test(realm.create(SwiftObject.self)) let addedObj = SwiftObject() realm.add(addedObj) test(addedObj) @@ -354,7 +354,7 @@ class ObjectTests: TestCase { test(SwiftOptionalObject()) let realm = try! Realm() try! realm.write { - test(realm.create(SwiftOptionalObject.self, value: [:])) + test(realm.create(SwiftOptionalObject.self)) let addedObj = SwiftOptionalObject() realm.add(addedObj) test(addedObj) @@ -398,7 +398,7 @@ class ObjectTests: TestCase { test(SwiftListObject()) let realm = try! Realm() try! realm.write { - test(realm.create(SwiftListObject.self, value: [:])) + test(realm.create(SwiftListObject.self)) let addedObj = SwiftListObject() realm.add(addedObj) test(addedObj) @@ -440,7 +440,7 @@ class ObjectTests: TestCase { test(SwiftMutableSetObject()) let realm = try! Realm() try! realm.write { - test(realm.create(SwiftMutableSetObject.self, value: [:])) + test(realm.create(SwiftMutableSetObject.self)) let addedObj = SwiftMutableSetObject() realm.add(addedObj) test(addedObj) @@ -723,7 +723,7 @@ class ObjectTests: TestCase { setAndTestAllTypes(setter, getter: getter, object: SwiftObject()) try! Realm().write { - let persistedObject = try! Realm().create(SwiftObject.self, value: [:]) + let persistedObject = try! Realm().create(SwiftObject.self) self.setAndTestAllTypes(setter, getter: getter, object: persistedObject) } } @@ -743,7 +743,7 @@ class ObjectTests: TestCase { setAndTestAllTypes(setter, getter: getter, object: SwiftObject()) try! Realm().write { - let persistedObject = try! Realm().create(SwiftObject.self, value: [:]) + let persistedObject = try! Realm().create(SwiftObject.self) self.setAndTestAllTypes(setter, getter: getter, object: persistedObject) } } @@ -1092,7 +1092,7 @@ class ObjectTests: TestCase { func testListPropertyNotifications() { let realm = try! Realm() realm.beginWrite() - let object = realm.create(SwiftRecursiveObject.self, value: [[]]) + let object = realm.create(SwiftRecursiveObject.self) try! realm.commitWrite() let token = object.observe(expectChange("objects", Int?.none, Int?.none)) @@ -1384,7 +1384,7 @@ class ObjectTests: TestCase { func testMutableSetPropertyNotifications() { let realm = try! Realm() realm.beginWrite() - let object = realm.create(SwiftRecursiveObject.self, value: [[]]) + let object = realm.create(SwiftRecursiveObject.self) try! realm.commitWrite() let token = object.observe(expectChange("objectSet", Int?.none, Int?.none)) diff --git a/RealmSwift/Tests/PerformanceTests.swift b/RealmSwift/Tests/PerformanceTests.swift index 5a222d8f12..140bcbfeb4 100644 --- a/RealmSwift/Tests/PerformanceTests.swift +++ b/RealmSwift/Tests/PerformanceTests.swift @@ -229,7 +229,7 @@ class SwiftPerformanceTests: TestCase { let realm = copyRealmToTestPath(largeRealm) realm.beginWrite() let arrayPropertyObject = realm.create(SwiftArrayPropertyObject.self, - value: ["name", realm.objects(SwiftStringObject.self).map { $0 } as NSArray, []]) + value: ["name", realm.objects(SwiftStringObject.self)]) try! realm.commitWrite() measure { @@ -243,7 +243,7 @@ class SwiftPerformanceTests: TestCase { let realm = copyRealmToTestPath(largeRealm) realm.beginWrite() let setPropertyObject = realm.create(SwiftMutableSetPropertyObject.self, - value: ["name", realm.objects(SwiftStringObject.self).map { $0 } as NSArray, []]) + value: ["name", realm.objects(SwiftStringObject.self)]) try! realm.commitWrite() measure { @@ -257,7 +257,7 @@ class SwiftPerformanceTests: TestCase { let realm = copyRealmToTestPath(largeRealm) realm.beginWrite() let arrayPropertyObject = realm.create(SwiftArrayPropertyObject.self, - value: ["name", realm.objects(SwiftStringObject.self).map { $0 } as NSArray, []]) + value: ["name", realm.objects(SwiftStringObject.self)]) try! realm.commitWrite() measure { @@ -272,7 +272,7 @@ class SwiftPerformanceTests: TestCase { let realm = copyRealmToTestPath(largeRealm) realm.beginWrite() let setPropertyObject = realm.create(SwiftMutableSetPropertyObject.self, - value: ["name", realm.objects(SwiftStringObject.self).map { $0 } as NSArray, []]) + value: ["name", realm.objects(SwiftStringObject.self)]) try! realm.commitWrite() measure { @@ -308,7 +308,7 @@ class SwiftPerformanceTests: TestCase { func testEnumerateAndAccessMixed() { let realm = inMemoryRealm(#function) realm.beginWrite() - let list = realm.create(ModernListAnyRealmValueObject.self, value: []).value + let list = realm.create(ModernListAnyRealmValueObject.self).value for i in 0..<500000 { list.append(.int(i)) } @@ -347,7 +347,7 @@ class SwiftPerformanceTests: TestCase { func testManualDeletion() { inMeasureBlock { let realm = self.copyRealmToTestPath(mediumRealm) - let objects = realm.objects(SwiftStringObject.self).map { $0 } + let objects = Array(realm.objects(SwiftStringObject.self)) self.startMeasuring() try! realm.write { realm.delete(objects) diff --git a/RealmSwift/Tests/ProjectionTests.swift b/RealmSwift/Tests/ProjectionTests.swift index 5ae6edbb45..502d0bc11d 100644 --- a/RealmSwift/Tests/ProjectionTests.swift +++ b/RealmSwift/Tests/ProjectionTests.swift @@ -427,7 +427,11 @@ class ProjectionTests: TestCase { dt.friends.append(js) realm.create(ModernAllTypesObject.self, value: allTypeValues) - realm.create(AdvancedObject.self, value: ["pk": ObjectId.generate(), "commonArray": [1, 2, 3], "objectsArray": [[1, true], [2, false]], "commonSet": [1, 2, 3], "objectsSet": [[1, true], [2, false]]]) + realm.create(AdvancedObject.self, value: ["pk": ObjectId.generate(), + "commonArray": [1, 2, 3], + "objectsArray": [[1, true] as [Any], [2, false]], + "commonSet": [1, 2, 3], + "objectsSet": [[1, true] as [Any], [2, false]]]) } return realm } diff --git a/RealmSwift/Tests/RealmCollectionTypeTests.swift b/RealmSwift/Tests/RealmCollectionTypeTests.swift index e42d581804..9922e57778 100644 --- a/RealmSwift/Tests/RealmCollectionTypeTests.swift +++ b/RealmSwift/Tests/RealmCollectionTypeTests.swift @@ -289,7 +289,7 @@ class RealmCollectionTests(_ type: T.Type, value: [String: Any], update: UpdatePolicy = .error) -> T { + return create(type, value: value as Any, update: update) + } + + @discardableResult + public func create(_ type: T.Type, value: [Any], update: UpdatePolicy = .error) -> T { + return create(type, value: value as Any, update: update) + } +} + +extension Object { + public convenience init(value: [String: Any]) { + self.init(value: value as Any) + } + + public convenience init(value: [Any]) { + self.init(value: value as Any) + } +} + +extension AsymmetricObject { + public convenience init(value: [String: Any]) { + self.init(value: value as Any) + } + + public convenience init(value: [Any]) { + self.init(value: value as Any) + } +} diff --git a/RealmSwift/Tests/ThreadSafeReferenceTests.swift b/RealmSwift/Tests/ThreadSafeReferenceTests.swift index 1fdc9b1ed4..156a067b43 100644 --- a/RealmSwift/Tests/ThreadSafeReferenceTests.swift +++ b/RealmSwift/Tests/ThreadSafeReferenceTests.swift @@ -31,9 +31,9 @@ class ThreadSafeReferenceTests: TestCase { func testInvalidThreadSafeReferenceConstruction() { let stringObject = SwiftStringObject() - let arrayParent = SwiftArrayPropertyObject(value: ["arrayObject", [["a"]], []]) + let arrayParent = SwiftArrayPropertyObject(value: ["arrayObject", [["a"]]]) let arrayObject = arrayParent.array - let setParent = SwiftMutableSetPropertyObject(value: ["setObject", [["a"]], []]) + let setParent = SwiftMutableSetPropertyObject(value: ["setObject", [["a"]]]) let setObject = setParent.set assertThrows(ThreadSafeReference(to: stringObject), reason: "Cannot construct reference to unmanaged object") diff --git a/examples/installation/catalyst/objc/CocoaPodsDynamicExample/CocoaPodsDynamicExample.xcodeproj/project.pbxproj b/examples/installation/catalyst/objc/CocoaPodsDynamicExample/CocoaPodsDynamicExample.xcodeproj/project.pbxproj index db3da239ac..0d247cc186 100644 --- a/examples/installation/catalyst/objc/CocoaPodsDynamicExample/CocoaPodsDynamicExample.xcodeproj/project.pbxproj +++ b/examples/installation/catalyst/objc/CocoaPodsDynamicExample/CocoaPodsDynamicExample.xcodeproj/project.pbxproj @@ -201,7 +201,7 @@ E83EBA761AFAB18F0026370F /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1400; + LastUpgradeCheck = 1430; ORGANIZATIONNAME = Realm; TargetAttributes = { E83EBA7D1AFAB18F0026370F = { diff --git a/examples/installation/catalyst/objc/CocoaPodsExample/CocoaPodsExample.xcodeproj/project.pbxproj b/examples/installation/catalyst/objc/CocoaPodsExample/CocoaPodsExample.xcodeproj/project.pbxproj index b48e89aeba..9f64383f83 100644 --- a/examples/installation/catalyst/objc/CocoaPodsExample/CocoaPodsExample.xcodeproj/project.pbxproj +++ b/examples/installation/catalyst/objc/CocoaPodsExample/CocoaPodsExample.xcodeproj/project.pbxproj @@ -199,7 +199,7 @@ E83EBA761AFAB18F0026370F /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1400; + LastUpgradeCheck = 1430; ORGANIZATIONNAME = Realm; TargetAttributes = { E83EBA7D1AFAB18F0026370F = { diff --git a/examples/installation/catalyst/swift/CocoaPodsExample/CocoaPodsExample.xcodeproj/project.pbxproj b/examples/installation/catalyst/swift/CocoaPodsExample/CocoaPodsExample.xcodeproj/project.pbxproj index 79a000a0af..b140155dce 100644 --- a/examples/installation/catalyst/swift/CocoaPodsExample/CocoaPodsExample.xcodeproj/project.pbxproj +++ b/examples/installation/catalyst/swift/CocoaPodsExample/CocoaPodsExample.xcodeproj/project.pbxproj @@ -195,7 +195,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0710; - LastUpgradeCheck = 1400; + LastUpgradeCheck = 1430; ORGANIZATIONNAME = Realm; TargetAttributes = { E804A9551AFAB8C000CCAE65 = { diff --git a/examples/installation/ios/objc/CarthageExample/CarthageExample.xcodeproj/project.pbxproj b/examples/installation/ios/objc/CarthageExample/CarthageExample.xcodeproj/project.pbxproj index b8852dcdaf..5a84206031 100644 --- a/examples/installation/ios/objc/CarthageExample/CarthageExample.xcodeproj/project.pbxproj +++ b/examples/installation/ios/objc/CarthageExample/CarthageExample.xcodeproj/project.pbxproj @@ -203,7 +203,7 @@ E8F8D98C1B0177C10098F6CD /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1400; + LastUpgradeCheck = 1430; ORGANIZATIONNAME = Realm; TargetAttributes = { E8F8D9931B0177C10098F6CD = { diff --git a/examples/installation/ios/objc/CarthageExample/CarthageExample.xcodeproj/xcshareddata/xcschemes/CarthageExample.xcscheme b/examples/installation/ios/objc/CarthageExample/CarthageExample.xcodeproj/xcshareddata/xcschemes/CarthageExample.xcscheme index 88dd19fd17..71752adf48 100644 --- a/examples/installation/ios/objc/CarthageExample/CarthageExample.xcodeproj/xcshareddata/xcschemes/CarthageExample.xcscheme +++ b/examples/installation/ios/objc/CarthageExample/CarthageExample.xcodeproj/xcshareddata/xcschemes/CarthageExample.xcscheme @@ -1,6 +1,6 @@ + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES">