Compare commits

..

9 Commits
7.0.0 ... 7.0.1

Author SHA1 Message Date
John Estropia
f3beca8769 fix compiler error in testcases 2019-10-25 16:17:25 +09:00
John Estropia
4baeb6d922 Fix weak linking of SwiftUI in podspec 2019-10-25 14:35:04 +09:00
John Estropia
98d860aff6 Add unit tests for List and Object Publishers 2019-10-25 14:34:22 +09:00
John Estropia
11a9e3991c changed ListPublisher and ObjectPublisher factory method naming to match ListMonitor and ObjectMonitor naming 2019-10-25 12:43:39 +09:00
John Estropia
f380d9dc25 ObjectSnapshot: allow dynamicMember keyPaths from superclasses 2019-10-25 12:36:13 +09:00
John Estropia
d546ff154f Merge pull request #344 from timfraedrich/patch-1
small correction to documentation
2019-10-23 19:27:33 +09:00
John Estropia
f21597d332 Merge pull request #341 from dmatushkin/develop
Fix for build on iOS with Swift Package Manager
2019-10-23 19:27:01 +09:00
Tim Fraedrich
56d9719984 small correction to documentation
While using some code from the documentation that led to issues I noticed that some parts of it are not accurate anymore, so I corrected a few small things that came to my attention. Maybe it is worth having an even closer look though.
2019-10-04 14:19:14 +00:00
dmatushkin
6d75dcbc32 Fix for build on iOS with Swift Package Manager 2019-09-15 14:57:20 +04:00
15 changed files with 487 additions and 649 deletions

View File

@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "CoreStore"
s.version = "7.0.0"
s.version = "7.0.1"
s.swift_version = "5.1"
s.license = "MIT"
s.homepage = "https://github.com/JohnEstropia/CoreStore"
@@ -18,5 +18,5 @@ Pod::Spec.new do |s|
s.public_header_files = "Sources/**/*.h"
s.frameworks = "Foundation", "CoreData"
s.requires_arc = true
s.pod_target_xcconfig = { 'OTHER_SWIFT_FLAGS[config=Debug]' => '-D DEBUG', 'OTHER_LDFLAGS' => '-weak_framework Combine' }
s.pod_target_xcconfig = { 'OTHER_SWIFT_FLAGS[config=Debug]' => '-D DEBUG', 'OTHER_LDFLAGS' => '-weak_framework Combine -weak_framework SwiftUI' }
end

View File

@@ -522,6 +522,9 @@
B580857A1CDF808C004C2EEB /* SetupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B58085741CDF7F00004C2EEB /* SetupTests.swift */; };
B580857B1CDF808D004C2EEB /* SetupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B58085741CDF7F00004C2EEB /* SetupTests.swift */; };
B580857C1CDF808F004C2EEB /* SetupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B58085741CDF7F00004C2EEB /* SetupTests.swift */; };
B581B9322362BB8C002BDB2B /* ObjectPublisherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B581B9312362BB8C002BDB2B /* ObjectPublisherTests.swift */; };
B581B9332362BB8C002BDB2B /* ObjectPublisherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B581B9312362BB8C002BDB2B /* ObjectPublisherTests.swift */; };
B581B9342362BB8C002BDB2B /* ObjectPublisherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B581B9312362BB8C002BDB2B /* ObjectPublisherTests.swift */; };
B5831B701F34AC3400A9F647 /* AttributeProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5831B6F1F34AC3400A9F647 /* AttributeProtocol.swift */; };
B5831B711F34AC3400A9F647 /* AttributeProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5831B6F1F34AC3400A9F647 /* AttributeProtocol.swift */; };
B5831B721F34AC3400A9F647 /* AttributeProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5831B6F1F34AC3400A9F647 /* AttributeProtocol.swift */; };
@@ -994,6 +997,7 @@
B57D27BD1D0BBE8200539C58 /* BaseTestDataTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseTestDataTestCase.swift; sourceTree = "<group>"; };
B57D27C11D0BC20100539C58 /* QueryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryTests.swift; sourceTree = "<group>"; };
B58085741CDF7F00004C2EEB /* SetupTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SetupTests.swift; sourceTree = "<group>"; };
B581B9312362BB8C002BDB2B /* ObjectPublisherTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectPublisherTests.swift; sourceTree = "<group>"; };
B5831B6F1F34AC3400A9F647 /* AttributeProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttributeProtocol.swift; sourceTree = "<group>"; };
B5831B741F34AC7A00A9F647 /* RelationshipProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelationshipProtocol.swift; sourceTree = "<group>"; };
B5831B791F34ACBA00A9F647 /* Transformable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Transformable.swift; sourceTree = "<group>"; };
@@ -1262,6 +1266,7 @@
B5D8CA7A2346EC550055D7D1 /* ListPublisherTests.swift */,
B5DC47C51C93D22900FA3BF3 /* MigrationChainTests.swift */,
B5220E071D0C5F8D009BC71E /* ObjectObserverTests.swift */,
B581B9312362BB8C002BDB2B /* ObjectPublisherTests.swift */,
B52557771D02826E00E51965 /* OrderByTests.swift */,
B57D27C11D0BC20100539C58 /* QueryTests.swift */,
B52557831D02A07400E51965 /* SectionByTests.swift */,
@@ -2285,6 +2290,7 @@
B5220E0C1D0D0D19009BC71E /* ImportTests.swift in Sources */,
B5D339B41E925C2B00C880DE /* DynamicModelTests.swift in Sources */,
B5D372841A39CD6900F583D9 /* Model.xcdatamodeld in Sources */,
B581B9322362BB8C002BDB2B /* ObjectPublisherTests.swift in Sources */,
B52557881D02DE8100E51965 /* FetchTests.swift in Sources */,
B5489F501CF603D5008B4978 /* FromTests.swift in Sources */,
B52557781D02826E00E51965 /* OrderByTests.swift in Sources */,
@@ -2508,6 +2514,7 @@
B5220E0D1D0D0D19009BC71E /* ImportTests.swift in Sources */,
B5D339B51E925C2B00C880DE /* DynamicModelTests.swift in Sources */,
B525576D1CFAF18F00E51965 /* IntoTests.swift in Sources */,
B581B9332362BB8C002BDB2B /* ObjectPublisherTests.swift in Sources */,
B580857B1CDF808D004C2EEB /* SetupTests.swift in Sources */,
B52557891D02DE8100E51965 /* FetchTests.swift in Sources */,
B5489F511CF603D5008B4978 /* FromTests.swift in Sources */,
@@ -2731,6 +2738,7 @@
B525576E1CFAF18F00E51965 /* IntoTests.swift in Sources */,
B5D339B61E925C2B00C880DE /* DynamicModelTests.swift in Sources */,
B580857C1CDF808F004C2EEB /* SetupTests.swift in Sources */,
B581B9342362BB8C002BDB2B /* ObjectPublisherTests.swift in Sources */,
B525578A1D02DE8100E51965 /* FetchTests.swift in Sources */,
B5220E281D1308E5009BC71E /* SectionByTests.swift in Sources */,
B5489F521CF603D5008B4978 /* FromTests.swift in Sources */,
@@ -3105,7 +3113,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 7.0.0;
MARKETING_VERSION = 7.0.1;
OTHER_LDFLAGS = (
"-weak_framework",
Combine,
@@ -3128,7 +3136,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 7.0.0;
MARKETING_VERSION = 7.0.1;
OTHER_LDFLAGS = (
"-weak_framework",
Combine,

View File

@@ -79,7 +79,7 @@ struct ColorsDemo {
static let palettes: ListPublisher<Palette> = {
return ColorsDemo.stack.listPublisher(
return ColorsDemo.stack.publishList(
From<Palette>()
.sectionBy(\.colorName)
.orderBy(.ascending(\.hue))

View File

@@ -31,7 +31,7 @@ final class SwiftUIContainerViewController: UIViewController {
let hostingController = UIHostingController(
rootView: SwiftUIView(
palettes: ColorsDemo.stack.listPublisher(
palettes: ColorsDemo.stack.publishList(
From<Palette>()
.sectionBy(\.colorName)
.orderBy(.ascending(\.hue))

View File

@@ -171,7 +171,7 @@ struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
SwiftUIView(
palettes: ColorsDemo.stack.listPublisher(
palettes: ColorsDemo.stack.publishList(
From<Palette>()
.sectionBy(\.colorName)
.orderBy(.ascending(\.hue))

View File

@@ -41,99 +41,26 @@ class ListPublisherTests: BaseTestDataTestCase {
self.prepareStack { (stack) in
// let observer = TestListObserver()
let listPublisher = stack.listPublisher(
let observer = NSObject()
let listPublisher = stack.publishList(
From<TestEntity1>(),
SectionBy(#keyPath(TestEntity1.testBoolean)),
OrderBy<TestEntity1>(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID)))
)
// monitor.addObserver(observer)
//
// XCTAssertFalse(monitor.hasSections())
// XCTAssertFalse(monitor.hasObjects())
// XCTAssertTrue(monitor.objectsInAllSections().isEmpty)
//
// var events = 0
//
// let willChangeExpectation = self.expectation(
// forNotification: NSNotification.Name(rawValue: "listMonitorWillChange:"),
// object: observer,
// handler: { (note) -> Bool in
//
// XCTAssertEqual(events, 0)
// XCTAssertEqual((note.userInfo as NSDictionary?) ?? [:], NSDictionary())
// defer {
//
// events += 1
// }
// return events == 0
// }
// )
// let didInsertSectionExpectation = self.expectation(
// forNotification: NSNotification.Name(rawValue: "listMonitor:didInsertSection:toSectionIndex:"),
// object: observer,
// handler: { (note) -> Bool in
//
// XCTAssertEqual(events, 1)
// XCTAssertEqual(
// ((note.userInfo as NSDictionary?) ?? [:]),
// [
// "sectionInfo": monitor.sectionInfo(at: 0),
// "sectionIndex": 0
// ] as NSDictionary
// )
// defer {
//
// events += 1
// }
// return events == 1
// }
// )
// let didInsertObjectExpectation = self.expectation(
// forNotification: NSNotification.Name(rawValue: "listMonitor:didInsertObject:toIndexPath:"),
// object: observer,
// handler: { (note) -> Bool in
//
// XCTAssertEqual(events, 2)
//
// let userInfo = note.userInfo
// XCTAssertNotNil(userInfo)
// XCTAssertEqual(
// Set(userInfo?.keys.map({ $0 as! String }) ?? []),
// ["indexPath", "object"]
// )
//
// let indexPath = userInfo?["indexPath"] as? NSIndexPath
// XCTAssertEqual(indexPath?.index(atPosition: 0), 0)
// XCTAssertEqual(indexPath?.index(atPosition: 1), 0)
//
// let object = userInfo?["object"] as? TestEntity1
// XCTAssertEqual(object?.testBoolean, NSNumber(value: true))
// XCTAssertEqual(object?.testNumber, NSNumber(value: 1))
// XCTAssertEqual(object?.testDecimal, NSDecimalNumber(string: "1"))
// XCTAssertEqual(object?.testString, "nil:TestEntity1:1")
// XCTAssertEqual(object?.testData, ("nil:TestEntity1:1" as NSString).data(using: String.Encoding.utf8.rawValue)!)
// XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-01T00:00:00Z")!)
// defer {
//
// events += 1
// }
// return events == 2
// }
// )
// let didChangeExpectation = self.expectation(
// forNotification: NSNotification.Name(rawValue: "listMonitorDidChange:"),
// object: observer,
// handler: { (note) -> Bool in
//
// XCTAssertEqual((note.userInfo as NSDictionary?) ?? [:], NSDictionary())
// defer {
//
// events += 1
// }
// return events == 3
// }
// )
XCTAssertFalse(listPublisher.snapshot.hasSections())
XCTAssertFalse(listPublisher.snapshot.hasItems())
XCTAssertTrue(listPublisher.snapshot.itemIDs.isEmpty)
let didChangeExpectation = self.expectation(description: "didChange")
listPublisher.addObserver(observer) { listPublisher in
XCTAssertTrue(listPublisher.snapshot.hasSections())
XCTAssertTrue(listPublisher.snapshot.hasItems())
XCTAssertEqual(listPublisher.snapshot.numberOfItems(inSectionIndex: 0), 1)
didChangeExpectation.fulfill()
}
let saveExpectation = self.expectation(description: "save")
stack.perform(
asynchronous: { (transaction) -> Bool in
@@ -161,522 +88,216 @@ class ListPublisherTests: BaseTestDataTestCase {
self.waitAndCheckExpectations()
withExtendedLifetime(listPublisher, {})
withExtendedLifetime(observer, {})
}
}
// @objc
// dynamic func test_ThatListObservers_CanReceiveUpdateNotifications() {
//
// self.prepareStack { (stack) in
//
// self.prepareTestDataForStack(stack)
//
// let observer = TestListObserver()
// let monitor = stack.monitorSectionedList(
// From<TestEntity1>(),
// SectionBy(#keyPath(TestEntity1.testBoolean)),
// OrderBy<TestEntity1>(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID)))
// )
// monitor.addObserver(observer)
//
// XCTAssertTrue(monitor.hasSections())
// XCTAssertEqual(monitor.numberOfSections(), 2)
// XCTAssertTrue(monitor.hasObjects())
// XCTAssertTrue(monitor.hasObjects(in: 0))
// XCTAssertEqual(monitor.numberOfObjects(in: 0), 2)
// XCTAssertEqual(monitor.numberOfObjects(in: 1), 3)
//
// var events = 0
//
// let willChangeExpectation = self.expectation(
// forNotification: NSNotification.Name(rawValue: "listMonitorWillChange:"),
// object: observer,
// handler: { (note) -> Bool in
//
// XCTAssertEqual(events, 0)
// XCTAssertEqual((note.userInfo as NSDictionary?) ?? [:], NSDictionary())
// defer {
//
// events += 1
// }
// return events == 0
// }
// )
//
// let didUpdateObjectExpectation = self.expectation(
// forNotification: NSNotification.Name(rawValue: "listMonitor:didUpdateObject:atIndexPath:"),
// object: observer,
// handler: { (note) -> Bool in
//
// XCTAssert(events == 1 || events == 2)
//
// let userInfo = note.userInfo
// XCTAssertNotNil(userInfo)
// XCTAssertEqual(
// Set(userInfo?.keys.map({ $0 as! String }) ?? []),
// ["indexPath", "object"]
// )
//
// let indexPath = userInfo?["indexPath"] as? NSIndexPath
// let object = userInfo?["object"] as? TestEntity1
//
// switch object?.testEntityID {
//
// case NSNumber(value: 101)?:
// XCTAssertEqual(indexPath?.index(atPosition: 0), 1)
// XCTAssertEqual(indexPath?.index(atPosition: 1), 0)
//
// XCTAssertEqual(object?.testBoolean, NSNumber(value: true))
// XCTAssertEqual(object?.testNumber, NSNumber(value: 11))
// XCTAssertEqual(object?.testDecimal, NSDecimalNumber(string: "11"))
// XCTAssertEqual(object?.testString, "nil:TestEntity1:11")
// XCTAssertEqual(object?.testData, ("nil:TestEntity1:11" as NSString).data(using: String.Encoding.utf8.rawValue)!)
// XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-11T00:00:00Z")!)
//
// case NSNumber(value: 102)?:
// XCTAssertEqual(indexPath?.index(atPosition: 0), 0)
// XCTAssertEqual(indexPath?.index(atPosition: 1), 0)
//
// XCTAssertEqual(object?.testBoolean, NSNumber(value: false))
// XCTAssertEqual(object?.testNumber, NSNumber(value: 22))
// XCTAssertEqual(object?.testDecimal, NSDecimalNumber(string: "22"))
// XCTAssertEqual(object?.testString, "nil:TestEntity1:22")
// XCTAssertEqual(object?.testData, ("nil:TestEntity1:22" as NSString).data(using: String.Encoding.utf8.rawValue)!)
// XCTAssertEqual(object?.testDate, self.dateFormatter.date(from: "2000-01-22T00:00:00Z")!)
//
// default:
// XCTFail()
// }
// defer {
//
// events += 1
// }
// return events == 1 || events == 2
// }
// )
// let didChangeExpectation = self.expectation(
// forNotification: NSNotification.Name(rawValue: "listMonitorDidChange:"),
// object: observer,
// handler: { (note) -> Bool in
//
// XCTAssertEqual(events, 3)
// XCTAssertEqual((note.userInfo as NSDictionary?) ?? [:], NSDictionary())
// defer {
//
// events += 1
// }
// return events == 3
// }
// )
// let saveExpectation = self.expectation(description: "save")
// stack.perform(
// asynchronous: { (transaction) -> Bool in
//
// if let object = try transaction.fetchOne(
// From<TestEntity1>(),
// Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) {
//
// object.testNumber = NSNumber(value: 11)
// object.testDecimal = NSDecimalNumber(string: "11")
// object.testString = "nil:TestEntity1:11"
// object.testData = ("nil:TestEntity1:11" as NSString).data(using: String.Encoding.utf8.rawValue)!
// object.testDate = self.dateFormatter.date(from: "2000-01-11T00:00:00Z")!
// }
// else {
//
// XCTFail()
// }
// if let object = try transaction.fetchOne(
// From<TestEntity1>(),
// Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 102)) {
//
// object.testNumber = NSNumber(value: 22)
// object.testDecimal = NSDecimalNumber(string: "22")
// object.testString = "nil:TestEntity1:22"
// object.testData = ("nil:TestEntity1:22" as NSString).data(using: String.Encoding.utf8.rawValue)!
// object.testDate = self.dateFormatter.date(from: "2000-01-22T00:00:00Z")!
// }
// else {
//
// XCTFail()
// }
// return transaction.hasChanges
// },
// success: { (hasChanges) in
//
// XCTAssertTrue(hasChanges)
// saveExpectation.fulfill()
// },
// failure: { _ in
//
// XCTFail()
// }
// )
// self.waitAndCheckExpectations()
// }
// }
//
// @objc
// dynamic func test_ThatListObservers_CanReceiveMoveNotifications() {
//
// self.prepareStack { (stack) in
//
// self.prepareTestDataForStack(stack)
//
// let observer = TestListObserver()
// let monitor = stack.monitorSectionedList(
// From<TestEntity1>(),
// SectionBy(#keyPath(TestEntity1.testBoolean)),
// OrderBy<TestEntity1>(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID)))
// )
// monitor.addObserver(observer)
//
// var events = 0
//
// let willChangeExpectation = self.expectation(
// forNotification: NSNotification.Name(rawValue: "listMonitorWillChange:"),
// object: observer,
// handler: { (note) -> Bool in
//
// XCTAssertEqual(events, 0)
// XCTAssertEqual((note.userInfo as NSDictionary?) ?? [:], NSDictionary())
// defer {
//
// events += 1
// }
// return events == 0
// }
// )
// let didMoveObjectExpectation = self.expectation(
// forNotification: NSNotification.Name(rawValue: "listMonitor:didMoveObject:fromIndexPath:toIndexPath:"),
// object: observer,
// handler: { (note) -> Bool in
//
// XCTAssertEqual(events, 1)
//
// let userInfo = note.userInfo
// XCTAssertNotNil(userInfo)
// XCTAssertEqual(
// Set(userInfo?.keys.map({ $0 as! String }) ?? []),
// ["fromIndexPath", "toIndexPath", "object"]
// )
//
// let fromIndexPath = userInfo?["fromIndexPath"] as? NSIndexPath
// XCTAssertEqual(fromIndexPath?.index(atPosition: 0), 0)
// XCTAssertEqual(fromIndexPath?.index(atPosition: 1), 0)
//
// let toIndexPath = userInfo?["toIndexPath"] as? NSIndexPath
// XCTAssertEqual(toIndexPath?.index(atPosition: 0), 1)
// XCTAssertEqual(toIndexPath?.index(atPosition: 1), 1)
//
// let object = userInfo?["object"] as? TestEntity1
// XCTAssertEqual(object?.testEntityID, NSNumber(value: 102))
// XCTAssertEqual(object?.testBoolean, NSNumber(value: true))
//
// defer {
//
// events += 1
// }
// return events == 1
// }
// )
// let didChangeExpectation = self.expectation(
// forNotification: NSNotification.Name(rawValue: "listMonitorDidChange:"),
// object: observer,
// handler: { (note) -> Bool in
//
// XCTAssertEqual(events, 2)
// XCTAssertEqual((note.userInfo as NSDictionary?) ?? [:], NSDictionary())
// defer {
//
// events += 1
// }
// return events == 2
// }
// )
// let saveExpectation = self.expectation(description: "save")
// stack.perform(
// asynchronous: { (transaction) -> Bool in
//
// if let object = try transaction.fetchOne(
// From<TestEntity1>(),
// Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 102)) {
//
// object.testBoolean = NSNumber(value: true)
// }
// else {
//
// XCTFail()
// }
// return transaction.hasChanges
// },
// success: { (hasChanges) in
//
// XCTAssertTrue(hasChanges)
// saveExpectation.fulfill()
// },
// failure: { _ in
//
// XCTFail()
// }
// )
// self.waitAndCheckExpectations()
// }
// }
//
// @objc
// dynamic func test_ThatListObservers_CanReceiveDeleteNotifications() {
//
// self.prepareStack { (stack) in
//
// self.prepareTestDataForStack(stack)
//
// let observer = TestListObserver()
// let monitor = stack.monitorSectionedList(
// From<TestEntity1>(),
// SectionBy(#keyPath(TestEntity1.testBoolean)),
// OrderBy<TestEntity1>(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID)))
// )
// monitor.addObserver(observer)
//
// var events = 0
//
// let willChangeExpectation = self.expectation(
// forNotification: NSNotification.Name(rawValue: "listMonitorWillChange:"),
// object: observer,
// handler: { (note) -> Bool in
//
// XCTAssertEqual(events, 0)
// XCTAssertEqual((note.userInfo as NSDictionary?) ?? [:], NSDictionary())
// defer {
//
// events += 1
// }
// return events == 0
// }
// )
// let didUpdateObjectExpectation = self.expectation(
// forNotification: NSNotification.Name(rawValue: "listMonitor:didDeleteObject:fromIndexPath:"),
// object: observer,
// handler: { (note) -> Bool in
//
// XCTAssert(events == 1 || events == 2)
//
// let userInfo = note.userInfo
// XCTAssertNotNil(userInfo)
// XCTAssertEqual(
// Set(userInfo?.keys.map({ $0 as! String }) ?? []),
// ["indexPath", "object"]
// )
//
// let indexPath = userInfo?["indexPath"] as? NSIndexPath
//
// XCTAssertEqual(indexPath?.section, 0)
// XCTAssert(indexPath?.index(atPosition: 1) == 0 || indexPath?.index(atPosition: 1) == 1)
//
// let object = userInfo?["object"] as? TestEntity1
// XCTAssertEqual(object?.isDeleted, true)
//
// defer {
//
// events += 1
// }
// return events == 1 || events == 2
// }
// )
// let didDeleteSectionExpectation = self.expectation(
// forNotification: NSNotification.Name(rawValue: "listMonitor:didDeleteSection:fromSectionIndex:"),
// object: observer,
// handler: { (note) -> Bool in
//
// XCTAssertEqual(events, 3)
//
// let userInfo = note.userInfo
// XCTAssertNotNil(userInfo)
// XCTAssertEqual(
// Set(userInfo?.keys.map({ $0 as! String }) ?? []),
// ["sectionInfo", "sectionIndex"]
// )
//
// let sectionInfo = userInfo?["sectionInfo"] as? NSFetchedResultsSectionInfo
// XCTAssertNotNil(sectionInfo)
// XCTAssertEqual(sectionInfo?.name, "0")
//
// let sectionIndex = userInfo?["sectionIndex"]
// XCTAssertEqual(sectionIndex as? NSNumber, NSNumber(value: 0))
//
// defer {
//
// events += 1
// }
// return events == 3
// }
// )
// let didChangeExpectation = self.expectation(
// forNotification: NSNotification.Name(rawValue: "listMonitorDidChange:"),
// object: observer,
// handler: { (note) -> Bool in
//
// XCTAssertEqual(events, 4)
// XCTAssertEqual((note.userInfo as NSDictionary?) ?? [:], NSDictionary())
// defer {
//
// events += 1
// }
// return events == 4
// }
// )
// let saveExpectation = self.expectation(description: "save")
// stack.perform(
// asynchronous: { (transaction) -> Bool in
//
// let count = try transaction.deleteAll(
// From<TestEntity1>(),
// Where<TestEntity1>(#keyPath(TestEntity1.testBoolean), isEqualTo: false)
// )
// XCTAssertEqual(count, 2)
// return transaction.hasChanges
// },
// success: { (hasChanges) in
//
// XCTAssertTrue(hasChanges)
// saveExpectation.fulfill()
// },
// failure: { _ in
//
// XCTFail()
// }
// )
// self.waitAndCheckExpectations()
// }
// }
//}
//
//
//// MARK: TestListObserver
//
//@available(macOS 10.12, *)
//class TestListObserver: ListSectionObserver {
//
// // MARK: ListObserver
//
// typealias ListEntityType = TestEntity1
//
// func listMonitorWillChange(_ monitor: ListMonitor<TestEntity1>) {
//
// NotificationCenter.default.post(
// name: Notification.Name(rawValue: "listMonitorWillChange:"),
// object: self,
// userInfo: [:]
// )
// }
//
// func listMonitorDidChange(_ monitor: ListMonitor<TestEntity1>) {
//
// NotificationCenter.default.post(
// name: Notification.Name(rawValue: "listMonitorDidChange:"),
// object: self,
// userInfo: [:]
// )
// }
//
// func listMonitorWillRefetch(_ monitor: ListMonitor<TestEntity1>) {
//
// NotificationCenter.default.post(
// name: Notification.Name(rawValue: "listMonitorWillRefetch:"),
// object: self,
// userInfo: [:]
// )
// }
//
// func listMonitorDidRefetch(_ monitor: ListMonitor<TestEntity1>) {
//
// NotificationCenter.default.post(
// name: Notification.Name(rawValue: "listMonitorDidRefetch:"),
// object: self,
// userInfo: [:]
// )
// }
//
//
// // MARK: ListObjectObserver
//
// func listMonitor(_ monitor: ListMonitor<TestEntity1>, didInsertObject object: TestEntity1, toIndexPath indexPath: IndexPath) {
//
// NotificationCenter.default.post(
// name: Notification.Name(rawValue: "listMonitor:didInsertObject:toIndexPath:"),
// object: self,
// userInfo: [
// "object": object,
// "indexPath": indexPath
// ]
// )
// }
//
// func listMonitor(_ monitor: ListMonitor<TestEntity1>, didDeleteObject object: TestEntity1, fromIndexPath indexPath: IndexPath) {
//
// NotificationCenter.default.post(
// name: Notification.Name(rawValue: "listMonitor:didDeleteObject:fromIndexPath:"),
// object: self,
// userInfo: [
// "object": object,
// "indexPath": indexPath
// ]
// )
// }
//
// func listMonitor(_ monitor: ListMonitor<TestEntity1>, didUpdateObject object: TestEntity1, atIndexPath indexPath: IndexPath) {
//
// NotificationCenter.default.post(
// name: Notification.Name(rawValue: "listMonitor:didUpdateObject:atIndexPath:"),
// object: self,
// userInfo: [
// "object": object,
// "indexPath": indexPath
// ]
// )
// }
//
//
// func listMonitor(_ monitor: ListMonitor<TestEntity1>, didMoveObject object: TestEntity1, fromIndexPath: IndexPath, toIndexPath: IndexPath) {
//
// NotificationCenter.default.post(
// name: Notification.Name(rawValue: "listMonitor:didMoveObject:fromIndexPath:toIndexPath:"),
// object: self,
// userInfo: [
// "object": object,
// "fromIndexPath": fromIndexPath,
// "toIndexPath": toIndexPath
// ]
// )
// }
//
//
// // MARK: ListSectionObserver
//
// func listMonitor(_ monitor: ListMonitor<TestEntity1>, didInsertSection sectionInfo: NSFetchedResultsSectionInfo, toSectionIndex sectionIndex: Int) {
//
// NotificationCenter.default.post(
// name: Notification.Name(rawValue: "listMonitor:didInsertSection:toSectionIndex:"),
// object: self,
// userInfo: [
// "sectionInfo": sectionInfo,
// "sectionIndex": sectionIndex
// ]
// )
// }
//
// func listMonitor(_ monitor: ListMonitor<TestEntity1>, didDeleteSection sectionInfo: NSFetchedResultsSectionInfo, fromSectionIndex sectionIndex: Int) {
//
// NotificationCenter.default.post(
// name: Notification.Name(rawValue: "listMonitor:didDeleteSection:fromSectionIndex:"),
// object: self,
// userInfo: [
// "sectionInfo": sectionInfo,
// "sectionIndex": sectionIndex
// ]
// )
// }
@objc
dynamic func test_ThatListPublishers_CanReceiveUpdateNotifications() {
self.prepareStack { (stack) in
self.prepareTestDataForStack(stack)
let observer = NSObject()
let listPublisher = stack.publishList(
From<TestEntity1>(),
SectionBy(#keyPath(TestEntity1.testBoolean)),
OrderBy<TestEntity1>(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID)))
)
XCTAssertTrue(listPublisher.snapshot.hasSections())
XCTAssertEqual(listPublisher.snapshot.numberOfSections, 2)
XCTAssertTrue(listPublisher.snapshot.hasItems())
XCTAssertTrue(listPublisher.snapshot.hasItems(inSectionIndex: 0))
XCTAssertEqual(listPublisher.snapshot.numberOfItems(inSectionIndex: 0), 2)
XCTAssertEqual(listPublisher.snapshot.numberOfItems(inSectionIndex: 1), 3)
let didChangeExpectation = self.expectation(description: "didChange")
listPublisher.addObserver(observer) { listPublisher in
XCTAssertTrue(listPublisher.snapshot.hasSections())
XCTAssertEqual(listPublisher.snapshot.numberOfSections, 2)
XCTAssertTrue(listPublisher.snapshot.hasItems())
XCTAssertTrue(listPublisher.snapshot.hasItems(inSectionIndex: 0))
XCTAssertEqual(listPublisher.snapshot.numberOfItems(inSectionIndex: 0), 2)
XCTAssertEqual(listPublisher.snapshot.numberOfItems(inSectionIndex: 1), 3)
didChangeExpectation.fulfill()
}
let saveExpectation = self.expectation(description: "save")
stack.perform(
asynchronous: { (transaction) -> Bool in
if let object = try transaction.fetchOne(
From<TestEntity1>(),
Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) {
object.testNumber = NSNumber(value: 11)
object.testDecimal = NSDecimalNumber(string: "11")
object.testString = "nil:TestEntity1:11"
object.testData = ("nil:TestEntity1:11" as NSString).data(using: String.Encoding.utf8.rawValue)!
object.testDate = self.dateFormatter.date(from: "2000-01-11T00:00:00Z")!
}
else {
XCTFail()
}
if let object = try transaction.fetchOne(
From<TestEntity1>(),
Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 102)) {
object.testNumber = NSNumber(value: 22)
object.testDecimal = NSDecimalNumber(string: "22")
object.testString = "nil:TestEntity1:22"
object.testData = ("nil:TestEntity1:22" as NSString).data(using: String.Encoding.utf8.rawValue)!
object.testDate = self.dateFormatter.date(from: "2000-01-22T00:00:00Z")!
}
else {
XCTFail()
}
return transaction.hasChanges
},
success: { (hasChanges) in
XCTAssertTrue(hasChanges)
saveExpectation.fulfill()
},
failure: { _ in
XCTFail()
}
)
self.waitAndCheckExpectations()
withExtendedLifetime(listPublisher, {})
withExtendedLifetime(observer, {})
}
}
@objc
dynamic func test_ThatListPublishers_CanReceiveMoveNotifications() {
self.prepareStack { (stack) in
self.prepareTestDataForStack(stack)
let observer = NSObject()
let listPublisher = stack.publishList(
From<TestEntity1>(),
SectionBy(#keyPath(TestEntity1.testBoolean)),
OrderBy<TestEntity1>(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID)))
)
XCTAssertTrue(listPublisher.snapshot.hasSections())
XCTAssertEqual(listPublisher.snapshot.numberOfSections, 2)
XCTAssertTrue(listPublisher.snapshot.hasItems())
XCTAssertTrue(listPublisher.snapshot.hasItems(inSectionIndex: 0))
XCTAssertEqual(listPublisher.snapshot.numberOfItems(inSectionIndex: 0), 2)
XCTAssertEqual(listPublisher.snapshot.numberOfItems(inSectionIndex: 1), 3)
let didChangeExpectation = self.expectation(description: "didChange")
listPublisher.addObserver(observer) { listPublisher in
XCTAssertTrue(listPublisher.snapshot.hasSections())
XCTAssertEqual(listPublisher.snapshot.numberOfSections, 2)
XCTAssertTrue(listPublisher.snapshot.hasItems())
XCTAssertTrue(listPublisher.snapshot.hasItems(inSectionIndex: 0))
XCTAssertEqual(listPublisher.snapshot.numberOfItems(inSectionIndex: 0), 1)
XCTAssertEqual(listPublisher.snapshot.numberOfItems(inSectionIndex: 1), 4)
didChangeExpectation.fulfill()
}
let saveExpectation = self.expectation(description: "save")
stack.perform(
asynchronous: { (transaction) -> Bool in
if let object = try transaction.fetchOne(
From<TestEntity1>(),
Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 102)) {
object.testBoolean = NSNumber(value: true)
}
else {
XCTFail()
}
return transaction.hasChanges
},
success: { (hasChanges) in
XCTAssertTrue(hasChanges)
saveExpectation.fulfill()
},
failure: { _ in
XCTFail()
}
)
self.waitAndCheckExpectations()
withExtendedLifetime(listPublisher, {})
withExtendedLifetime(observer, {})
}
}
@objc
dynamic func test_ThatListPublishers_CanReceiveDeleteNotifications() {
self.prepareStack { (stack) in
self.prepareTestDataForStack(stack)
let observer = NSObject()
let listPublisher = stack.publishList(
From<TestEntity1>(),
SectionBy(#keyPath(TestEntity1.testBoolean)),
OrderBy<TestEntity1>(.ascending(#keyPath(TestEntity1.testBoolean)), .ascending(#keyPath(TestEntity1.testEntityID)))
)
XCTAssertTrue(listPublisher.snapshot.hasSections())
XCTAssertEqual(listPublisher.snapshot.numberOfSections, 2)
XCTAssertTrue(listPublisher.snapshot.hasItems())
XCTAssertTrue(listPublisher.snapshot.hasItems(inSectionIndex: 0))
XCTAssertEqual(listPublisher.snapshot.numberOfItems(inSectionIndex: 0), 2)
XCTAssertEqual(listPublisher.snapshot.numberOfItems(inSectionIndex: 1), 3)
let didChangeExpectation = self.expectation(description: "didChange")
listPublisher.addObserver(observer) { listPublisher in
XCTAssertTrue(listPublisher.snapshot.hasSections())
XCTAssertEqual(listPublisher.snapshot.numberOfSections, 1)
XCTAssertTrue(listPublisher.snapshot.hasItems())
XCTAssertTrue(listPublisher.snapshot.hasItems(inSectionIndex: 0))
XCTAssertEqual(listPublisher.snapshot.numberOfItems(inSectionIndex: 0), 3)
didChangeExpectation.fulfill()
}
let saveExpectation = self.expectation(description: "save")
stack.perform(
asynchronous: { (transaction) -> Bool in
let count = try transaction.deleteAll(
From<TestEntity1>(),
Where<TestEntity1>(#keyPath(TestEntity1.testBoolean), isEqualTo: false)
)
XCTAssertEqual(count, 2)
return transaction.hasChanges
},
success: { (hasChanges) in
XCTAssertTrue(hasChanges)
saveExpectation.fulfill()
},
failure: { _ in
XCTFail()
}
)
self.waitAndCheckExpectations()
}
}
}
#endif

View File

@@ -0,0 +1,154 @@
//
// ObjectPublisherTests.swift
// CoreStore
//
// Copyright © 2018 John Rommel Estropia
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
import XCTest
@testable
import CoreStore
// MARK: - ObjectPublisherTests
@available(macOS 10.12, *)
class ObjectPublisherTests: BaseTestDataTestCase {
@objc
dynamic func test_ThatObjectPublishers_CanReceiveUpdateNotifications() {
self.prepareStack { (stack) in
self.prepareTestDataForStack(stack)
guard let object = try stack.fetchOne(
From<TestEntity1>(),
Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) else {
XCTFail()
return
}
let observer = NSObject()
let objectPublisher = stack.publishObject(object)
XCTAssertEqual(objectPublisher.object, object)
XCTAssertNotNil(objectPublisher.snapshot)
let didChangeExpectation = self.expectation(description: "didChange")
objectPublisher.addObserver(observer) { objectPublisher in
XCTAssertEqual(objectPublisher.object?.testNumber, NSNumber(value: 10))
XCTAssertEqual(objectPublisher.object?.testString, "nil:TestEntity1:10")
didChangeExpectation.fulfill()
}
let saveExpectation = self.expectation(description: "save")
stack.perform(
asynchronous: { (transaction) -> Bool in
guard let object = transaction.edit(object) else {
XCTFail()
try transaction.cancel()
}
object.testNumber = NSNumber(value: 10)
object.testString = "nil:TestEntity1:10"
return transaction.hasChanges
},
success: { (hasChanges) in
XCTAssertTrue(hasChanges)
saveExpectation.fulfill()
},
failure: { _ in
XCTFail()
}
)
self.waitAndCheckExpectations()
withExtendedLifetime(objectPublisher, {})
withExtendedLifetime(observer, {})
}
}
@objc
dynamic func test_ThatObjectPublishers_CanReceiveDeleteNotifications() {
self.prepareStack { (stack) in
self.prepareTestDataForStack(stack)
guard let object = try stack.fetchOne(
From<TestEntity1>(),
Where<TestEntity1>(#keyPath(TestEntity1.testEntityID), isEqualTo: 101)) else {
XCTFail()
return
}
let observer = NSObject()
let objectPublisher = stack.publishObject(object)
XCTAssertEqual(objectPublisher.object, object)
XCTAssertNotNil(objectPublisher.snapshot)
let didChangeExpectation = self.expectation(description: "didChange")
objectPublisher.addObserver(observer) { objectPublisher in
XCTAssertNil(objectPublisher.object)
XCTAssertNil(objectPublisher.snapshot)
didChangeExpectation.fulfill()
}
let saveExpectation = self.expectation(description: "save")
stack.perform(
asynchronous: { (transaction) -> Bool in
guard let object = transaction.edit(object) else {
XCTFail()
try transaction.cancel()
}
transaction.delete(object)
return transaction.hasChanges
},
success: { (hasChanges) in
XCTAssertTrue(hasChanges)
saveExpectation.fulfill()
},
failure: { _ in
XCTFail()
}
)
self.waitAndCheckExpectations()
withExtendedLifetime(objectPublisher, {})
withExtendedLifetime(observer, {})
}
}
}

View File

@@ -1552,10 +1552,10 @@ Including `ListObserver`, there are 3 observer protocols you can implement depen
- `ListObjectObserver`: in addition to `ListObserver` methods, also lets you handle object inserts, updates, and deletes:
```swift
func listMonitor(_ monitor: ListMonitor<MyPersonEntity>, didInsertObject object: MyPersonEntity, toIndexPath indexPath: NSIndexPath)
func listMonitor(_ monitor: ListMonitor<MyPersonEntity>, didDeleteObject object: MyPersonEntity, fromIndexPath indexPath: NSIndexPath)
func listMonitor(_ monitor: ListMonitor<MyPersonEntity>, didUpdateObject object: MyPersonEntity, atIndexPath indexPath: NSIndexPath)
func listMonitor(_ monitor: ListMonitor<MyPersonEntity>, didMoveObject object: MyPersonEntity, fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath)
func listMonitor(_ monitor: ListMonitor<MyPersonEntity>, didInsertObject object: MyPersonEntity, toIndexPath indexPath: IndexPath)
func listMonitor(_ monitor: ListMonitor<MyPersonEntity>, didDeleteObject object: MyPersonEntity, fromIndexPath indexPath: IndexPath)
func listMonitor(_ monitor: ListMonitor<MyPersonEntity>, didUpdateObject object: MyPersonEntity, atIndexPath indexPath: IndexPath)
func listMonitor(_ monitor: ListMonitor<MyPersonEntity>, didMoveObject object: MyPersonEntity, fromIndexPath: IndexPath, toIndexPath: IndexPath)
```
- `ListSectionObserver`: in addition to `ListObjectObserver` methods, also lets you handle section inserts and deletes:
```swift
@@ -1612,9 +1612,9 @@ func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -
}
```
To access the objects of a sectioned list, use an `NSIndexPath` or a tuple:
To access the objects of a sectioned list, use an `IndexPath` or a tuple:
```swift
let indexPath = NSIndexPath(forRow: 2, inSection: 1)
let indexPath = IndexPath(row: 2, section: 1)
let person1 = self.monitor[indexPath]
let person2 = self.monitor[1, 2]
// person1 and person2 are the same object

View File

@@ -1160,7 +1160,7 @@ extension NSEntityDescription: CoreStoreDebugStringConvertible {
info.append(("compoundIndexes", self.compoundIndexes))
}
if #available(macOS 10.11, *) {
if #available(macOS 10.11, iOS 9.0, *) {
info.append(("uniquenessConstraints", self.uniquenessConstraints))
}

View File

@@ -452,7 +452,7 @@ public final class CoreStoreSchema: DynamicSchema {
}
for (entity, entityDescription) in entityDescriptionsByEntity {
if #available(macOS 10.11, *) {
if #available(macOS 10.11, iOS 9.0, *) {
let uniqueConstraints = entity.uniqueConstraints.filter({ !$0.isEmpty })
if !uniqueConstraints.isEmpty {

View File

@@ -39,7 +39,7 @@ extension DataStack {
- parameter object: the `DynamicObject` to observe changes from
- returns: an `ObjectPublisher` that broadcasts changes to `object`
*/
public func objectPublisher<O: DynamicObject>(_ object: O) -> ObjectPublisher<O> {
public func publishObject<O: DynamicObject>(_ object: O) -> ObjectPublisher<O> {
return ObjectPublisher<O>(objectID: object.cs_id(), context: self.unsafeContext())
}
@@ -51,9 +51,9 @@ extension DataStack {
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: a `ListPublisher` that broadcasts changes to the fetched results
*/
public func listPublisher<O>(_ from: From<O>, _ fetchClauses: FetchClause...) -> ListPublisher<O> {
public func publishList<O>(_ from: From<O>, _ fetchClauses: FetchClause...) -> ListPublisher<O> {
return self.listPublisher(from, fetchClauses)
return self.publishList(from, fetchClauses)
}
/**
@@ -63,7 +63,7 @@ extension DataStack {
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: a `ListPublisher` that broadcasts changes to the fetched results
*/
public func listPublisher<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) -> ListPublisher<O> {
public func publishList<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) -> ListPublisher<O> {
return ListPublisher(
dataStack: self,
@@ -99,9 +99,9 @@ extension DataStack {
- parameter clauseChain: a `FetchChainableBuilderType` built from a chain of clauses
- returns: a `ListPublisher` that broadcasts changes to the fetched results
*/
public func listPublisher<B: FetchChainableBuilderType>(_ clauseChain: B) -> ListPublisher<B.ObjectType> {
public func publishList<B: FetchChainableBuilderType>(_ clauseChain: B) -> ListPublisher<B.ObjectType> {
return self.listPublisher(
return self.publishList(
clauseChain.from,
clauseChain.fetchClauses
)
@@ -115,9 +115,9 @@ extension DataStack {
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: a `ListPublisher` that broadcasts changes to the fetched results
*/
public func listPublisher<O>(_ from: From<O>, _ sectionBy: SectionBy<O>, _ fetchClauses: FetchClause...) -> ListPublisher<O> {
public func publishList<O>(_ from: From<O>, _ sectionBy: SectionBy<O>, _ fetchClauses: FetchClause...) -> ListPublisher<O> {
return self.listPublisher(
return self.publishList(
from,
sectionBy,
fetchClauses
@@ -132,7 +132,7 @@ extension DataStack {
- parameter fetchClauses: a series of `FetchClause` instances for fetching the object list. Accepts `Where`, `OrderBy`, and `Tweak` clauses.
- returns: a `ListPublisher` that broadcasts changes to the fetched results
*/
public func listPublisher<O>(_ from: From<O>, _ sectionBy: SectionBy<O>, _ fetchClauses: [FetchClause]) -> ListPublisher<O> {
public func publishList<O>(_ from: From<O>, _ sectionBy: SectionBy<O>, _ fetchClauses: [FetchClause]) -> ListPublisher<O> {
return ListPublisher(
dataStack: self,
@@ -169,14 +169,59 @@ extension DataStack {
- parameter clauseChain: a `SectionMonitorBuilderType` built from a chain of clauses
- returns: a `ListPublisher` that broadcasts changes to the fetched results
*/
public func listPublisher<B: SectionMonitorBuilderType>(_ clauseChain: B) -> ListPublisher<B.ObjectType> {
public func publishList<B: SectionMonitorBuilderType>(_ clauseChain: B) -> ListPublisher<B.ObjectType> {
return self.listPublisher(
return self.publishList(
clauseChain.from,
clauseChain.sectionBy,
clauseChain.fetchClauses
)
}
// MARK: - Deprecated
@available(*, deprecated, renamed: "publishObject(_:)")
public func objectPublisher<O: DynamicObject>(_ object: O) -> ObjectPublisher<O> {
return self.publishObject(object)
}
@available(*, deprecated, renamed: "publishList(_:_:)")
public func listPublisher<O>(_ from: From<O>, _ fetchClauses: FetchClause...) -> ListPublisher<O> {
return self.publishList(from, fetchClauses)
}
@available(*, deprecated, renamed: "publishList(_:_:)")
public func listPublisher<O>(_ from: From<O>, _ fetchClauses: [FetchClause]) -> ListPublisher<O> {
return self.publishList(from, fetchClauses)
}
@available(*, deprecated, renamed: "publishList(_:)")
public func listPublisher<B: FetchChainableBuilderType>(_ clauseChain: B) -> ListPublisher<B.ObjectType> {
return self.publishList(clauseChain)
}
@available(*, deprecated, renamed: "publishList(_:_:_:)")
public func listPublisher<O>(_ from: From<O>, _ sectionBy: SectionBy<O>, _ fetchClauses: FetchClause...) -> ListPublisher<O> {
return self.publishList(from, sectionBy, fetchClauses)
}
@available(*, deprecated, renamed: "publishList(_:_:_:)")
public func listPublisher<O>(_ from: From<O>, _ sectionBy: SectionBy<O>, _ fetchClauses: [FetchClause]) -> ListPublisher<O> {
return self.publishList(from, sectionBy, fetchClauses)
}
@available(*, deprecated, renamed: "publishList(_:)")
public func listPublisher<B: SectionMonitorBuilderType>(_ clauseChain: B) -> ListPublisher<B.ObjectType> {
return self.publishList(clauseChain)
}
}
#endif

View File

@@ -614,7 +614,7 @@ extension DataStack {
}
let fileManager = FileManager.default
let systemTemporaryDirectoryURL: URL
if #available(macOS 10.12, *) {
if #available(macOS 10.12, iOS 10.0, *) {
systemTemporaryDirectoryURL = fileManager.temporaryDirectory
}

View File

@@ -120,17 +120,27 @@ extension NSManagedObjectContext {
return (updated: [], deleted: [])
}
if userInfo[NSInvalidatedAllObjectsKey] != nil {
let context = notification.object as! NSManagedObjectContext
return (updated: Set(context.registeredObjects.map({ $0.objectID })), deleted: [])
}
var updatedObjectIDs: Set<NSManagedObjectID> = []
if let updatedObjects = userInfo[NSUpdatedObjectsKey] as? Set<NSManagedObjectID> {
if let updatedObjects = userInfo[NSUpdatedObjectsKey] as? Set<NSManagedObject> {
updatedObjectIDs.formUnion(updatedObjects)
updatedObjectIDs.formUnion(updatedObjects.map({ $0.objectID }))
}
if let mergedObjects = userInfo[NSRefreshedObjectsKey] as? Set<NSManagedObjectID> {
if let mergedObjects = userInfo[NSRefreshedObjectsKey] as? Set<NSManagedObject> {
updatedObjectIDs.formUnion(mergedObjects)
updatedObjectIDs.formUnion(mergedObjects.map({ $0.objectID }))
}
let deletedObjectIDs: Set<NSManagedObjectID> = (userInfo[NSDeletedObjectsKey] as? Set<NSManagedObjectID>) ?? []
return (updated: updatedObjectIDs, deleted: deletedObjectIDs)
if let mergedObjects = userInfo[NSInvalidatedObjectsKey] as? Set<NSManagedObject> {
updatedObjectIDs.formUnion(mergedObjects.map({ $0.objectID }))
}
let deletedObjectIDs: Set<NSManagedObject> = (userInfo[NSDeletedObjectsKey] as? Set<NSManagedObject>) ?? []
return (updated: updatedObjectIDs, deleted: Set(deletedObjectIDs.map({ $0.objectID })))
}
)
}

View File

@@ -354,7 +354,7 @@ extension ObjectPublisher where O: CoreStoreObject {
/**
Returns the value for the property identified by a given key.
*/
public subscript<V>(dynamicMember member: KeyPath<O, ValueContainer<O>.Required<V>>) -> V? {
public subscript<OBase, V>(dynamicMember member: KeyPath<O, ValueContainer<OBase>.Required<V>>) -> V? {
return self.object?[keyPath: member].value
}
@@ -362,7 +362,7 @@ extension ObjectPublisher where O: CoreStoreObject {
/**
Returns the value for the property identified by a given key.
*/
public subscript<V>(dynamicMember member: KeyPath<O, ValueContainer<O>.Optional<V>>) -> V? {
public subscript<OBase, V>(dynamicMember member: KeyPath<O, ValueContainer<OBase>.Optional<V>>) -> V? {
return self.object?[keyPath: member].value
}
@@ -370,7 +370,7 @@ extension ObjectPublisher where O: CoreStoreObject {
/**
Returns the value for the property identified by a given key.
*/
public subscript<V>(dynamicMember member: KeyPath<O, TransformableContainer<O>.Required<V>>) -> V? {
public subscript<OBase, V>(dynamicMember member: KeyPath<O, TransformableContainer<OBase>.Required<V>>) -> V? {
return self.object?[keyPath: member].value
}
@@ -378,7 +378,7 @@ extension ObjectPublisher where O: CoreStoreObject {
/**
Returns the value for the property identified by a given key.
*/
public subscript<V>(dynamicMember member: KeyPath<O, TransformableContainer<O>.Optional<V>>) -> V? {
public subscript<OBase, V>(dynamicMember member: KeyPath<O, TransformableContainer<OBase>.Optional<V>>) -> V? {
return self.object?[keyPath: member].value
}
@@ -386,7 +386,7 @@ extension ObjectPublisher where O: CoreStoreObject {
/**
Returns the value for the property identified by a given key.
*/
public subscript<D>(dynamicMember member: KeyPath<O, RelationshipContainer<O>.ToOne<D>>) -> D? {
public subscript<OBase, D>(dynamicMember member: KeyPath<O, RelationshipContainer<OBase>.ToOne<D>>) -> D? {
return self.object?[keyPath: member].value
}
@@ -394,7 +394,7 @@ extension ObjectPublisher where O: CoreStoreObject {
/**
Returns the value for the property identified by a given key.
*/
public subscript<D>(dynamicMember member: KeyPath<O, RelationshipContainer<O>.ToManyOrdered<D>>) -> [D]? {
public subscript<OBase, D>(dynamicMember member: KeyPath<O, RelationshipContainer<OBase>.ToManyOrdered<D>>) -> [D]? {
return self.object?[keyPath: member].value
}
@@ -402,7 +402,7 @@ extension ObjectPublisher where O: CoreStoreObject {
/**
Returns the value for the property identified by a given key.
*/
public subscript<D>(dynamicMember member: KeyPath<O, RelationshipContainer<O>.ToManyUnordered<D>>) -> Set<D>? {
public subscript<OBase, D>(dynamicMember member: KeyPath<O, RelationshipContainer<OBase>.ToManyUnordered<D>>) -> Set<D>? {
return self.object?[keyPath: member].value
}

View File

@@ -146,7 +146,7 @@ extension ObjectSnapshot where O: CoreStoreObject {
/**
Returns the value for the property identified by a given key.
*/
public subscript<V>(dynamicMember member: KeyPath<O, ValueContainer<O>.Required<V>>) -> V {
public subscript<OBase, V>(dynamicMember member: KeyPath<O, ValueContainer<OBase>.Required<V>>) -> V {
get {
@@ -163,7 +163,7 @@ extension ObjectSnapshot where O: CoreStoreObject {
/**
Returns the value for the property identified by a given key.
*/
public subscript<V>(dynamicMember member: KeyPath<O, ValueContainer<O>.Optional<V>>) -> V? {
public subscript<OBase, V>(dynamicMember member: KeyPath<O, ValueContainer<OBase>.Optional<V>>) -> V? {
get {
@@ -180,7 +180,7 @@ extension ObjectSnapshot where O: CoreStoreObject {
/**
Returns the value for the property identified by a given key.
*/
public subscript<V>(dynamicMember member: KeyPath<O, TransformableContainer<O>.Required<V>>) -> V {
public subscript<OBase, V>(dynamicMember member: KeyPath<O, TransformableContainer<OBase>.Required<V>>) -> V {
get {
@@ -197,7 +197,7 @@ extension ObjectSnapshot where O: CoreStoreObject {
/**
Returns the value for the property identified by a given key.
*/
public subscript<V>(dynamicMember member: KeyPath<O, TransformableContainer<O>.Optional<V>>) -> V? {
public subscript<OBase, V>(dynamicMember member: KeyPath<O, TransformableContainer<OBase>.Optional<V>>) -> V? {
get {
@@ -214,7 +214,7 @@ extension ObjectSnapshot where O: CoreStoreObject {
/**
Returns the value for the property identified by a given key.
*/
public subscript<D>(dynamicMember member: KeyPath<O, RelationshipContainer<O>.ToOne<D>>) -> D.ObjectID? {
public subscript<OBase, D>(dynamicMember member: KeyPath<O, RelationshipContainer<OBase>.ToOne<D>>) -> D.ObjectID? {
get {
@@ -231,7 +231,7 @@ extension ObjectSnapshot where O: CoreStoreObject {
/**
Returns the value for the property identified by a given key.
*/
public subscript<D>(dynamicMember member: KeyPath<O, RelationshipContainer<O>.ToManyOrdered<D>>) -> [D.ObjectID] {
public subscript<OBase, D>(dynamicMember member: KeyPath<O, RelationshipContainer<OBase>.ToManyOrdered<D>>) -> [D.ObjectID] {
get {
@@ -248,7 +248,7 @@ extension ObjectSnapshot where O: CoreStoreObject {
/**
Returns the value for the property identified by a given key.
*/
public subscript<D>(dynamicMember member: KeyPath<O, RelationshipContainer<O>.ToManyUnordered<D>>) -> Set<D.ObjectID> {
public subscript<OBase, D>(dynamicMember member: KeyPath<O, RelationshipContainer<OBase>.ToManyUnordered<D>>) -> Set<D.ObjectID> {
get {