forked from silvrwolfboy/macdriver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSArray.go
46 lines (39 loc) · 1.44 KB
/
NSArray.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package core
import (
"github.com/progrium/macdriver/objc"
)
import "C"
// NSArray is a static ordered collection of objects.
// https://developer.apple.com/documentation/foundation/nsarray?language=objc
type NSArray struct {
gen_NSArray
}
// NSArray_WithObjects creates and returns an array containing the objects in the argument list.
// https://developer.apple.com/documentation/foundation/nsarray/1460068-initwithobjects?language=objc
func NSArray_WithObjects(objs ...objc.Object) NSArray {
objsInterface := make([]interface{}, len(objs))
for i, obj := range objs {
objsInterface[i] = obj
}
return NSArray_fromRef(objc.Get("NSArray").Send("arrayWithObjects:", objsInterface...))
}
// Count returns the number of objects in the array.
// https://developer.apple.com/documentation/foundation/nsarray/1409982-count?language=objc
func (a NSArray) Count() uint64 {
return uint64(a.gen_NSArray.Count())
}
// ObjectAtIndex returns the object located at the specified index.
// https://developer.apple.com/documentation/foundation/nsarray/1417555-objectatindex?language=objc
func (a NSArray) ObjectAtIndex(i uint64) objc.Object {
return a.Send("objectAtIndex:", i)
}
// Strings returns the NSArray as slice of string by calling the String Method on each objc.Object.
func (a NSArray) Strings() []string {
count := int(a.Count())
ss := make([]string, count)
for i := 0; i < count; i++ {
o := a.ObjectAtIndex(uint64(i))
ss[i] = o.String()
}
return ss
}