HSSpotlightGroup
TypeA grouped set of Spotlight results that share a common metadata attribute value.
Groups are returned by HSSpotlightQuery.groups() when grouping attributes have been
configured with setGroupingAttributes(). Do not instantiate HSSpotlightGroup directly.
When multiple grouping attributes are specified, groups nest: each group has subgroups()
containing the next level of grouping.
Properties
Methods
value() -> NSObject
The shared value of the grouping attribute for all results in this group.
Returns `null` only in the unlikely case that the underlying value cannot be bridged.
Declaration
value() -> NSObject
Returns
NSObject
The attribute value (string, number, Date, etc.) or null
Example
q.groups().forEach(g => console.log(g.attribute + ' = ' + g.value()))
results() -> HSSpotlightItem[]
Returns the items contained in this group as an array of `HSSpotlightItem` objects.
Declaration
results() -> HSSpotlightItem[]
Returns
HSSpotlightItem[]
An array of `HSSpotlightItem` objects
Example
q.groups().forEach(group => {
console.log(group.value() + ': ' + group.count + ' items')
group.results().forEach(item =>
console.log(' ' + item.valueForAttribute('kMDItemPath'))
)
})
subgroups() -> HSSpotlightGroup[]
Returns nested subgroups when multiple grouping attributes were specified.
Returns an empty array if no subgroups exist for this group.
Declaration
subgroups() -> HSSpotlightGroup[]
Returns
HSSpotlightGroup[]
An array of `HSSpotlightGroup` objects
Example
// Two-level grouping: contentType → kind
q.groups().forEach(type => {
type.subgroups().forEach(kind =>
console.log(type.value() + '/' + kind.value() + ': ' + kind.count)
)
})