diff --git a/.github/workflows/master-push.yml b/.github/workflows/master-push.yml index 1820bca2a0..fcf518d88f 100644 --- a/.github/workflows/master-push.yml +++ b/.github/workflows/master-push.yml @@ -6,8 +6,8 @@ on: - "master" - "release/**" env: - XCODE_VERSION: "['15.1', '15.2', '15.3']" - XCODE_TEST_VERSIONS: "['15.1', '15.2', '15.3']" + XCODE_VERSION: "['15.1', '15.2', '15.3', '15.4']" + XCODE_TEST_VERSIONS: "['15.1', '15.2', '15.3', '15.4']" PLATFORM: "['ios', 'osx', 'watchos', 'tvos', 'catalyst', 'visionos']" BUILD_PLATFORM: "['ios', 'iossimulator', 'osx', 'watchos', 'watchossimulator', 'tvos', 'tvossimulator', 'catalyst', 'visionos', 'visionossimulator']" DOC_VERSION: '15.3' diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index a37523e4c2..b279ad4bc1 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -1,7 +1,7 @@ name: Publish release on: workflow_dispatch env: - XCODE_VERSION: "['15.1', '15.2', '15.3']" + XCODE_VERSION: "['15.1', '15.2', '15.3', '15.4']" TEST_XCODE_VERSION: '15.3' jobs: prepare: diff --git a/CHANGELOG.md b/CHANGELOG.md index bfdc478508..c09702e157 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ x.y.z Release notes (yyyy-MM-dd) ============================================================= ### Enhancements -* None. +* Update release packaging for Xcode 15.4. ### Fixed * ([#????](https://github.com/realm/realm-swift/issues/????), since v?.?.?) @@ -13,9 +13,9 @@ x.y.z Release notes (yyyy-MM-dd) ### Compatibility * Realm Studio: 15.0.0 or later. * APIs are backwards compatible with all previous releases in the 10.x.y series. -* Carthage release for Swift is built with Xcode 15.3.0. +* Carthage release for Swift is built with Xcode 15.4.0. * CocoaPods: 1.10 or later. -* Xcode: 15.1.0-15.3.0. +* Xcode: 15.1.0-15.4.0. ### Internal * Upgraded realm-core from ? to ? diff --git a/Realm/ObjectServerTests/AsyncSyncTests.swift b/Realm/ObjectServerTests/AsyncSyncTests.swift index a3ccb65f3c..ad9e813fac 100644 --- a/Realm/ObjectServerTests/AsyncSyncTests.swift +++ b/Realm/ObjectServerTests/AsyncSyncTests.swift @@ -190,7 +190,7 @@ class AsyncAwaitSyncTests: SwiftSyncTestCase { try await write { realm in let object = SwiftCustomColumnObject() object.id = objectId - object.binaryCol = "string".data(using: String.Encoding.utf8)! + object.binaryCol = Data("string".utf8) let linkedObject = SwiftCustomColumnObject() linkedObject.id = linkedObjectId object.objectCol = linkedObject @@ -207,7 +207,7 @@ class AsyncAwaitSyncTests: SwiftSyncTestCase { XCTAssertEqual(object.intCol, 1) XCTAssertEqual(object.doubleCol, 1.1) XCTAssertEqual(object.stringCol, "string") - XCTAssertEqual(object.binaryCol, "string".data(using: String.Encoding.utf8)!) + XCTAssertEqual(object.binaryCol, Data("string".utf8)) XCTAssertEqual(object.dateCol, Date(timeIntervalSince1970: -1)) XCTAssertEqual(object.longCol, 1) XCTAssertEqual(object.decimalCol, Decimal128(1)) @@ -462,7 +462,7 @@ class AsyncAwaitSyncTests: SwiftSyncTestCase { XCTAssertEqual(obj.intCol, 1) XCTAssertEqual(obj.doubleCol, 1.1) XCTAssertEqual(obj.stringCol, "string") - XCTAssertEqual(obj.binaryCol, "string".data(using: String.Encoding.utf8)!) + XCTAssertEqual(obj.binaryCol, Data("string".utf8)) XCTAssertEqual(obj.decimalCol, Decimal128(1)) XCTAssertEqual(obj.dateCol, Date(timeIntervalSince1970: -1)) XCTAssertEqual(obj.longCol, Int64(1)) @@ -1168,7 +1168,7 @@ class AsyncFlexibleSyncTests: SwiftSyncTestCase { "intCol": 365, "doubleCol": 365.365, "stringCol": "@#¢∞¬÷÷", - "binaryCol": "string".data(using: String.Encoding.utf8)!, + "binaryCol": Data("string".utf8), "dateCol": Date(timeIntervalSince1970: -365), "longCol": 365, "decimalCol": Decimal128(365), @@ -1193,7 +1193,7 @@ class AsyncFlexibleSyncTests: SwiftSyncTestCase { XCTAssertEqual(foundObject!.intCol, 365) XCTAssertEqual(foundObject!.doubleCol, 365.365) XCTAssertEqual(foundObject!.stringCol, "@#¢∞¬÷÷") - XCTAssertEqual(foundObject!.binaryCol, "string".data(using: String.Encoding.utf8)!) + XCTAssertEqual(foundObject!.binaryCol, Data("string".utf8)) XCTAssertEqual(foundObject!.dateCol, Date(timeIntervalSince1970: -365)) XCTAssertEqual(foundObject!.longCol, 365) XCTAssertEqual(foundObject!.decimalCol, Decimal128(365)) @@ -1209,7 +1209,7 @@ class AsyncFlexibleSyncTests: SwiftSyncTestCase { try await write { realm in let object = SwiftCustomColumnObject() object.id = objectId - object.binaryCol = "string".data(using: String.Encoding.utf8)! + object.binaryCol = Data("string".utf8) let linkedObject = SwiftCustomColumnObject() linkedObject.id = linkedObjectId object.objectCol = linkedObject @@ -1232,7 +1232,7 @@ class AsyncFlexibleSyncTests: SwiftSyncTestCase { XCTAssertEqual(foundObject!.intCol, 1) XCTAssertEqual(foundObject!.doubleCol, 1.1) XCTAssertEqual(foundObject!.stringCol, "string") - XCTAssertEqual(foundObject!.binaryCol, "string".data(using: String.Encoding.utf8)!) + XCTAssertEqual(foundObject!.binaryCol, Data("string".utf8)) XCTAssertEqual(foundObject!.dateCol, Date(timeIntervalSince1970: -1)) XCTAssertEqual(foundObject!.longCol, 1) XCTAssertEqual(foundObject!.decimalCol, Decimal128(1)) @@ -1248,7 +1248,7 @@ class AsyncFlexibleSyncTests: SwiftSyncTestCase { try await write { realm in let object = SwiftCustomColumnObject() object.id = objectId - object.binaryCol = "string".data(using: String.Encoding.utf8)! + object.binaryCol = Data("string".utf8) let linkedObject = SwiftCustomColumnObject() linkedObject.id = linkedObjectId object.objectCol = linkedObject @@ -1271,7 +1271,7 @@ class AsyncFlexibleSyncTests: SwiftSyncTestCase { XCTAssertEqual(foundObject!.intCol, 1) XCTAssertEqual(foundObject!.doubleCol, 1.1) XCTAssertEqual(foundObject!.stringCol, "string") - XCTAssertEqual(foundObject!.binaryCol, "string".data(using: String.Encoding.utf8)!) + XCTAssertEqual(foundObject!.binaryCol, Data("string".utf8)) XCTAssertEqual(foundObject!.dateCol, Date(timeIntervalSince1970: -1)) XCTAssertEqual(foundObject!.longCol, 1) XCTAssertEqual(foundObject!.decimalCol, Decimal128(1)) @@ -1287,7 +1287,7 @@ class AsyncFlexibleSyncTests: SwiftSyncTestCase { try await write { realm in let object = SwiftCustomColumnObject() object.id = objectId - object.binaryCol = "string".data(using: String.Encoding.utf8)! + object.binaryCol = Data("string".utf8) let linkedObject = SwiftCustomColumnObject() linkedObject.id = linkedObjectId object.objectCol = linkedObject @@ -1313,7 +1313,7 @@ class AsyncFlexibleSyncTests: SwiftSyncTestCase { XCTAssertEqual(foundObject!.intCol, 1) XCTAssertEqual(foundObject!.doubleCol, 1.1) XCTAssertEqual(foundObject!.stringCol, "string") - XCTAssertEqual(foundObject!.binaryCol, "string".data(using: String.Encoding.utf8)!) + XCTAssertEqual(foundObject!.binaryCol, Data("string".utf8)) XCTAssertEqual(foundObject!.dateCol, Date(timeIntervalSince1970: -1)) XCTAssertEqual(foundObject!.longCol, 1) XCTAssertEqual(foundObject!.decimalCol, Decimal128(1)) diff --git a/Realm/ObjectServerTests/RealmServer.swift b/Realm/ObjectServerTests/RealmServer.swift index 7979e5bc1e..512f4e785d 100644 --- a/Realm/ObjectServerTests/RealmServer.swift +++ b/Realm/ObjectServerTests/RealmServer.swift @@ -38,6 +38,7 @@ extension URLSession { completionHandler(.success(data)) } else if let error = error { completionHandler(.failure(error)) + // swiftlint:disable:next non_optional_string_data_conversion } else if let data = data, let string = String(data: data, encoding: .utf8) { completionHandler(.failure(NSError(domain: URLError.errorDomain, code: URLError.badServerResponse.rawValue, @@ -654,6 +655,7 @@ public class RealmServer: NSObject { let logLevel = self.logLevel pipe.fileHandleForReading.readabilityHandler = { file in guard file.availableData.count > 0, + // swiftlint:disable:next non_optional_string_data_conversion let available = String(data: file.availableData, encoding: .utf8)?.split(separator: "\t") else { return } @@ -674,9 +676,9 @@ public class RealmServer: NSObject { } else if part.contains("ERROR") { parts.append("🔴") } else if let json = try? JSONSerialization.jsonObject(with: part.data(using: .utf8)!) { - parts.append(String(data: try! JSONSerialization.data(withJSONObject: json, - options: .prettyPrinted), - encoding: .utf8)!) + parts.append(String(decoding: try! JSONSerialization.data(withJSONObject: json, + options: .prettyPrinted), + as: UTF8.self)) } else if !part.isEmpty { parts.append(String(part)) } diff --git a/Realm/ObjectServerTests/SwiftObjectServerTests.swift b/Realm/ObjectServerTests/SwiftObjectServerTests.swift index 426e5cd5d4..dd40675d51 100644 --- a/Realm/ObjectServerTests/SwiftObjectServerTests.swift +++ b/Realm/ObjectServerTests/SwiftObjectServerTests.swift @@ -126,7 +126,7 @@ class SwiftObjectServerTests: SwiftSyncTestCase { XCTAssertEqual(obj.intCol, 1) XCTAssertEqual(obj.doubleCol, 1.1) XCTAssertEqual(obj.stringCol, "string") - XCTAssertEqual(obj.binaryCol, "string".data(using: String.Encoding.utf8)!) + XCTAssertEqual(obj.binaryCol, Data("string".utf8)) XCTAssertEqual(obj.decimalCol, Decimal128(1)) XCTAssertEqual(obj.dateCol, Date(timeIntervalSince1970: -1)) XCTAssertEqual(obj.longCol, Int64(1)) @@ -506,7 +506,7 @@ class SwiftObjectServerTests: SwiftSyncTestCase { let ex = expectation(description: "async open") ex.expectedFulfillmentCount = 2 let config = try configuration() - let completion = { (result: Result) -> Void in + let completion = { (result: Result) in guard case .failure = result else { XCTFail("No error on cancelled async open") return ex.fulfill() diff --git a/Realm/ObjectServerTests/SwiftServerObjects.swift b/Realm/ObjectServerTests/SwiftServerObjects.swift index 1325861a4d..4e71ae32de 100644 --- a/Realm/ObjectServerTests/SwiftServerObjects.swift +++ b/Realm/ObjectServerTests/SwiftServerObjects.swift @@ -63,7 +63,7 @@ public class SwiftTypesSyncObject: Object { @Persisted public var intCol: Int = 1 @Persisted public var doubleCol: Double = 1.1 @Persisted public var stringCol: String = "string" - @Persisted public var binaryCol: Data = "string".data(using: String.Encoding.utf8)! + @Persisted public var binaryCol: Data = Data("string".utf8) @Persisted public var dateCol: Date = Date(timeIntervalSince1970: -1) @Persisted public var longCol: Int64 = 1 @Persisted public var decimalCol: Decimal128 = Decimal128(1) @@ -208,7 +208,7 @@ public class SwiftCustomColumnObject: Object { @Persisted public var intCol: Int = 1 @Persisted public var doubleCol: Double = 1.1 @Persisted public var stringCol: String = "string" - @Persisted public var binaryCol = "string".data(using: String.Encoding.utf8)! + @Persisted public var binaryCol = Data("string".utf8) @Persisted public var dateCol: Date = Date(timeIntervalSince1970: -1) @Persisted public var longCol: Int64 = 1 @Persisted public var decimalCol: Decimal128 = Decimal128(1) diff --git a/Realm/RLMObjectId.mm b/Realm/RLMObjectId.mm index f156b3ae63..1d47c74e45 100644 --- a/Realm/RLMObjectId.mm +++ b/Realm/RLMObjectId.mm @@ -89,7 +89,7 @@ - (id)copyWithZone:(NSZone *)zone { } + (instancetype)objectId { - return [[RLMObjectId alloc] initWithValue:realm::ObjectId::gen()]; + return [[self alloc] initWithValue:realm::ObjectId::gen()]; } - (BOOL)isEqual:(id)object { diff --git a/Realm/TestUtils/TestUtils.mm b/Realm/TestUtils/TestUtils.mm index c4ca7f3085..d4a5b92b97 100644 --- a/Realm/TestUtils/TestUtils.mm +++ b/Realm/TestUtils/TestUtils.mm @@ -166,30 +166,6 @@ bool RLMHasCachedRealmForPath(NSString *path) { return RLMGetAnyCachedRealmForPath(path.UTF8String); } -static std::string serialize(id obj) { - auto data = [NSJSONSerialization dataWithJSONObject:obj - options:0 - error:nil]; - return std::string(static_cast(data.bytes), data.length); -} - -static std::string fakeJWT() { - std::string unencoded_prefix = serialize(@{@"alg": @"HS256"}); - std::string unencoded_body = serialize(@{ - @"user_data": @{@"token": @"dummy token"}, - @"exp": @123, - @"iat": @456, - @"access": @[@"download", @"upload"] - }); - std::string encoded_prefix, encoded_body; - encoded_prefix.resize(realm::util::base64_encoded_size(unencoded_prefix.size())); - encoded_body.resize(realm::util::base64_encoded_size(unencoded_body.size())); - realm::util::base64_encode(unencoded_prefix, encoded_prefix); - realm::util::base64_encode(unencoded_body, encoded_body); - std::string suffix = "Et9HFtf9R3GEMA0IICOfFMVXY7kkTX1wr4qCyhIf58U"; - return encoded_prefix + "." + encoded_body + "." + suffix; -} - // A network transport which doesn't actually do anything @interface NoOpTransport : NSObject @end @@ -261,18 +237,6 @@ + (RLMRealmConfiguration *)fakeFlexibleSyncConfiguration { } @end -// Xcode 13 adds -[NSUUID compare:] so this warns about the category -// implementing a method which already exists, but we can't use just the -// built-in one yet. -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation" -@implementation NSUUID (RLMUUIDCompareTests) -- (NSComparisonResult)compare:(NSUUID *)other { - return [[self UUIDString] compare:other.UUIDString]; -} -@end -#pragma clang diagnostic pop - bool RLMThreadSanitizerEnabled() { #if __has_feature(thread_sanitizer) return true; diff --git a/Realm/TestUtils/include/TestUtils.h b/Realm/TestUtils/include/TestUtils.h index 55b2cfc053..5fddace785 100644 --- a/Realm/TestUtils/include/TestUtils.h +++ b/Realm/TestUtils/include/TestUtils.h @@ -21,21 +21,19 @@ #import +RLM_HEADER_AUDIT_BEGIN(nullability) + FOUNDATION_EXTERN void RLMAssertThrowsWithReasonMatchingSwift(XCTestCase *self, __attribute__((noescape)) dispatch_block_t block, NSString *regexString, - NSString *message, + NSString *_Nullable message, NSString *fileName, NSUInteger lineNumber); @interface RLMRealmConfiguration (TestUser) -+ (RLMRealmConfiguration *_Nonnull)fakeSyncConfiguration; -+ (RLMRealmConfiguration *_Nonnull)fakeFlexibleSyncConfiguration; -@end - -@interface NSUUID (RLMUUIDCompareTests) -- (NSComparisonResult)compare:(NSUUID *)other; ++ (RLMRealmConfiguration *)fakeSyncConfiguration; ++ (RLMRealmConfiguration *)fakeFlexibleSyncConfiguration; @end // It appears to be impossible to check this from Swift so we need a helper function @@ -44,3 +42,4 @@ FOUNDATION_EXTERN bool RLMThreadSanitizerEnabled(void); FOUNDATION_EXTERN bool RLMCanFork(void); FOUNDATION_EXTERN pid_t RLMFork(void); +RLM_HEADER_AUDIT_END(nullability) diff --git a/Realm/Tests/Swift/SwiftObjectInterfaceTests.swift b/Realm/Tests/Swift/SwiftObjectInterfaceTests.swift index a9c1723c50..9c081ccb0f 100644 --- a/Realm/Tests/Swift/SwiftObjectInterfaceTests.swift +++ b/Realm/Tests/Swift/SwiftObjectInterfaceTests.swift @@ -250,10 +250,10 @@ class SwiftRLMObjectInterfaceTests: RLMTestCase { func testPrimitiveArray() { let obj = SwiftRLMPrimitiveArrayObject() let str = "str" as NSString - let data = "str".data(using: .utf8)! as Data as NSData + let data = Data("str".utf8) as NSData let date = NSDate() let str2 = "str2" as NSString - let data2 = "str2".data(using: .utf8)! as Data as NSData + let data2 = Data("str2".utf8) as NSData let date2 = NSDate(timeIntervalSince1970: 0) obj.stringCol.add(str) @@ -291,7 +291,7 @@ class SwiftRLMObjectInterfaceTests: RLMTestCase { func testPrimitiveSet() { let obj = SwiftRLMPrimitiveSetObject() let str = "str" as NSString - let data = "str".data(using: .utf8)! as Data as NSData + let data = Data("str".utf8) as NSData let date = NSDate() obj.stringCol.add(str) XCTAssertTrue(obj.stringCol.contains(str)) diff --git a/Realm/Tests/Swift/SwiftPropertyTypeTest.swift b/Realm/Tests/Swift/SwiftPropertyTypeTest.swift index 364234cfcc..26e331d54d 100644 --- a/Realm/Tests/Swift/SwiftPropertyTypeTest.swift +++ b/Realm/Tests/Swift/SwiftPropertyTypeTest.swift @@ -128,7 +128,7 @@ class SwiftRLMPropertyTypeTest: RLMTestCase { let realm = realmWithTestPath() var object: SwiftRLMObjectiveCTypesObject! let now = NSDate() - let data = "fizzbuzz".data(using: .utf8)! as Data as NSData + let data = Data("fizzbuzz".utf8) as NSData try! realm.transaction { object = SwiftRLMObjectiveCTypesObject() realm.add(object) diff --git a/RealmSwift/AsymmetricObject.swift b/RealmSwift/AsymmetricObject.swift index a431b0a22a..c7c0e59561 100644 --- a/RealmSwift/AsymmetricObject.swift +++ b/RealmSwift/AsymmetricObject.swift @@ -81,8 +81,8 @@ extension AsymmetricObject { It is not considered part of the public API. :nodoc: */ - public override final class func _getProperties() -> [RLMProperty] { - return ObjectUtil.getSwiftProperties(self) + public override static func _getProperties() -> [RLMProperty] { + ObjectUtil.getSwiftProperties(self) } // MARK: Object Customization diff --git a/RealmSwift/EmbeddedObject.swift b/RealmSwift/EmbeddedObject.swift index 9034d864dd..e9a845b08c 100644 --- a/RealmSwift/EmbeddedObject.swift +++ b/RealmSwift/EmbeddedObject.swift @@ -58,8 +58,8 @@ import Realm.Private public typealias EmbeddedObject = RealmSwiftEmbeddedObject extension EmbeddedObject: _RealmCollectionValueInsideOptional { /// :nodoc: - public class override final func isEmbedded() -> Bool { - return true + public static override func isEmbedded() -> Bool { + true } // MARK: Initializers @@ -114,8 +114,8 @@ extension EmbeddedObject: _RealmCollectionValueInsideOptional { It is not considered part of the public API. :nodoc: */ - public override final class func _getProperties() -> [RLMProperty] { - return ObjectUtil.getSwiftProperties(self) + public override static func _getProperties() -> [RLMProperty] { + ObjectUtil.getSwiftProperties(self) } // MARK: Object Customization diff --git a/RealmSwift/List.swift b/RealmSwift/List.swift index 905dc79c48..8c049725c9 100644 --- a/RealmSwift/List.swift +++ b/RealmSwift/List.swift @@ -208,7 +208,7 @@ public final class List: RLMSwiftCollectionBase, rlmArray.exchangeObject(at: UInt(index1), withObjectAt: UInt(index2)) } - @objc class func _unmanagedCollection() -> RLMArray { + @objc static func _unmanagedCollection() -> RLMArray { if let type = Element.self as? ObjectBase.Type { return RLMArray(objectClassName: type.className()) } @@ -222,8 +222,8 @@ public final class List: RLMSwiftCollectionBase, } /// :nodoc: - @objc public override class func _backingCollectionType() -> AnyClass { - return RLMManagedArray.self + @objc public override static func _backingCollectionType() -> AnyClass { + RLMManagedArray.self } // Printable requires a description property defined in Swift (and not obj-c), diff --git a/RealmSwift/Map.swift b/RealmSwift/Map.swift index 64f1422355..88274cefcd 100644 --- a/RealmSwift/Map.swift +++ b/RealmSwift/Map.swift @@ -729,7 +729,7 @@ public final class Map: RLMSwiftColle for more information. */ public func freeze() -> Map { - return Map(objc: rlmDictionary.freeze()) + Map(objc: rlmDictionary.freeze()) } /** @@ -739,10 +739,10 @@ public final class Map: RLMSwiftColle If called on a live `Map`, will return itself. */ public func thaw() -> Map? { - return Map(objc: rlmDictionary.thaw()) + Map(objc: rlmDictionary.thaw()) } - @objc class func _unmanagedCollection() -> RLMDictionary { + @objc static func _unmanagedCollection() -> RLMDictionary { if let type = Value.self as? HasClassName.Type ?? Value.PersistedType.self as? HasClassName.Type { return RLMDictionary(objectClassName: type.className(), keyType: Key._rlmType) } @@ -753,8 +753,8 @@ public final class Map: RLMSwiftColle } /// :nodoc: - @objc public override class func _backingCollectionType() -> AnyClass { - return RLMManagedDictionary.self + @objc public override static func _backingCollectionType() -> AnyClass { + RLMManagedDictionary.self } /** diff --git a/RealmSwift/MutableSet.swift b/RealmSwift/MutableSet.swift index 3521db8616..fb64b1be34 100644 --- a/RealmSwift/MutableSet.swift +++ b/RealmSwift/MutableSet.swift @@ -186,7 +186,7 @@ public final class MutableSet: RLMSwiftCollection rlmSet.union(other.rlmSet) } - @objc class func _unmanagedCollection() -> RLMSet { + @objc static func _unmanagedCollection() -> RLMSet { if let type = Element.self as? ObjectBase.Type { return RLMSet(objectClassName: type.className()) } @@ -197,8 +197,8 @@ public final class MutableSet: RLMSwiftCollection } /// :nodoc: - @objc public override class func _backingCollectionType() -> AnyClass { - return RLMManagedSet.self + @objc public override static func _backingCollectionType() -> AnyClass { + RLMManagedSet.self } // Printable requires a description property defined in Swift (and not obj-c), diff --git a/RealmSwift/Object.swift b/RealmSwift/Object.swift index 99a218b1f6..292407f9f8 100644 --- a/RealmSwift/Object.swift +++ b/RealmSwift/Object.swift @@ -133,8 +133,8 @@ extension Object: _RealmCollectionValueInsideOptional { It is not considered part of the public API. :nodoc: */ - public override final class func _getProperties() -> [RLMProperty] { - return ObjectUtil.getSwiftProperties(self) + public override static func _getProperties() -> [RLMProperty] { + ObjectUtil.getSwiftProperties(self) } // MARK: Object Customization @@ -713,7 +713,7 @@ public final class DynamicObject: Object { /// :nodoc: public override func value(forUndefinedKey key: String) -> Any? { - return self[key] + self[key] } /// :nodoc: @@ -722,11 +722,11 @@ public final class DynamicObject: Object { } /// :nodoc: - public override class func shouldIncludeInDefaultSchema() -> Bool { - return false + public override static func shouldIncludeInDefaultSchema() -> Bool { + false } - override public class func sharedSchema() -> RLMObjectSchema? { + override public static func sharedSchema() -> RLMObjectSchema? { nil } diff --git a/RealmSwift/ObjectId.swift b/RealmSwift/ObjectId.swift index 8813f72a04..9a7b6f47dd 100644 --- a/RealmSwift/ObjectId.swift +++ b/RealmSwift/ObjectId.swift @@ -39,10 +39,12 @@ public final class ObjectId: RLMObjectId, Decodable, @unchecked Sendable { super.init() } + // swiftlint:disable unneeded_override /// Creates a new randomly-initialized ObjectId. - public override class func generate() -> ObjectId { - return unsafeDowncast(super.generate(), to: ObjectId.self) + public override static func generate() -> ObjectId { + super.generate() } + // swiftlint:enable unneeded_override /// Creates a new ObjectId from the given 24-byte hexadecimal string. /// diff --git a/RealmSwift/Tests/CodableTests.swift b/RealmSwift/Tests/CodableTests.swift index d377d44a59..9a8bf17963 100644 --- a/RealmSwift/Tests/CodableTests.swift +++ b/RealmSwift/Tests/CodableTests.swift @@ -305,10 +305,10 @@ class CodableTests: TestCase { func encode(_ value: T?) -> String { let opt = RealmOptional() opt.value = value - return try! String(data: encoder.encode([opt]), encoding: .utf8)! + return try! String(decoding: encoder.encode([opt]), as: UTF8.self) } func encode(_ value: T?) -> String { - return try! String(data: encoder.encode([value]), encoding: .utf8)! + return try! String(decoding: encoder.encode([value]), as: UTF8.self) } func legacyObjectString(_ nullRealmProperty: Bool = false) -> String { @@ -1217,6 +1217,7 @@ class CodableTests: TestCase { // Verify that it encodes to exactly the original string (which requires // that the original string be formatted how JSONEncoder formats things) encoder.outputFormatting = [.prettyPrinted, .sortedKeys] + // swiftlint:disable:next non_optional_string_data_conversion let actual = try String(data: encoder.encode(obj), encoding: .utf8) XCTAssertEqual(str, actual) @@ -1598,6 +1599,7 @@ class CodableTests: TestCase { // Verify that it encodes to exactly the original string (which requires // that the original string be formatted how JSONEncoder formats things) encoder.outputFormatting = [.prettyPrinted, .sortedKeys] + // swiftlint:disable:next non_optional_string_data_conversion let actual = try String(data: encoder.encode(obj), encoding: .utf8) XCTAssertEqual(str, actual) } @@ -1811,6 +1813,7 @@ class CodableTests: TestCase { obj.objectId = ObjectId("1234567890abcdef12345678") obj.uuid = UUID(uuidString: "00000000-0000-0000-0000-000000000000")! obj.date = Date(timeIntervalSince1970: 0) + // swiftlint:disable:next non_optional_string_data_conversion let actual = try String(data: encoder.encode(obj), encoding: .utf8) let expected = #"{"bool":false,"bool_list":[],"bool_map":{},"bool_opt":null,"bool_opt_list":[],"bool_opt_map":{},"bool_opt_set":[],"bool_set":[],"data":"","data_list":[],"data_map":{},"data_opt":null,"data_opt_list":[],"data_opt_map":{},"data_opt_set":[],"data_set":[],"date":-978307200,"date_list":[],"date_map":{},"date_opt":null,"date_opt_list":[],"date_opt_map":{},"date_opt_set":[],"date_set":[],"decimal":"0","decimal_list":[],"decimal_map":{},"decimal_opt":null,"decimal_opt_list":[],"decimal_opt_map":{},"decimal_opt_set":[],"decimal_set":[],"double":0,"double_list":[],"double_map":{},"double_opt":null,"double_opt_list":[],"double_opt_map":{},"double_opt_set":[],"double_set":[],"embedded_object_list":[],"embedded_object_opt":null,"embedded_object_opt_map":{},"float":0,"float_list":[],"float_map":{},"float_opt":null,"float_opt_list":[],"float_opt_map":{},"float_opt_set":[],"float_set":[],"int":0,"int_list":[],"int_map":{},"int_opt":null,"int_opt_list":[],"int_opt_map":{},"int_opt_set":[],"int_set":[],"int8":0,"int8_list":[],"int8_map":{},"int8_opt":null,"int8_opt_list":[],"int8_opt_map":{},"int8_opt_set":[],"int8_set":[],"int16":0,"int16_list":[],"int16_map":{},"int16_opt":null,"int16_opt_list":[],"int16_opt_map":{},"int16_opt_set":[],"int16_set":[],"int32":0,"int32_list":[],"int32_map":{},"int32_opt":null,"int32_opt_list":[],"int32_opt_map":{},"int32_opt_set":[],"int32_set":[],"int64":0,"int64_list":[],"int64_map":{},"int64_opt":null,"int64_opt_list":[],"int64_opt_map":{},"int64_opt_set":[],"int64_set":[],"object_id":"1234567890abcdef12345678","object_id_list":[],"object_id_map":{},"object_id_opt":null,"object_id_opt_list":[],"object_id_opt_map":{},"object_id_opt_set":[],"object_id_set":[],"object_list":[],"object_opt":null,"object_opt_map":{},"object_set":[],"string":"","string_list":[],"string_map":{},"string_opt":null,"string_opt_list":[],"string_opt_map":{},"string_opt_set":[],"string_set":[],"uuid":"00000000-0000-0000-0000-000000000000","uuid_list":[],"uuid_map":{},"uuid_opt":null,"uuid_opt_list":[],"uuid_opt_map":{},"uuid_opt_set":[],"uuid_set":[]}"# XCTAssertEqual(expected, actual) diff --git a/RealmSwift/Tests/KeyPathTests.swift b/RealmSwift/Tests/KeyPathTests.swift index 90e98d3c98..57c8a0f08e 100644 --- a/RealmSwift/Tests/KeyPathTests.swift +++ b/RealmSwift/Tests/KeyPathTests.swift @@ -564,7 +564,7 @@ class SwiftOldSyntaxAllTypesObject: Object { @objc dynamic var floatCol = 1.23 as Float @objc dynamic var doubleCol = 12.3 @objc dynamic var stringCol = "a" - @objc dynamic var binaryCol = "a".data(using: String.Encoding.utf8)! + @objc dynamic var binaryCol = Data("a".utf8) @objc dynamic var dateCol = Date(timeIntervalSince1970: 1) @objc dynamic var decimalCol = Decimal128("123e4") @objc dynamic var objectIdCol = ObjectId("1234567890ab1234567890ab") @@ -597,7 +597,7 @@ class SwiftOldSyntaxAllTypesEmbeddedObject: EmbeddedObject { @objc dynamic var floatCol = 1.23 as Float @objc dynamic var doubleCol = 12.3 @objc dynamic var stringCol = "a" - @objc dynamic var binaryCol = "a".data(using: String.Encoding.utf8)! + @objc dynamic var binaryCol = Data("a".utf8) @objc dynamic var dateCol = Date(timeIntervalSince1970: 1) @objc dynamic var decimalCol = Decimal128("123e4") @objc dynamic var objectIdCol = ObjectId("1234567890ab1234567890ab") @@ -634,7 +634,7 @@ class ModernAllTypesEmbeddedObject: EmbeddedObject { @Persisted var floatCol = 1.23 as Float @Persisted var doubleCol = 12.3 @Persisted var stringCol = "a" - @Persisted var binaryCol = "a".data(using: String.Encoding.utf8)! + @Persisted var binaryCol = Data("a".utf8) @Persisted var dateCol = Date(timeIntervalSince1970: 1) @Persisted var decimalCol = Decimal128("123e4") @Persisted var objectIdCol = ObjectId("1234567890ab1234567890ab") diff --git a/RealmSwift/Tests/MigrationTests.swift b/RealmSwift/Tests/MigrationTests.swift index e1990ec0ae..be414e1965 100644 --- a/RealmSwift/Tests/MigrationTests.swift +++ b/RealmSwift/Tests/MigrationTests.swift @@ -851,7 +851,7 @@ class MigrationTests: TestCase { XCTAssertEqual((oldObj["decimalCol"] as! Decimal128), 123e4 as Decimal128) XCTAssertEqual((newObj["decimalCol"] as! Decimal128), 123e4 as Decimal128) - let binaryCol = "a".data(using: String.Encoding.utf8)! + let binaryCol = Data("a".utf8) XCTAssertEqual((oldObj["binaryCol"] as! Data), binaryCol) XCTAssertEqual((newObj["binaryCol"] as! Data), binaryCol) diff --git a/RealmSwift/Tests/ModernObjectCreationTests.swift b/RealmSwift/Tests/ModernObjectCreationTests.swift index e75bc0af51..a4884c1131 100644 --- a/RealmSwift/Tests/ModernObjectCreationTests.swift +++ b/RealmSwift/Tests/ModernObjectCreationTests.swift @@ -33,7 +33,7 @@ class ModernObjectCreationTests: TestCase { "floatCol": 15 as Float, "doubleCol": 16 as Double, "stringCol": "a", - "binaryCol": "b".data(using: .utf8)!, + "binaryCol": Data("b".utf8), "dateCol": Date(timeIntervalSince1970: 17), "decimalCol": 18 as Decimal128, "objectIdCol": ObjectId.generate(), @@ -61,7 +61,7 @@ class ModernObjectCreationTests: TestCase { "optFloatCol": 35 as Float, "optDoubleCol": 36 as Double, "optStringCol": "c", - "optBinaryCol": "d".data(using: .utf8)!, + "optBinaryCol": Data("d".utf8), "optDateCol": Date(timeIntervalSince1970: 37), "optDecimalCol": 38 as Decimal128, "optObjectIdCol": ObjectId.generate(), @@ -78,7 +78,7 @@ class ModernObjectCreationTests: TestCase { "arrayFloat": [1 as Float, 2 as Float, 3 as Float, 1 as Float], "arrayDouble": [1 as Double, 2 as Double, 3 as Double, 1 as Double], "arrayString": ["a", "b", "c"] as [String], - "arrayBinary": ["a".data(using: .utf8)!] as [Data], + "arrayBinary": [Data("a".utf8)] as [Data], "arrayDate": [Date(), Date()] as [Date], "arrayDecimal": [1 as Decimal128, 2 as Decimal128], "arrayObjectId": [ObjectId.generate(), ObjectId.generate()], @@ -94,7 +94,7 @@ class ModernObjectCreationTests: TestCase { "arrayOptFloat": [1 as Float, 2 as Float, 3 as Float, 1 as Float, nil], "arrayOptDouble": [1 as Double, 2 as Double, 3 as Double, 1 as Double, nil], "arrayOptString": ["a", "b", "c", nil], - "arrayOptBinary": ["a".data(using: .utf8)!, nil], + "arrayOptBinary": [Data("a".utf8), nil], "arrayOptDate": [Date(), Date(), nil], "arrayOptDecimal": [1 as Decimal128, 2 as Decimal128, nil], "arrayOptObjectId": [ObjectId.generate(), ObjectId.generate(), nil], @@ -109,7 +109,7 @@ class ModernObjectCreationTests: TestCase { "setFloat": [1 as Float, 2 as Float, 3 as Float, 1 as Float], "setDouble": [1 as Double, 2 as Double, 3 as Double, 1 as Double], "setString": ["a", "b", "c"] as [String], - "setBinary": ["a".data(using: .utf8)!] as [Data], + "setBinary": [Data("a".utf8)] as [Data], "setDate": [Date(), Date()] as [Date], "setDecimal": [1 as Decimal128, 2 as Decimal128], "setObjectId": [ObjectId.generate(), ObjectId.generate()], @@ -125,7 +125,7 @@ class ModernObjectCreationTests: TestCase { "setOptFloat": [1 as Float, 2 as Float, 3 as Float, 1 as Float, nil], "setOptDouble": [1 as Double, 2 as Double, 3 as Double, 1 as Double, nil], "setOptString": ["a", "b", "c", nil], - "setOptBinary": ["a".data(using: .utf8)!, nil], + "setOptBinary": [Data("a".utf8), nil], "setOptDate": [Date(), Date(), nil], "setOptDecimal": [1 as Decimal128, 2 as Decimal128, nil], "setOptObjectId": [ObjectId.generate(), ObjectId.generate(), nil], @@ -140,7 +140,7 @@ class ModernObjectCreationTests: TestCase { "mapFloat": ["1": 1 as Float, "2": 2 as Float, "3": 3 as Float, "4": 1 as Float], "mapDouble": ["1": 1 as Double, "2": 2 as Double, "3": 3 as Double, "4": 1 as Double], "mapString": ["1": "a", "2": "b", "3": "c"] as [String: String], - "mapBinary": ["1": "a".data(using: .utf8)!] as [String: Data], + "mapBinary": ["1": Data("a".utf8)] as [String: Data], "mapDate": ["1": Date(), "2": Date()] as [String: Date], "mapDecimal": ["1": 1 as Decimal128, "2": 2 as Decimal128], "mapObjectId": ["1": ObjectId.generate(), "2": ObjectId.generate()], @@ -156,7 +156,7 @@ class ModernObjectCreationTests: TestCase { "mapOptFloat": ["1": 1 as Float, "2": 2 as Float, "3": 3 as Float, "4": 1 as Float, "5": nil], "mapOptDouble": ["1": 1 as Double, "2": 2 as Double, "3": 3 as Double, "4": 1 as Double, "5": nil], "mapOptString": ["1": "a", "2": "b", "3": "c", "4": nil], - "mapOptBinary": ["1": "a".data(using: .utf8)!, "2": nil], + "mapOptBinary": ["1": Data("a".utf8), "2": nil], "mapOptDate": ["1": Date(), "2": Date(), "3": nil], "mapOptDecimal": ["1": 1 as Decimal128, "2": 2 as Decimal128, "3": nil], "mapOptObjectId": ["1": ObjectId.generate(), "2": ObjectId.generate(), "3": nil], diff --git a/RealmSwift/Tests/ObjectCreationTests.swift b/RealmSwift/Tests/ObjectCreationTests.swift index 4797cec4b3..1c46cbf174 100644 --- a/RealmSwift/Tests/ObjectCreationTests.swift +++ b/RealmSwift/Tests/ObjectCreationTests.swift @@ -82,7 +82,7 @@ class ObjectCreationTests: TestCase { "floatCol": 1.1 as Float, "doubleCol": 11.1, "stringCol": "b", - "binaryCol": "b".data(using: String.Encoding.utf8)!, + "binaryCol": Data("b".utf8), "dateCol": Date(timeIntervalSince1970: 2), "decimalCol": 3 as Decimal128, "objectIdCol": ObjectId.generate(), @@ -129,7 +129,7 @@ class ObjectCreationTests: TestCase { func testInitWithArray() { // array with all values specified let baselineValues: [Any] = [true, 1, Int8(1), Int16(1), Int32(1), Int64(1), IntEnum.value1.rawValue, 1.1 as Float, - 11.1, "b", "b".data(using: String.Encoding.utf8)!, + 11.1, "b", Data("b".utf8), Date(timeIntervalSince1970: 2), Decimal128(number: 123), ObjectId.generate(), ["boolCol": true], UUID(uuidString: "137decc8-b300-4954-a233-f89909f4fd89")!, @@ -247,7 +247,7 @@ class ObjectCreationTests: TestCase { "floatCol": 1.1 as Float, "doubleCol": 11.1, "stringCol": "b", - "binaryCol": "b".data(using: String.Encoding.utf8)!, + "binaryCol": Data("b".utf8), "dateCol": Date(timeIntervalSince1970: 2), "decimalCol": 3 as Decimal128, "objectIdCol": ObjectId.generate(), @@ -303,7 +303,7 @@ class ObjectCreationTests: TestCase { func testCreateWithArray() { // array with all values specified let baselineValues: [Any] = [true, 1, Int8(1), Int16(1), Int32(1), Int64(1), IntEnum.value1.rawValue, 1.1 as Float, - 11.1, "b", "b".data(using: String.Encoding.utf8)!, + 11.1, "b", Data("b".utf8), Date(timeIntervalSince1970: 2), Decimal128(number: 123), ObjectId.generate(), ["boolCol": true], UUID(uuidString: "137decc8-b300-4954-a233-f89909f4fd89")!, @@ -429,7 +429,7 @@ class ObjectCreationTests: TestCase { "floatCol": 1.1 as Float, "doubleCol": 11.1, "stringCol": "b", - "binaryCol": "b".data(using: String.Encoding.utf8)!, + "binaryCol": Data("b".utf8), "dateCol": Date(timeIntervalSince1970: 2), "decimalCol": 3 as Decimal128, "objectIdCol": ObjectId.generate(), @@ -464,7 +464,7 @@ class ObjectCreationTests: TestCase { "floatCol": 1.1 as Float, "doubleCol": 11.1, "stringCol": "b", - "binaryCol": "b".data(using: String.Encoding.utf8)!, + "binaryCol": Data("b".utf8), "dateCol": Date(timeIntervalSince1970: 2), "decimalCol": 3 as Decimal128, "objectIdCol": ObjectId.generate(), @@ -559,7 +559,7 @@ class ObjectCreationTests: TestCase { "floatCol": 1.1, "doubleCol": 11.1, "stringCol": "b", - "binaryCol": "b".data(using: String.Encoding.utf8)!, + "binaryCol": Data("b".utf8), "dateCol": Date(timeIntervalSince1970: 2), "decimalCol": 3 as Decimal128, "objectIdCol": ObjectId.generate(), diff --git a/RealmSwift/Tests/ObjectTests.swift b/RealmSwift/Tests/ObjectTests.swift index 2b64850a83..714a1c4655 100644 --- a/RealmSwift/Tests/ObjectTests.swift +++ b/RealmSwift/Tests/ObjectTests.swift @@ -315,7 +315,7 @@ class ObjectTests: TestCase { XCTAssertNil(object.value(forKey: "anyCol")) let expected = object.value(forKey: "binaryCol") as! Data - let actual = "a".data(using: String.Encoding.utf8)! + let actual = Data("a".utf8) XCTAssertEqual(expected, actual) XCTAssertEqual(object.value(forKey: "dateCol") as! Date?, Date(timeIntervalSince1970: 1)) @@ -526,9 +526,9 @@ class ObjectTests: TestCase { setter(object, "z", "stringCol") XCTAssertEqual(getter(object, "stringCol") as! String?, "z") - setter(object, "z".data(using: String.Encoding.utf8)! as Data, "binaryCol") + setter(object, Data("z".utf8), "binaryCol") let gotData = getter(object, "binaryCol") as! Data - XCTAssertTrue(gotData == "z".data(using: String.Encoding.utf8)!) + XCTAssertTrue(gotData == Data("z".utf8)) setter(object, Date(timeIntervalSince1970: 333), "dateCol") XCTAssertEqual(getter(object, "dateCol") as! Date?, Date(timeIntervalSince1970: 333)) @@ -629,9 +629,9 @@ class ObjectTests: TestCase { setter(object, "z", "stringCol") XCTAssertEqual((getter(object, "stringCol") as! String), "z") - setter(object, "z".data(using: String.Encoding.utf8)! as Data, "binaryCol") + setter(object, Data("z".utf8), "binaryCol") let gotData = getter(object, "binaryCol") as! Data - XCTAssertTrue(gotData == "z".data(using: String.Encoding.utf8)!) + XCTAssertTrue(gotData == Data("z".utf8)) setter(object, Date(timeIntervalSince1970: 333), "dateCol") XCTAssertEqual((getter(object, "dateCol") as! Date), Date(timeIntervalSince1970: 333)) @@ -805,7 +805,7 @@ class ObjectTests: TestCase { let realm = try! Realm() var object: SwiftObjectiveCTypesObject! let now = NSDate() - let data = "fizzbuzz".data(using: .utf8)! as Data as NSData + let data = Data("fizzbuzz".utf8) as NSData try! realm.write { object = SwiftObjectiveCTypesObject() realm.add(object) @@ -1881,7 +1881,7 @@ class ObjectTests: TestCase { "floatCol": 4.56 as Float, "doubleCol": 45.6, "stringCol": "b", - "binaryCol": "b".data(using: String.Encoding.utf8)!, + "binaryCol": Data("b".utf8), "dateCol": Date(timeIntervalSince1970: 2), "objectCol": [true], "uuidCol": UUID(), @@ -1910,7 +1910,7 @@ class ObjectTests: TestCase { "float": [6.6 as Float], "double": [7.7], "string": ["8"], - "data": ["9".data(using: String.Encoding.utf8)!], + "data": [Data("9".utf8)], "date": [Date(timeIntervalSince1970: 10)], "intOpt": [11, nil], "int8Opt": [12, nil], @@ -1920,7 +1920,7 @@ class ObjectTests: TestCase { "floatOpt": [16.16, nil], "doubleOpt": [17.17, nil], "stringOpt": ["18", nil], - "dataOpt": ["19".data(using: String.Encoding.utf8)!, nil], + "dataOpt": [Data("19".utf8), nil], "dateOpt": [Date(timeIntervalSince1970: 20), nil], "uuid": [UUID()], "uuidOpt": [UUID(), nil], diff --git a/RealmSwift/Tests/ProjectionTests.swift b/RealmSwift/Tests/ProjectionTests.swift index 3d8b60e11d..cd27f3fe3d 100644 --- a/RealmSwift/Tests/ProjectionTests.swift +++ b/RealmSwift/Tests/ProjectionTests.swift @@ -288,7 +288,7 @@ class ProjectionTests: TestCase { "floatCol": 15 as Float, "doubleCol": 16 as Double, "stringCol": "a", - "binaryCol": "b".data(using: .utf8)!, + "binaryCol": Data("b".utf8), "dateCol": Date(timeIntervalSince1970: 17), "decimalCol": 18 as Decimal128, "objectIdCol": ObjectId("6058f12b957ba06156586a7c"), @@ -315,7 +315,7 @@ class ProjectionTests: TestCase { "optFloatCol": 35 as Float, "optDoubleCol": 36 as Double, "optStringCol": "c", - "optBinaryCol": "d".data(using: .utf8)!, + "optBinaryCol": Data("d".utf8), "optDateCol": Date(timeIntervalSince1970: 37), "optDecimalCol": 38 as Decimal128, "optObjectIdCol": ObjectId("6058f12b957ba06156586a7c"), @@ -331,7 +331,7 @@ class ProjectionTests: TestCase { "arrayFloat": [1 as Float, 2 as Float, 3 as Float, 1 as Float], "arrayDouble": [1 as Double, 2 as Double, 3 as Double, 1 as Double], "arrayString": ["a", "b", "c"] as [String], - "arrayBinary": ["a".data(using: .utf8)!] as [Data], + "arrayBinary": [Data("a".utf8)] as [Data], "arrayDate": [Date(timeIntervalSince1970: 0), Date(timeIntervalSince1970: 1)] as [Date], "arrayDecimal": [1 as Decimal128, 2 as Decimal128], "arrayObjectId": [ObjectId("6058f12b957ba06156586a7c"), ObjectId("6058f12682b2fbb1f334ef1d")], @@ -346,7 +346,7 @@ class ProjectionTests: TestCase { "arrayOptFloat": [1 as Float, 2 as Float, 3 as Float, 1 as Float, nil], "arrayOptDouble": [1 as Double, 2 as Double, 3 as Double, 1 as Double, nil], "arrayOptString": ["a", "b", "c", nil], - "arrayOptBinary": ["a".data(using: .utf8)!, nil], + "arrayOptBinary": [Data("a".utf8), nil], "arrayOptDate": [Date(timeIntervalSince1970: 0), Date(timeIntervalSince1970: 1), nil], "arrayOptDecimal": [1 as Decimal128, 2 as Decimal128, nil], "arrayOptObjectId": [ObjectId("6058f12b957ba06156586a7c"), ObjectId("6058f12682b2fbb1f334ef1d"), nil], @@ -360,7 +360,7 @@ class ProjectionTests: TestCase { "setFloat": [1 as Float, 2 as Float, 3 as Float, 1 as Float], "setDouble": [1 as Double, 2 as Double, 3 as Double, 1 as Double], "setString": ["a", "b", "c"] as [String], - "setBinary": ["a".data(using: .utf8)!] as [Data], + "setBinary": [Data("a".utf8)] as [Data], "setDate": [Date(timeIntervalSince1970: 1), Date(timeIntervalSince1970: 2)] as [Date], "setDecimal": [1 as Decimal128, 2 as Decimal128], "setObjectId": [ObjectId("6058f12b957ba06156586a7c"), @@ -378,7 +378,7 @@ class ProjectionTests: TestCase { "setOptFloat": [1 as Float, 2 as Float, 3 as Float, 1 as Float, nil], "setOptDouble": [1 as Double, 2 as Double, 3 as Double, 1 as Double, nil], "setOptString": ["a", "b", "c", nil], - "setOptBinary": ["a".data(using: .utf8)!, nil], + "setOptBinary": [Data("a".utf8), nil], "setOptDate": [Date(timeIntervalSince1970: 1), Date(timeIntervalSince1970: 2), nil], "setOptDecimal": [1 as Decimal128, 2 as Decimal128, nil], "setOptObjectId": [ObjectId("6058f12b957ba06156586a7c"), ObjectId("6058f12682b2fbb1f334ef1d"), nil], @@ -395,7 +395,7 @@ class ProjectionTests: TestCase { "mapFloat": ["1": 1 as Float, "2": 2 as Float, "3": 3 as Float, "4": 1 as Float], "mapDouble": ["1": 1 as Double, "2": 2 as Double, "3": 3 as Double, "4": 1 as Double], "mapString": ["1": "a", "2": "b", "3": "c"] as [String: String], - "mapBinary": ["1": "a".data(using: .utf8)!] as [String: Data], + "mapBinary": ["1": Data("a".utf8)] as [String: Data], "mapDate": ["1": Date(timeIntervalSince1970: 1), "2": Date(timeIntervalSince1970: 2)] as [String: Date], "mapDecimal": ["1": 1 as Decimal128, "2": 2 as Decimal128], "mapObjectId": ["1": ObjectId("6058f12b957ba06156586a7c"), @@ -413,7 +413,7 @@ class ProjectionTests: TestCase { "mapOptFloat": ["1": 1 as Float, "2": 2 as Float, "3": 3 as Float, "4": 1 as Float, "5": nil], "mapOptDouble": ["1": 1 as Double, "2": 2 as Double, "3": 3 as Double, "4": 1 as Double, "5": nil], "mapOptString": ["1": "a", "2": "b", "3": "c", "4": nil], - "mapOptBinary": ["1": "a".data(using: .utf8)!, "2": nil], + "mapOptBinary": ["1": Data("a".utf8), "2": nil], "mapOptDate": ["1": Date(timeIntervalSince1970: 1), "2": Date(timeIntervalSince1970: 2), "3": nil], "mapOptDecimal": ["1": 1 as Decimal128, "2": 2 as Decimal128, "3": nil], "mapOptObjectId": ["1": ObjectId("6058f12b957ba06156586a7c"), @@ -804,7 +804,7 @@ class ProjectionTests: TestCase { let obj = realm.objects(ModernAllTypesObject.self).first! let obs = realm.objects(AllTypesPrimitiveProjection.self).first! - let data = "c".data(using: String.Encoding.utf8)! + let data = Data("c".utf8) let date = Date(timeIntervalSince1970: 7) let decimal = Decimal128(number: 3) let objectId = ObjectId.generate() @@ -1093,7 +1093,7 @@ class ProjectionTests: TestCase { func testAllPropertyTypes() { var (obj, obs) = newObjects(allTypeValues) - let data = "b".data(using: String.Encoding.utf8)! + let data = Data("b".utf8) let date = Date(timeIntervalSince1970: 2) let decimal = Decimal128(number: 3) let objectId = ObjectId() diff --git a/RealmSwift/Tests/QueryTests.swift b/RealmSwift/Tests/QueryTests.swift index 1e3e7cd86a..36a76dfb4e 100644 --- a/RealmSwift/Tests/QueryTests.swift +++ b/RealmSwift/Tests/QueryTests.swift @@ -3722,7 +3722,6 @@ class QueryTests: TestCase { XCTAssertEqual(obj.map.where(q2).count, 1) } - // swiftlint:disable opening_brace test(LinkToModernAllTypesObject.self, "(boolCol == %@)", false, { $0.boolCol == false }, @@ -3963,7 +3962,6 @@ class QueryTests: TestCase { UUIDWrapper(persistedValue: UUID(uuidString: "33041937-05b2-464a-98ad-3910cbe0d09f")!), { $0.optUuid == UUIDWrapper(persistedValue: UUID(uuidString: "33041937-05b2-464a-98ad-3910cbe0d09f")!) }, { $0.optUuid == UUIDWrapper(persistedValue: UUID(uuidString: "33041937-05b2-464a-98ad-3910cbe0d09f")!) }) - // swiftlint:enable opening_brace } func testSetContainsObject() { diff --git a/RealmSwift/Tests/RealmTests.swift b/RealmSwift/Tests/RealmTests.swift index b476cd47b1..1da2f85e27 100644 --- a/RealmSwift/Tests/RealmTests.swift +++ b/RealmSwift/Tests/RealmTests.swift @@ -833,7 +833,7 @@ class RealmTests: TestCase { func testRemoveNotification() { let realm = try! Realm() var notificationCalled = false - let token = realm.observe { (_, realm) -> Void in + let token = realm.observe { (_, realm) in XCTAssertEqual(realm.configuration.fileURL, self.defaultRealmURL()) notificationCalled = true } diff --git a/RealmSwift/Tests/SwiftTestObjects.swift b/RealmSwift/Tests/SwiftTestObjects.swift index 2613b9c01c..e3adc56891 100644 --- a/RealmSwift/Tests/SwiftTestObjects.swift +++ b/RealmSwift/Tests/SwiftTestObjects.swift @@ -81,7 +81,7 @@ class SwiftObject: Object { @objc dynamic var floatCol = 1.23 as Float @objc dynamic var doubleCol = 12.3 @objc dynamic var stringCol = "a" - @objc dynamic var binaryCol = "a".data(using: String.Encoding.utf8)! + @objc dynamic var binaryCol = Data("a".utf8) @objc dynamic var dateCol = Date(timeIntervalSince1970: 1) @objc dynamic var decimalCol = Decimal128("123e4") @objc dynamic var objectIdCol = ObjectId("1234567890ab1234567890ab") @@ -104,7 +104,7 @@ class SwiftObject: Object { "floatCol": 1.23 as Float, "doubleCol": 12.3, "stringCol": "a", - "binaryCol": "a".data(using: String.Encoding.utf8)!, + "binaryCol": Data("a".utf8), "dateCol": Date(timeIntervalSince1970: 1), "decimalCol": Decimal128("123e4"), "objectIdCol": ObjectId("1234567890ab1234567890ab"), @@ -254,7 +254,7 @@ class SwiftImplicitlyUnwrappedOptionalObject: Object { class SwiftOptionalDefaultValuesObject: Object { @objc dynamic var optNSStringCol: NSString? = "A" @objc dynamic var optStringCol: String? = "B" - @objc dynamic var optBinaryCol: Data? = "C".data(using: String.Encoding.utf8)! as Data + @objc dynamic var optBinaryCol: Data? = Data("C".utf8) @objc dynamic var optDateCol: Date? = Date(timeIntervalSince1970: 10) @objc dynamic var optDecimalCol: Decimal128? = "123" @objc dynamic var optObjectIdCol: ObjectId? = ObjectId("1234567890ab1234567890ab") @@ -273,7 +273,7 @@ class SwiftOptionalDefaultValuesObject: Object { return [ "optNSStringCol": "A", "optStringCol": "B", - "optBinaryCol": "C".data(using: String.Encoding.utf8)!, + "optBinaryCol": Data("C".utf8), "optDateCol": Date(timeIntervalSince1970: 10), "optDecimalCol": Decimal128("123"), "optObjectIdCol": ObjectId("1234567890ab1234567890ab"), @@ -295,7 +295,7 @@ class SwiftOptionalIgnoredPropertiesObject: Object { @objc dynamic var optNSStringCol: NSString? = "A" @objc dynamic var optStringCol: String? = "B" - @objc dynamic var optBinaryCol: Data? = "C".data(using: String.Encoding.utf8)! as Data + @objc dynamic var optBinaryCol: Data? = Data("C".utf8) @objc dynamic var optDateCol: Date? = Date(timeIntervalSince1970: 10) @objc dynamic var optDecimalCol: Decimal128? = "123" @objc dynamic var optObjectIdCol: ObjectId? = ObjectId("1234567890ab1234567890ab") diff --git a/RealmSwift/Tests/TestUtils.swift b/RealmSwift/Tests/TestUtils.swift index 1cdb49a8bb..64e42ba9b8 100644 --- a/RealmSwift/Tests/TestUtils.swift +++ b/RealmSwift/Tests/TestUtils.swift @@ -278,6 +278,7 @@ public func assertPreconditionFailure(_ message: String, _ expression: () asy guard let data = try pipe.fileHandleForReading.readToEnd() else { return XCTFail("Expected child process to crash with message \"\(message)\", but it exited without printing anything", file: file, line: line) } + // swiftlint:disable:next non_optional_string_data_conversion guard let str = String(data: data, encoding: .utf8) else { return XCTFail("Expected child process to crash with message \"\(message)\", but it did not print valid utf-8", file: file, line: line) } diff --git a/RealmSwift/Tests/TestValueFactory.swift b/RealmSwift/Tests/TestValueFactory.swift index 771d2ff567..1f4738aadf 100644 --- a/RealmSwift/Tests/TestValueFactory.swift +++ b/RealmSwift/Tests/TestValueFactory.swift @@ -362,7 +362,7 @@ extension String: MapValueFactoryOptional { // MARK: - Data extension Data: ValueFactory { - private static let _values: [Data] = ["a".data(using: .utf8)!, "b".data(using: .utf8)!, "c".data(using: .utf8)!] + private static let _values: [Data] = [Data("a".utf8), Data("b".utf8), Data("c".utf8)] static func values() -> [Data] { return _values } diff --git a/build.sh b/build.sh index 52b01c01e1..22c3ff4735 100755 --- a/build.sh +++ b/build.sh @@ -1343,9 +1343,9 @@ x.y.z Release notes (yyyy-MM-dd) ### Compatibility * Realm Studio: 15.0.0 or later. * APIs are backwards compatible with all previous releases in the 10.x.y series. -* Carthage release for Swift is built with Xcode 15.3.0. +* Carthage release for Swift is built with Xcode 15.4.0. * CocoaPods: 1.10 or later. -* Xcode: 15.1.0-15.3.0. +* Xcode: 15.1.0-15.4.0. ### Internal * Upgraded realm-core from ? to ? diff --git a/examples/tvos/swift/DownloadCache/RepositoriesViewController.swift b/examples/tvos/swift/DownloadCache/RepositoriesViewController.swift index 306c22cc1b..0a84ab5302 100644 --- a/examples/tvos/swift/DownloadCache/RepositoriesViewController.swift +++ b/examples/tvos/swift/DownloadCache/RepositoriesViewController.swift @@ -80,7 +80,7 @@ class RepositoriesViewController: UICollectionViewController, UITextFieldDelegat let repository = results![indexPath.item] cell.titleLabel.text = repository.name - URLSession.shared.dataTask(with: URLRequest(url: URL(string: repository.avatarURL!)!)) { (data, _, error) -> Void in + URLSession.shared.dataTask(with: URLRequest(url: URL(string: repository.avatarURL!)!)) { (data, _, error) in if let error = error { print(error.localizedDescription) return diff --git a/scripts/package_examples.rb b/scripts/package_examples.rb index 4f3c2d06be..d3341b2cbc 100755 --- a/scripts/package_examples.rb +++ b/scripts/package_examples.rb @@ -44,7 +44,7 @@ def replace_framework(example, framework, path) "examples/tvos/swift", ] -xcode_versions = %w(15.1 15.2 15.3) +xcode_versions = %w(15.1 15.2 15.3 15.4) # Remove reference to Realm.xcodeproj from all example workspaces. base_examples.each do |example| diff --git a/scripts/pr-ci-matrix.rb b/scripts/pr-ci-matrix.rb index 2690979912..b3beb155da 100755 --- a/scripts/pr-ci-matrix.rb +++ b/scripts/pr-ci-matrix.rb @@ -86,7 +86,7 @@ def action # because they don't care about Xcode versions, while some others are latest-only # because they're particularly slow to run. module Workflows - XCODE_VERSIONS = %w(15.1 15.2 15.3) + XCODE_VERSIONS = %w(15.1 15.2 15.3 15.4) all = ->(v) { true } latest_only = ->(v) { v == XCODE_VERSIONS.last }