Skip to content

Commit dc14fce

Browse files
authored
Merge pull request #672 from zapcannon87/master
feat!(object): new API for fetching object
2 parents 6cc7cb4 + 9de137c commit dc14fce

File tree

13 files changed

+536
-564
lines changed

13 files changed

+536
-564
lines changed

AVOS/AVOS.xcodeproj/project.pbxproj

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@
5151
D30B6A5A24A09D23006ABE09 /* LCRequestManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7068A7221BA3614D0004623A /* LCRequestManager.m */; };
5252
D30B6A5B24A09D23006ABE09 /* LCRelation_Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C841A581A5A79FF00C5C6C4 /* LCRelation_Internal.h */; };
5353
D30B6A5C24A09D23006ABE09 /* LCSubclassing.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C841A591A5A79FF00C5C6C4 /* LCSubclassing.h */; settings = {ATTRIBUTES = (Public, ); }; };
54-
D30B6A5D24A09D23006ABE09 /* LCSaveOption.h in Headers */ = {isa = PBXBuildFile; fileRef = 830EB9F21C44D68400BA917F /* LCSaveOption.h */; settings = {ATTRIBUTES = (Public, ); }; };
55-
D30B6A5E24A09D23006ABE09 /* LCSaveOption_internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 830EB9FE1C44F3D600BA917F /* LCSaveOption_internal.h */; };
56-
D30B6A5F24A09D23006ABE09 /* LCSaveOption.m in Sources */ = {isa = PBXBuildFile; fileRef = 830EB9F31C44D68400BA917F /* LCSaveOption.m */; };
54+
D30B6A5D24A09D23006ABE09 /* LCObjectOption.h in Headers */ = {isa = PBXBuildFile; fileRef = 830EB9F21C44D68400BA917F /* LCObjectOption.h */; settings = {ATTRIBUTES = (Public, ); }; };
55+
D30B6A5E24A09D23006ABE09 /* LCObjectOption_Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 830EB9FE1C44F3D600BA917F /* LCObjectOption_Internal.h */; };
56+
D30B6A5F24A09D23006ABE09 /* LCObjectOption.m in Sources */ = {isa = PBXBuildFile; fileRef = 830EB9F31C44D68400BA917F /* LCObjectOption.m */; };
5757
D30B6A6024A09D52006ABE09 /* LCInstallation.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C841A5B1A5A79FF00C5C6C4 /* LCInstallation.h */; settings = {ATTRIBUTES = (Public, ); }; };
5858
D30B6A6124A09D52006ABE09 /* LCInstallation.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C841A5C1A5A79FF00C5C6C4 /* LCInstallation.m */; };
5959
D30B6A6224A09D52006ABE09 /* LCInstallation_Internal.h in Headers */ = {isa = PBXBuildFile; fileRef = 8C841A5D1A5A79FF00C5C6C4 /* LCInstallation_Internal.h */; };
@@ -348,9 +348,9 @@
348348
830E7CFA1B1CAD3B005F4B22 /* LCDatabaseMigrator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCDatabaseMigrator.h; sourceTree = "<group>"; };
349349
830E7CFB1B1CAD3B005F4B22 /* LCDatabaseMigrator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LCDatabaseMigrator.m; sourceTree = "<group>"; };
350350
830E7CFE1B1CB07B005F4B22 /* LCDatabaseCommon.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCDatabaseCommon.h; sourceTree = "<group>"; };
351-
830EB9F21C44D68400BA917F /* LCSaveOption.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCSaveOption.h; sourceTree = "<group>"; };
352-
830EB9F31C44D68400BA917F /* LCSaveOption.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LCSaveOption.m; sourceTree = "<group>"; };
353-
830EB9FE1C44F3D600BA917F /* LCSaveOption_internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCSaveOption_internal.h; sourceTree = "<group>"; };
351+
830EB9F21C44D68400BA917F /* LCObjectOption.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCObjectOption.h; sourceTree = "<group>"; };
352+
830EB9F31C44D68400BA917F /* LCObjectOption.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LCObjectOption.m; sourceTree = "<group>"; };
353+
830EB9FE1C44F3D600BA917F /* LCObjectOption_Internal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCObjectOption_Internal.h; sourceTree = "<group>"; };
354354
830F159E1F010F260009B4D0 /* LCIMRecalledMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCIMRecalledMessage.h; sourceTree = "<group>"; };
355355
830F159F1F010F260009B4D0 /* LCIMRecalledMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LCIMRecalledMessage.m; sourceTree = "<group>"; };
356356
831E29581D882CBB006E502B /* LCIMMessageOption.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LCIMMessageOption.h; sourceTree = "<group>"; };
@@ -944,9 +944,9 @@
944944
7068A7221BA3614D0004623A /* LCRequestManager.m */,
945945
8C841A581A5A79FF00C5C6C4 /* LCRelation_Internal.h */,
946946
8C841A591A5A79FF00C5C6C4 /* LCSubclassing.h */,
947-
830EB9F21C44D68400BA917F /* LCSaveOption.h */,
948-
830EB9FE1C44F3D600BA917F /* LCSaveOption_internal.h */,
949-
830EB9F31C44D68400BA917F /* LCSaveOption.m */,
947+
830EB9F21C44D68400BA917F /* LCObjectOption.h */,
948+
830EB9FE1C44F3D600BA917F /* LCObjectOption_Internal.h */,
949+
830EB9F31C44D68400BA917F /* LCObjectOption.m */,
950950
);
951951
path = Object;
952952
sourceTree = "<group>";
@@ -1484,7 +1484,7 @@
14841484
D30B6B2324A09F59006ABE09 /* AVIMGenericCommand+AVIMMessagesAdditions.h in Headers */,
14851485
D30B6AF824A09F1F006ABE09 /* LCGPBMessage.h in Headers */,
14861486
D30B6A2924A09B1F006ABE09 /* LCApplication_Internal.h in Headers */,
1487-
D30B6A5E24A09D23006ABE09 /* LCSaveOption_internal.h in Headers */,
1487+
D30B6A5E24A09D23006ABE09 /* LCObjectOption_Internal.h in Headers */,
14881488
D30B6A9E24A09E35006ABE09 /* LCErrorUtils.h in Headers */,
14891489
D30B6A6824A09D62006ABE09 /* LCCloudQueryResult_Internal.h in Headers */,
14901490
D30B6AAB24A09E35006ABE09 /* LCKeyValueStore.h in Headers */,
@@ -1528,7 +1528,7 @@
15281528
D30B6A8124A09DCA006ABE09 /* LCNetworking.h in Headers */,
15291529
D30B6B3B24A09F79006ABE09 /* LCIMConversationCacheStore.h in Headers */,
15301530
D30B6A4224A09CC2006ABE09 /* LCScheduler.h in Headers */,
1531-
D30B6A5D24A09D23006ABE09 /* LCSaveOption.h in Headers */,
1531+
D30B6A5D24A09D23006ABE09 /* LCObjectOption.h in Headers */,
15321532
D30B6AEF24A09F1E006ABE09 /* LCGPBEmpty.pbobjc.h in Headers */,
15331533
D30B6AEB24A09F1E006ABE09 /* LCGPBDictionary.h in Headers */,
15341534
D30B6A7E24A09DCA006ABE09 /* LCCompatibilityMacros.h in Headers */,
@@ -1687,7 +1687,7 @@
16871687
D30B6AB524A09E35006ABE09 /* LCDynamicObject.m in Sources */,
16881688
D30B6A4124A09CC2006ABE09 /* LCPersistenceUtils.m in Sources */,
16891689
D30B6A4324A09CC2006ABE09 /* LCScheduler.m in Sources */,
1690-
D30B6A5F24A09D23006ABE09 /* LCSaveOption.m in Sources */,
1690+
D30B6A5F24A09D23006ABE09 /* LCObjectOption.m in Sources */,
16911691
D30B6A5824A09D23006ABE09 /* LCRelation.m in Sources */,
16921692
D30B6A7224A09D7B006ABE09 /* LCPaasClient.m in Sources */,
16931693
D30B6B4E24A09F85006ABE09 /* LCIMFileMessage.m in Sources */,

AVOS/LeanCloudObjc/Foundation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// Object
2727
#import "LCObject.h"
2828
#import "LCObject+Subclass.h"
29-
#import "LCSaveOption.h"
29+
#import "LCObjectOption.h"
3030
#import "LCSubclassing.h"
3131
#import "LCRelation.h"
3232

AVOS/LeanCloudObjcTests/LCUserTestCase.swift

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,4 +372,83 @@ class LCUserTestCase: BaseTestCase {
372372
}
373373
}
374374
}
375+
376+
func testFetch() {
377+
let objectWithInvalidID = LCObject(objectId: uuid)
378+
XCTAssertFalse(objectWithInvalidID.fetch())
379+
do {
380+
try objectWithInvalidID.fetchAndThrows()
381+
XCTFail()
382+
} catch {
383+
XCTAssertEqual((error as NSError).code, kLCErrorObjectNotFound)
384+
}
385+
do {
386+
try objectWithInvalidID.fetch(with: nil)
387+
XCTFail()
388+
} catch {
389+
XCTAssertEqual((error as NSError).code, kLCErrorObjectNotFound)
390+
}
391+
do {
392+
try LCObject.fetchAll([objectWithInvalidID], error: ())
393+
XCTFail()
394+
} catch {
395+
XCTAssertNotNil(error)
396+
}
397+
398+
let validObject = LCObject()
399+
let childObject = LCObject()
400+
let key = "childObject"
401+
validObject[key] = childObject
402+
XCTAssertTrue(validObject.save())
403+
404+
guard let objectId = validObject.objectId else {
405+
XCTFail()
406+
return
407+
}
408+
409+
expecting { exp in
410+
let object = LCObject(objectId: objectId)
411+
object.fetchInBackground { obj, error in
412+
XCTAssertTrue(Thread.isMainThread)
413+
XCTAssertTrue(obj === object)
414+
XCTAssertNil(error)
415+
let child = object[key] as? LCObject
416+
XCTAssertEqual(child?.objectId, childObject.objectId)
417+
XCTAssertNil(child?.createdAt)
418+
XCTAssertNil(child?.updatedAt)
419+
exp.fulfill()
420+
}
421+
}
422+
423+
expecting { exp in
424+
let object = LCObject(objectId: objectId)
425+
let option = LCObjectFetchOption()
426+
option.selectKeys = [key]
427+
option.includeKeys = [key]
428+
object.fetchInBackground(with: option) { obj, error in
429+
XCTAssertTrue(Thread.isMainThread)
430+
XCTAssertTrue(obj === object)
431+
XCTAssertNil(error)
432+
let child = object[key] as? LCObject
433+
XCTAssertEqual(child?.objectId, childObject.objectId)
434+
XCTAssertNotNil(child?.createdAt)
435+
XCTAssertNotNil(child?.updatedAt)
436+
exp.fulfill()
437+
}
438+
}
439+
440+
expecting { exp in
441+
let object = LCObject(objectId: objectId)
442+
LCObject.fetchAll(inBackground: [object]) { objects, error in
443+
XCTAssertTrue(Thread.isMainThread)
444+
XCTAssertEqual(objects?.count, 1)
445+
let child = (objects?.first as? LCObject)?[key] as? LCObject
446+
XCTAssertEqual(child?.objectId, childObject.objectId)
447+
XCTAssertNil(child?.createdAt)
448+
XCTAssertNil(child?.updatedAt)
449+
XCTAssertNil(error)
450+
exp.fulfill()
451+
}
452+
}
453+
}
375454
}

0 commit comments

Comments
 (0)