mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-03-30 22:31:59 +02:00
Merge branch 'master' into minIOS11
# Conflicts: # Sources/ListSnapshot.swift
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
Pod::Spec.new do |s|
|
Pod::Spec.new do |s|
|
||||||
s.name = "CoreStore"
|
s.name = "CoreStore"
|
||||||
s.version = "7.3.0"
|
s.version = "7.3.1"
|
||||||
s.swift_version = "5.3"
|
s.swift_version = "5.3"
|
||||||
s.license = "MIT"
|
s.license = "MIT"
|
||||||
s.homepage = "https://github.com/JohnEstropia/CoreStore"
|
s.homepage = "https://github.com/JohnEstropia/CoreStore"
|
||||||
|
|||||||
@@ -3415,7 +3415,7 @@
|
|||||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||||
MARKETING_VERSION = 7.3.0;
|
MARKETING_VERSION = 7.3.1;
|
||||||
OTHER_LDFLAGS = (
|
OTHER_LDFLAGS = (
|
||||||
"-weak_framework",
|
"-weak_framework",
|
||||||
Combine,
|
Combine,
|
||||||
@@ -3438,7 +3438,7 @@
|
|||||||
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
DYLIB_INSTALL_NAME_BASE = "@rpath";
|
||||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||||
MARKETING_VERSION = 7.3.0;
|
MARKETING_VERSION = 7.3.1;
|
||||||
OTHER_LDFLAGS = (
|
OTHER_LDFLAGS = (
|
||||||
"-weak_framework",
|
"-weak_framework",
|
||||||
Combine,
|
Combine,
|
||||||
@@ -3498,7 +3498,7 @@
|
|||||||
GCC_NO_COMMON_BLOCKS = YES;
|
GCC_NO_COMMON_BLOCKS = YES;
|
||||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||||
MARKETING_VERSION = 7.3.0;
|
MARKETING_VERSION = 7.3.1;
|
||||||
OTHER_LDFLAGS = (
|
OTHER_LDFLAGS = (
|
||||||
"-weak_framework",
|
"-weak_framework",
|
||||||
Combine,
|
Combine,
|
||||||
@@ -3524,7 +3524,7 @@
|
|||||||
GCC_NO_COMMON_BLOCKS = YES;
|
GCC_NO_COMMON_BLOCKS = YES;
|
||||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||||
MARKETING_VERSION = 7.3.0;
|
MARKETING_VERSION = 7.3.1;
|
||||||
OTHER_LDFLAGS = (
|
OTHER_LDFLAGS = (
|
||||||
"-weak_framework",
|
"-weak_framework",
|
||||||
Combine,
|
Combine,
|
||||||
@@ -3589,7 +3589,7 @@
|
|||||||
GCC_NO_COMMON_BLOCKS = YES;
|
GCC_NO_COMMON_BLOCKS = YES;
|
||||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
|
||||||
MARKETING_VERSION = 7.3.0;
|
MARKETING_VERSION = 7.3.1;
|
||||||
OTHER_LDFLAGS = (
|
OTHER_LDFLAGS = (
|
||||||
"-weak_framework",
|
"-weak_framework",
|
||||||
Combine,
|
Combine,
|
||||||
@@ -3618,7 +3618,7 @@
|
|||||||
GCC_NO_COMMON_BLOCKS = YES;
|
GCC_NO_COMMON_BLOCKS = YES;
|
||||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
|
||||||
MARKETING_VERSION = 7.3.0;
|
MARKETING_VERSION = 7.3.1;
|
||||||
OTHER_LDFLAGS = (
|
OTHER_LDFLAGS = (
|
||||||
"-weak_framework",
|
"-weak_framework",
|
||||||
Combine,
|
Combine,
|
||||||
@@ -3684,7 +3684,7 @@
|
|||||||
GCC_NO_COMMON_BLOCKS = YES;
|
GCC_NO_COMMON_BLOCKS = YES;
|
||||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||||
MARKETING_VERSION = 7.3.0;
|
MARKETING_VERSION = 7.3.1;
|
||||||
OTHER_LDFLAGS = (
|
OTHER_LDFLAGS = (
|
||||||
"-weak_framework",
|
"-weak_framework",
|
||||||
Combine,
|
Combine,
|
||||||
@@ -3712,7 +3712,7 @@
|
|||||||
GCC_NO_COMMON_BLOCKS = YES;
|
GCC_NO_COMMON_BLOCKS = YES;
|
||||||
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
|
||||||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||||
MARKETING_VERSION = 7.3.0;
|
MARKETING_VERSION = 7.3.1;
|
||||||
OTHER_LDFLAGS = (
|
OTHER_LDFLAGS = (
|
||||||
"-weak_framework",
|
"-weak_framework",
|
||||||
Combine,
|
Combine,
|
||||||
|
|||||||
2
CoreStore.xcworkspace/contents.xcworkspacedata
generated
2
CoreStore.xcworkspace/contents.xcworkspacedata
generated
@@ -8,6 +8,6 @@
|
|||||||
location = "group:CoreStore.xcodeproj">
|
location = "group:CoreStore.xcodeproj">
|
||||||
</FileRef>
|
</FileRef>
|
||||||
<FileRef
|
<FileRef
|
||||||
location = "group:/Users/JohnEstropia/Documents/XCodeProjects/CoreStore/LegacyDemo/LegacyDemo.xcodeproj">
|
location = "group:LegacyDemo/LegacyDemo.xcodeproj">
|
||||||
</FileRef>
|
</FileRef>
|
||||||
</Workspace>
|
</Workspace>
|
||||||
|
|||||||
@@ -2095,7 +2095,7 @@ This installs CoreStore as a framework. Declare `import CoreStore` in your swift
|
|||||||
#### Install with Swift Package Manager:
|
#### Install with Swift Package Manager:
|
||||||
```swift
|
```swift
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(url: "https://github.com/JohnEstropia/CoreStore.git", from: "7.3.0"))
|
.package(url: "https://github.com/JohnEstropia/CoreStore.git", from: "7.3.1"))
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
Declare `import CoreStore` in your swift file to use the library.
|
Declare `import CoreStore` in your swift file to use the library.
|
||||||
|
|||||||
@@ -217,7 +217,8 @@ extension CoreStoreObject {
|
|||||||
|
|
||||||
guard
|
guard
|
||||||
let object = context.fetchExisting(id) as CoreStoreObject?,
|
let object = context.fetchExisting(id) as CoreStoreObject?,
|
||||||
let rawObject = object.rawObject
|
let rawObject = object.rawObject,
|
||||||
|
!rawObject.isDeleted
|
||||||
else {
|
else {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ extension Internals {
|
|||||||
|
|
||||||
var numberOfItems: Int {
|
var numberOfItems: Int {
|
||||||
|
|
||||||
return self.structure.allItemIDs.count
|
return self.structure.allItemsCount
|
||||||
}
|
}
|
||||||
|
|
||||||
var numberOfSections: Int {
|
var numberOfSections: Int {
|
||||||
@@ -106,6 +106,59 @@ extension Internals {
|
|||||||
return self.itemIdentifiers(inSection: identifier).count
|
return self.itemIdentifiers(inSection: identifier).count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func itemIdentifier(atAllItemsIndex index: Int) -> NSManagedObjectID? {
|
||||||
|
|
||||||
|
guard index >= 0 else {
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
var remainingIndex = index
|
||||||
|
for section in self.structure.sections {
|
||||||
|
|
||||||
|
let elements = section.elements
|
||||||
|
let sectionCount = elements.count
|
||||||
|
if remainingIndex < sectionCount {
|
||||||
|
|
||||||
|
return elements[remainingIndex].differenceIdentifier
|
||||||
|
}
|
||||||
|
|
||||||
|
remainingIndex -= sectionCount
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func itemIdentifiers(atAllItemsBounds bounds: Range<Int>) -> [NSManagedObjectID] {
|
||||||
|
|
||||||
|
var remainingIndex = bounds.lowerBound
|
||||||
|
var itemIdentifiers: [NSManagedObjectID] = []
|
||||||
|
for section in self.structure.sections {
|
||||||
|
|
||||||
|
let elements = section.elements
|
||||||
|
let sectionCount = elements.count
|
||||||
|
if remainingIndex < sectionCount {
|
||||||
|
|
||||||
|
itemIdentifiers.append(
|
||||||
|
contentsOf: elements[remainingIndex..<min(sectionCount, bounds.count)]
|
||||||
|
.map({ $0.differenceIdentifier })
|
||||||
|
)
|
||||||
|
}
|
||||||
|
else if !itemIdentifiers.isEmpty {
|
||||||
|
|
||||||
|
itemIdentifiers.append(
|
||||||
|
contentsOf: elements.prefix(bounds.count - itemIdentifiers.count)
|
||||||
|
.map({ $0.differenceIdentifier })
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if itemIdentifiers.count >= bounds.count {
|
||||||
|
|
||||||
|
return itemIdentifiers
|
||||||
|
}
|
||||||
|
|
||||||
|
remainingIndex -= sectionCount
|
||||||
|
}
|
||||||
|
return itemIdentifiers
|
||||||
|
}
|
||||||
|
|
||||||
func itemIdentifiers(inSection identifier: String) -> [NSManagedObjectID] {
|
func itemIdentifiers(inSection identifier: String) -> [NSManagedObjectID] {
|
||||||
|
|
||||||
return self.structure.items(in: identifier)
|
return self.structure.items(in: identifier)
|
||||||
@@ -332,6 +385,14 @@ extension Internals {
|
|||||||
return self.sections.map({ $0.differenceIdentifier })
|
return self.sections.map({ $0.differenceIdentifier })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var allItemsCount: Int {
|
||||||
|
|
||||||
|
return self.sections.reduce(into: 0) { (result, section) in
|
||||||
|
|
||||||
|
result += section.elements.count
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var allItemIDs: [NSManagedObjectID] {
|
var allItemIDs: [NSManagedObjectID] {
|
||||||
|
|
||||||
return self.sections.lazy.flatMap({ $0.elements }).map({ $0.differenceIdentifier })
|
return self.sections.lazy.flatMap({ $0.elements }).map({ $0.differenceIdentifier })
|
||||||
|
|||||||
@@ -267,6 +267,17 @@ public func == <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, D>
|
|||||||
return Where<O>(keyPath._kvcKeyPathString!, isEqualTo: objectID)
|
return Where<O>(keyPath._kvcKeyPathString!, isEqualTo: objectID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Creates a `Where` clause by comparing if a property is equal to a value
|
||||||
|
```
|
||||||
|
let dog = dataStack.fetchOne(From<Dog>().where(\.master == john))
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
public func == <O: ObjectRepresentation, D: NSManagedObject>(_ keyPath: KeyPath<O, D>, _ object: O) -> Where<O> where O.ObjectType: NSManagedObject {
|
||||||
|
|
||||||
|
return Where<O>(keyPath._kvcKeyPathString!, isEqualTo: object.cs_id())
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates a `Where` clause by comparing if a property is not equal to a value
|
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||||
```
|
```
|
||||||
@@ -278,6 +289,17 @@ public func != <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, D>
|
|||||||
return !Where<O>(keyPath._kvcKeyPathString!, isEqualTo: objectID)
|
return !Where<O>(keyPath._kvcKeyPathString!, isEqualTo: objectID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||||
|
```
|
||||||
|
let dog = dataStack.fetchOne(From<Dog>().where(\.master != john))
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
public func != <O: ObjectRepresentation, D: NSManagedObject>(_ keyPath: KeyPath<O, D>, _ object: O) -> Where<O> where O.ObjectType: NSManagedObject {
|
||||||
|
|
||||||
|
return !Where<O>(keyPath._kvcKeyPathString!, isEqualTo: object.cs_id())
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates a `Where` clause by checking if a sequence contains a value of a property
|
Creates a `Where` clause by checking if a sequence contains a value of a property
|
||||||
```
|
```
|
||||||
@@ -303,6 +325,17 @@ public func == <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, Op
|
|||||||
return Where<O>(keyPath._kvcKeyPathString!, isEqualTo: object)
|
return Where<O>(keyPath._kvcKeyPathString!, isEqualTo: object)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Creates a `Where` clause by comparing if a property is equal to a value
|
||||||
|
```
|
||||||
|
let dog = dataStack.fetchOne(From<Dog>().where(\.master == john))
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
public func == <O: ObjectRepresentation, D: NSManagedObject>(_ keyPath: KeyPath<O, Optional<D>>, _ object: O?) -> Where<O> where O.ObjectType: NSManagedObject {
|
||||||
|
|
||||||
|
return Where<O>(keyPath._kvcKeyPathString!, isEqualTo: object?.cs_toRaw())
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates a `Where` clause by comparing if a property is not equal to a value
|
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||||
```
|
```
|
||||||
@@ -314,6 +347,17 @@ public func != <O: NSManagedObject, D: NSManagedObject>(_ keyPath: KeyPath<O, Op
|
|||||||
return !Where<O>(keyPath._kvcKeyPathString!, isEqualTo: object)
|
return !Where<O>(keyPath._kvcKeyPathString!, isEqualTo: object)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||||
|
```
|
||||||
|
let dog = dataStack.fetchOne(From<Dog>().where(\.master != john))
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
public func != <O: ObjectRepresentation, D: NSManagedObject>(_ keyPath: KeyPath<O, Optional<D>>, _ object: O?) -> Where<O> where O.ObjectType: NSManagedObject {
|
||||||
|
|
||||||
|
return !Where<O>(keyPath._kvcKeyPathString!, isEqualTo: object?.cs_toRaw())
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates a `Where` clause by checking if a sequence contains a value of a property
|
Creates a `Where` clause by checking if a sequence contains a value of a property
|
||||||
```
|
```
|
||||||
@@ -690,6 +734,17 @@ public func == <O, D: FieldRelationshipToOneType>(_ keyPath: KeyPath<O, FieldCon
|
|||||||
return Where<O>(O.meta[keyPath: keyPath].keyPath, isEqualTo: object)
|
return Where<O>(O.meta[keyPath: keyPath].keyPath, isEqualTo: object)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Creates a `Where` clause by comparing if a property is equal to a value
|
||||||
|
```
|
||||||
|
let dog = dataStack.fetchOne(From<Dog>().where(\.master == john))
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
public func == <O, D: FieldRelationshipToOneType, R: ObjectRepresentation>(_ keyPath: KeyPath<O, FieldContainer<O>.Relationship<D>>, _ object: R?) -> Where<O> where D.DestinationObjectType == R.ObjectType {
|
||||||
|
|
||||||
|
return Where<O>(O.meta[keyPath: keyPath].keyPath, isEqualTo: object?.objectID())
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates a `Where` clause by comparing if a property is equal to a value
|
Creates a `Where` clause by comparing if a property is equal to a value
|
||||||
```
|
```
|
||||||
@@ -723,6 +778,17 @@ public func != <O, D: FieldRelationshipToOneType>(_ keyPath: KeyPath<O, FieldCon
|
|||||||
return !Where<O>(O.meta[keyPath: keyPath].keyPath, isEqualTo: object)
|
return !Where<O>(O.meta[keyPath: keyPath].keyPath, isEqualTo: object)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||||
|
```
|
||||||
|
let dog = dataStack.fetchOne(From<Dog>().where(\.master != john))
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
public func != <O, D: FieldRelationshipToOneType, R: ObjectRepresentation>(_ keyPath: KeyPath<O, FieldContainer<O>.Relationship<D>>, _ object: R?) -> Where<O> where D.DestinationObjectType == R.ObjectType {
|
||||||
|
|
||||||
|
return !Where<O>(O.meta[keyPath: keyPath].keyPath, isEqualTo: object?.objectID())
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates a `Where` clause by comparing if a property is not equal to a value
|
Creates a `Where` clause by comparing if a property is not equal to a value
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public struct ListSnapshot<O: DynamicObject>: RandomAccessCollection, Hashable {
|
|||||||
public subscript(index: Index) -> ObjectPublisher<O> {
|
public subscript(index: Index) -> ObjectPublisher<O> {
|
||||||
|
|
||||||
let context = self.context!
|
let context = self.context!
|
||||||
let itemID = self.diffableSnapshot.itemIdentifiers[index]
|
let itemID = self.diffableSnapshot.itemIdentifier(atAllItemsIndex: index)!
|
||||||
return context.objectPublisher(objectID: itemID)
|
return context.objectPublisher(objectID: itemID)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,16 +83,13 @@ public struct ListSnapshot<O: DynamicObject>: RandomAccessCollection, Hashable {
|
|||||||
*/
|
*/
|
||||||
public subscript(safeIndex index: Index) -> ObjectPublisher<O>? {
|
public subscript(safeIndex index: Index) -> ObjectPublisher<O>? {
|
||||||
|
|
||||||
guard let context = self.context else {
|
guard
|
||||||
|
let context = self.context,
|
||||||
|
let itemID = self.diffableSnapshot.itemIdentifier(atAllItemsIndex: index)
|
||||||
|
else {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
let itemIDs = self.diffableSnapshot.itemIdentifiers
|
|
||||||
guard itemIDs.indices.contains(index) else {
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
let itemID = itemIDs[index]
|
|
||||||
return context.objectPublisher(objectID: itemID)
|
return context.objectPublisher(objectID: itemID)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -610,19 +607,61 @@ public struct ListSnapshot<O: DynamicObject>: RandomAccessCollection, Hashable {
|
|||||||
return self.diffableSnapshot.numberOfItems
|
return self.diffableSnapshot.numberOfItems
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func index(after i: Index) -> Index {
|
||||||
|
|
||||||
|
return i + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
public func formIndex(after i: inout Index) {
|
||||||
|
|
||||||
|
return i += 1
|
||||||
|
}
|
||||||
|
|
||||||
|
public func index(before i: Index) -> Index {
|
||||||
|
|
||||||
|
return i - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
public func formIndex(before i: inout Index) {
|
||||||
|
|
||||||
|
return i -= 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: BidirectionalCollection
|
// MARK: BidirectionalCollection
|
||||||
|
|
||||||
public func index(_ i: Int, offsetBy distance: Int) -> Int {
|
public func index(_ i: Index, offsetBy distance: Int) -> Index {
|
||||||
|
|
||||||
return i + distance
|
return i + distance
|
||||||
}
|
}
|
||||||
|
|
||||||
public func distance(from start: Int, to end: Int) -> Int {
|
public func index(_ i: Index, offsetBy distance: Int, limitedBy limit: Int) -> Index? {
|
||||||
|
|
||||||
|
let length = limit - i
|
||||||
|
if distance > 0
|
||||||
|
? length >= 0 && length < distance
|
||||||
|
: length <= 0 && length > distance {
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return i + distance
|
||||||
|
}
|
||||||
|
|
||||||
|
public func distance(from start: Index, to end: Index) -> Int {
|
||||||
|
|
||||||
return end - start
|
return end - start
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public subscript(bounds: Range<Index>) -> ArraySlice<Element> {
|
||||||
|
|
||||||
|
guard let context = self.context else {
|
||||||
|
|
||||||
|
return .init()
|
||||||
|
}
|
||||||
|
let itemIDs = self.diffableSnapshot.itemIdentifiers(atAllItemsBounds: bounds)
|
||||||
|
return ArraySlice(itemIDs.map(context.objectPublisher(objectID:)))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// MARK: Sequence
|
// MARK: Sequence
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user