Skip to content

Commit

Permalink
Renamed "changed" to "modified" to align with JS
Browse files Browse the repository at this point in the history
  • Loading branch information
tgoyne committed May 24, 2019
1 parent 8d55465 commit 104f4d7
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 30 deletions.
10 changes: 5 additions & 5 deletions Realm/RLMObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ NS_ASSUME_NONNULL_BEGIN
given property name (or getter name, if defined), that value will remain untouched.
Nullable properties on the object can be set to nil by using `NSNull` as the updated value.
Each property is set even if the existing value is the same as the new value being set, and
notifications will report them all being changed. See `createOrUpdateChangedInDefaultRealmWithValue:`
notifications will report them all being changed. See `createOrUpdateModifiedInDefaultRealmWithValue:`
for a version of this function which only sets the values which have changed.
If the `value` argument is an array, all properties must be present, valid and in the same
Expand All @@ -218,7 +218,7 @@ NS_ASSUME_NONNULL_BEGIN
an object with the same primary key value in the default Realm, its values are updated and the object
is returned. Otherwise, this method creates and populates a new instance of the object in the default Realm.
If nested objects are included in the argument, `createOrUpdateChangedInDefaultRealmWithValue:` will be
If nested objects are included in the argument, `createOrUpdateModifiedInDefaultRealmWithValue:` will be
recursively called on them if they have primary keys, `createInDefaultRealmWithValue:` if they do not.
The `value` argument is used to populate the object. It can be a Realm object, a key-value coding
Expand Down Expand Up @@ -253,7 +253,7 @@ NS_ASSUME_NONNULL_BEGIN
@see `defaultPropertyValues`, `primaryKey`
*/
+ (instancetype)createOrUpdateChangedInDefaultRealmWithValue:(id)value;
+ (instancetype)createOrUpdateModifiedInDefaultRealmWithValue:(id)value;

/**
Creates or updates an Realm object within a specified Realm.
Expand Down Expand Up @@ -281,7 +281,7 @@ NS_ASSUME_NONNULL_BEGIN
given property name (or getter name, if defined), that value will remain untouched.
Nullable properties on the object can be set to nil by using `NSNull` as the updated value.
Each property is set even if the existing value is the same as the new value being set, and
notifications will report them all being changed. See `createOrUpdateChangedInRealm:withValue:`
notifications will report them all being changed. See `createOrUpdateModifiedInRealm:withValue:`
for a version of this function which only sets the values which have changed.
If the `value` argument is an array, all properties must be present, valid and in the same
Expand Down Expand Up @@ -337,7 +337,7 @@ NS_ASSUME_NONNULL_BEGIN
@see `defaultPropertyValues`, `primaryKey`
*/
+ (instancetype)createOrUpdateChangedInRealm:(RLMRealm *)realm withValue:(id)value;
+ (instancetype)createOrUpdateModifiedInRealm:(RLMRealm *)realm withValue:(id)value;

#pragma mark - Properties

Expand Down
6 changes: 3 additions & 3 deletions Realm/RLMObject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ + (instancetype)createOrUpdateInDefaultRealmWithValue:(id)value {
return [self createOrUpdateInRealm:[RLMRealm defaultRealm] withValue:value];
}

+ (instancetype)createOrUpdateChangedInDefaultRealmWithValue:(id)value {
return [self createOrUpdateChangedInRealm:[RLMRealm defaultRealm] withValue:value];
+ (instancetype)createOrUpdateModifiedInDefaultRealmWithValue:(id)value {
return [self createOrUpdateModifiedInRealm:[RLMRealm defaultRealm] withValue:value];
}

+ (instancetype)createOrUpdateInRealm:(RLMRealm *)realm withValue:(id)value {
RLMVerifyHasPrimaryKey(self);
return (RLMObject *)RLMCreateObjectInRealmWithValue(realm, [self className], value, RLMUpdatePolicyUpdateAll);
}

+ (instancetype)createOrUpdateChangedInRealm:(RLMRealm *)realm withValue:(id)value {
+ (instancetype)createOrUpdateModifiedInRealm:(RLMRealm *)realm withValue:(id)value {
RLMVerifyHasPrimaryKey(self);
return (RLMObject *)RLMCreateObjectInRealmWithValue(realm, [self className], value, RLMUpdatePolicyUpdateChanged);
}
Expand Down
2 changes: 1 addition & 1 deletion Realm/Tests/NotificationTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,7 @@ - (void)testDiffedUpdatesOnlyNotifyForPropertiesWhichActuallyChanged {

[realm beginWriteTransaction];
values[i] = _values[i];
[AllTypesWithPrimaryKey createOrUpdateChangedInRealm:realm withValue:values];
[AllTypesWithPrimaryKey createOrUpdateModifiedInRealm:realm withValue:values];
[realm commitWriteTransaction];

[self waitForExpectationsWithTimeout:2.0 handler:nil];
Expand Down
14 changes: 7 additions & 7 deletions RealmSwift/Realm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public final class Realm {
to be written to the Realm file. If all of the properties are changing, it may be slower than .all (but
will never result in *more* data being written).
*/
case changed = 1
case modified = 1
/**
Overwrite all properties in the existing object with the new values, even if they have not changed. This
results in change notifications reporting all properties as changed, and influences the sync merge logic.
Expand Down Expand Up @@ -315,7 +315,7 @@ public final class Realm {
- parameter update: If `true`, the Realm will try to find an existing copy of the object (with the same primary
key), and update it. Otherwise, the object will be added.
*/
@available(*, deprecated, message: "Pass .error, .changed or .all rather than a boolean. .error is equivalent to false and .all is equivalent to true.")
@available(*, deprecated, message: "Pass .error, .modified or .all rather than a boolean. .error is equivalent to false and .all is equivalent to true.")
public func add(_ object: Object, update: Bool) {
add(object, update: update ? .all : .error)
}
Expand Down Expand Up @@ -360,7 +360,7 @@ public final class Realm {
- parameter objects: A sequence which contains objects to be added to the Realm.
- parameter update: If `true`, objects that are already in the Realm will be updated instead of added anew.
*/
@available(*, deprecated, message: "Pass .error, .changed or .all rather than a boolean. .error is equivalent to false and .all is equivalent to true.")
@available(*, deprecated, message: "Pass .error, .modified or .all rather than a boolean. .error is equivalent to false and .all is equivalent to true.")
public func add<S: Sequence>(_ objects: S, update: Bool) where S.Iterator.Element: Object {
for obj in objects {
add(obj, update: update)
Expand Down Expand Up @@ -422,7 +422,7 @@ public final class Realm {
- returns: The newly created object.
*/
@discardableResult
@available(*, deprecated, message: "Pass .error, .changed or .all rather than a boolean. .error is equivalent to false and .all is equivalent to true.")
@available(*, deprecated, message: "Pass .error, .modified or .all rather than a boolean. .error is equivalent to false and .all is equivalent to true.")
public func create<T: Object>(_ type: T.Type, value: Any = [:], update: Bool) -> T {
return create(type, value: value, update: update ? .all : .error)
}
Expand All @@ -438,7 +438,7 @@ public final class Realm {

If the object type does not have a primary key or no object with the specified primary key
already exists, a new object is created in the Realm. If an object already exists in the Realm
with the specified primary key and the update policy is `.changed` or `.all`, the existing
with the specified primary key and the update policy is `.modified` or `.all`, the existing
object will be updated and a reference to that object will be returned.

If the object is being updated, all properties defined in its schema will be set by copying
Expand Down Expand Up @@ -507,7 +507,7 @@ public final class Realm {
:nodoc:
*/
@discardableResult
@available(*, deprecated, message: "Pass .error, .changed or .all rather than a boolean. .error is equivalent to false and .all is equivalent to true.")
@available(*, deprecated, 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 {
return dynamicCreate(typeName, value: value, update: update ? .all : .error)
}
Expand All @@ -528,7 +528,7 @@ public final class Realm {

If the object type does not have a primary key or no object with the specified primary key
already exists, a new object is created in the Realm. If an object already exists in the Realm
with the specified primary key and the update policy is `.changed` or `.all`, the existing
with the specified primary key and the update policy is `.modified` or `.all`, the existing
object will be updated and a reference to that object will be returned.

If the object is being updated, all properties defined in its schema will be set by copying
Expand Down
2 changes: 1 addition & 1 deletion RealmSwift/Sync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,7 @@ extension List where Element == Permission {
*/
public func findOrCreate(forRoleNamed roleName: String) -> Permission {
precondition(realm != nil, "Cannot be called on an unmanaged object")
return RLMPermissionForRole(_rlmArray, realm!.create(PermissionRole.self, value: [roleName], update: .changed)) as! Permission
return RLMPermissionForRole(_rlmArray, realm!.create(PermissionRole.self, value: [roleName], update: .modified)) as! Permission
}

/**
Expand Down
26 changes: 13 additions & 13 deletions RealmSwift/Tests/ObjectCreationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ class ObjectCreationTests: TestCase {
let standalone = SwiftPrimaryStringObject(value: ["primary", 11])
try! Realm().beginWrite()
let object = try! Realm().create(SwiftLinkToPrimaryStringObject.self, value: ["otherPrimary", ["primary", 12],
[["primary", 12]]], update: .changed)
[["primary", 12]]], update: .modified)
try! Realm().commitWrite()

let stringObjects = try! Realm().objects(SwiftPrimaryStringObject.self)
Expand Down Expand Up @@ -468,7 +468,7 @@ class ObjectCreationTests: TestCase {

try! Realm().beginWrite()
try! Realm().create(SwiftLinkToPrimaryStringObject.self, value: ["primary", ["10", 10], [["11", 11]]])
let object = try! Realm().create(SwiftLinkToPrimaryStringObject.self, value: otherRealmObject, update: .changed)
let object = try! Realm().create(SwiftLinkToPrimaryStringObject.self, value: otherRealmObject, update: .modified)
try! Realm().commitWrite()

XCTAssertNotEqual(otherRealmObject, object) // the object from the other realm should be copied into this realm
Expand Down Expand Up @@ -603,12 +603,12 @@ class ObjectCreationTests: TestCase {
realm.cancelWrite()
}

func testCreateOrUpdateChangedNil() {
func testCreateOrUpdateModifiedNil() {
let realm = try! Realm()
realm.beginWrite()

// Create with all fields nil
let object = realm.create(SwiftOptionalPrimaryObject.self, value: SwiftOptionalPrimaryObject(), update: .changed)
let object = realm.create(SwiftOptionalPrimaryObject.self, value: SwiftOptionalPrimaryObject(), update: .modified)

XCTAssertNil(object.id.value)
XCTAssertNil(object.optIntCol.value)
Expand Down Expand Up @@ -640,7 +640,7 @@ class ObjectCreationTests: TestCase {
object2.optNSStringCol = ""
object2.optBinaryCol = Data()
object2.optObjectCol = SwiftBoolObject()
realm.create(SwiftOptionalPrimaryObject.self, value: object2, update: .changed)
realm.create(SwiftOptionalPrimaryObject.self, value: object2, update: .modified)

XCTAssertNil(object.id.value)
XCTAssertNotNil(object.optIntCol.value)
Expand All @@ -658,7 +658,7 @@ class ObjectCreationTests: TestCase {
XCTAssertNotNil(object.optObjectCol)

// Try to switch back to nil
realm.create(SwiftOptionalPrimaryObject.self, value: SwiftOptionalPrimaryObject(), update: .changed)
realm.create(SwiftOptionalPrimaryObject.self, value: SwiftOptionalPrimaryObject(), update: .modified)

XCTAssertNil(object.id.value)

Expand All @@ -684,7 +684,7 @@ class ObjectCreationTests: TestCase {
let unmanagedValue = SwiftOptionalPrimaryObject()
// Shouldn't throw.
realm.beginWrite()
_ = realm.create(type(of: unmanagedValue), value: unmanagedValue, update: .changed)
_ = realm.create(type(of: unmanagedValue), value: unmanagedValue, update: .modified)
realm.cancelWrite()
}

Expand All @@ -700,15 +700,15 @@ class ObjectCreationTests: TestCase {
realm.cancelWrite()
}

func testCreateOrUpdateChangedDynamicManagedType() {
func testCreateOrUpdateModifiedDynamicManagedType() {
let realm = try! Realm()
let managedValue = SwiftOptionalPrimaryObject()
try! realm.write {
realm.add(managedValue)
}
// Shouldn't throw.
realm.beginWrite()
_ = realm.create(type(of: managedValue), value: managedValue, update: .changed)
_ = realm.create(type(of: managedValue), value: managedValue, update: .modified)
realm.cancelWrite()
}

Expand Down Expand Up @@ -753,7 +753,7 @@ class ObjectCreationTests: TestCase {

try! Realm().beginWrite()
let object = SwiftLinkToPrimaryStringObject(value: ["primary", ["primary", 2], []])
try! Realm().add(object, update: .changed)
try! Realm().add(object, update: .modified)
try! Realm().commitWrite()

XCTAssertNotNil(object.realm)
Expand Down Expand Up @@ -863,7 +863,7 @@ class ObjectCreationTests: TestCase {
realm.cancelWrite()
}

func testAddOrUpdateChangedNil() {
func testAddOrUpdateModifiedNil() {
let realm = try! Realm()
realm.beginWrite()

Expand Down Expand Up @@ -901,7 +901,7 @@ class ObjectCreationTests: TestCase {
object2.optNSStringCol = ""
object2.optBinaryCol = Data()
object2.optObjectCol = SwiftBoolObject()
realm.add(object2, update: .changed)
realm.add(object2, update: .modified)

XCTAssertNil(object.id.value)
XCTAssertNotNil(object.optIntCol.value)
Expand All @@ -920,7 +920,7 @@ class ObjectCreationTests: TestCase {

// Try to switch back to nil
let object3 = SwiftOptionalPrimaryObject()
realm.add(object3, update: .changed)
realm.add(object3, update: .modified)

XCTAssertNil(object.id.value)
XCTAssertNil(object.optIntCol.value)
Expand Down

0 comments on commit 104f4d7

Please sign in to comment.