API Docs

A 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

identifier

string
A unique identifier for this group object (UUID string).

attribute

string
The metadata attribute name by which results in this group are clustered.

count

number
The number of results contained in this group.

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.
value() -> NSObject
NSObject
The attribute value (string, number, Date, etc.) or null
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.
results() -> HSSpotlightItem[]
HSSpotlightItem[]
An array of `HSSpotlightItem` objects
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.
subgroups() -> HSSpotlightGroup[]
HSSpotlightGroup[]
An array of `HSSpotlightGroup` objects
// Two-level grouping: contentType → kind
q.groups().forEach(type => {
    type.subgroups().forEach(kind =>
        console.log(type.value() + '/' + kind.value() + ': ' + kind.count)
    )
})