ndb: add subscript and count for TagsSequence
These are helpful
This commit is contained in:
@@ -40,6 +40,14 @@ struct TagIterator: IteratorProtocol {
|
|||||||
return el
|
return el
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subscript(index: Int) -> NdbTagElem? {
|
||||||
|
if index >= tag.pointee.count {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return NdbTagElem(note: note, tag: tag, index: Int32(index))
|
||||||
|
}
|
||||||
|
|
||||||
var index: Int32
|
var index: Int32
|
||||||
let note: NdbNote
|
let note: NdbNote
|
||||||
var tag: UnsafeMutablePointer<ndb_tag>
|
var tag: UnsafeMutablePointer<ndb_tag>
|
||||||
|
|||||||
@@ -40,6 +40,21 @@ struct TagsIterator: IteratorProtocol {
|
|||||||
struct TagsSequence: Sequence {
|
struct TagsSequence: Sequence {
|
||||||
let note: NdbNote
|
let note: NdbNote
|
||||||
|
|
||||||
|
var count: UInt16 {
|
||||||
|
note.note.pointee.tags.count
|
||||||
|
}
|
||||||
|
|
||||||
|
subscript(index: Int) -> Iterator.Element? {
|
||||||
|
var i = 0
|
||||||
|
for element in self {
|
||||||
|
if i == index {
|
||||||
|
return element
|
||||||
|
}
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func makeIterator() -> TagsIterator {
|
func makeIterator() -> TagsIterator {
|
||||||
return .init(note: note)
|
return .init(note: note)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user