This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftData | |
@Model | |
class Item { | |
@Attribute(.unique) var name: String | |
var kind: String | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftData | |
@Model | |
class Item { | |
@Attribute(.unique) var name: String | |
var kind: String | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftData | |
import SwiftUI | |
@propertyWrapper | |
struct SectionedQuery<SectionIdentifier, Result>: DynamicProperty | |
where SectionIdentifier: Hashable, Result: PersistentModel { | |
private let sectionIdentifier: KeyPath<Result, SectionIdentifier> | |
@Query private var results: [Result] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import SwiftData | |
@propertyWrapper | |
struct SectionedQuery<SectionIdentifier, Result> | |
where SectionIdentifier: Hashable, Result: PersistentModel { | |
private let sectionIdentifier: KeyPath<Result, SectionIdentifier> | |
@Query private var results: [Result] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftData | |
import SwiftUI | |
@propertyWrapper | |
struct SectionedQuery<SectionIdentifier, Result> | |
where SectionIdentifier: Hashable, Result: PersistentModel { | |
private let sectionIdentifier: KeyPath<Result, SectionIdentifier> | |
private var results: [Result] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftData | |
import SwiftUI | |
@propertyWrapper | |
struct SectionedQuery<SectionIdentifier, Result> | |
where SectionIdentifier: Hashable, Result: PersistentModel { | |
private let sectionIdentifier: KeyPath<Result, SectionIdentifier> | |
private var results: [Result] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftData | |
import SwiftUI | |
@propertyWrapper | |
struct SectionedQuery<SectionIdentifier, Result> | |
where SectionIdentifier: Hashable, Result: PersistentModel { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftData | |
struct SectionedResults<SectionIdentifier, Result>: RandomAccessCollection | |
where SectionIdentifier: Hashable, Result: PersistentModel { | |
// ... | |
init(sectionIdentifier: KeyPath<Result, SectionIdentifier>, | |
results: [Result]) { | |
let groupedResults = Dictionary(grouping: results) { result in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Array where Iterator.Element: Hashable { | |
func uniqued() -> [Element] { | |
var seen: Set<Iterator.Element> = [] | |
return filter { seen.insert($0).inserted } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftData | |
struct SectionedResults<SectionIdentifier, Result>: RandomAccessCollection | |
where SectionIdentifier: Hashable, Result: PersistentModel { | |
typealias Element = Self.Section | |
typealias Index = Int | |
typealias Iterator = IndexingIterator<Self> | |
var elements: [Element] |
NewerOlder