2019-04-29 11:46:48 -04:00
|
|
|
package main
|
2019-04-30 09:14:25 -04:00
|
|
|
//go:generate nswrap
|
2019-04-29 11:46:48 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"gitlab.wow.st/gmp/nswrap/examples/foundation/ns"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2019-05-03 13:14:30 -04:00
|
|
|
n1 := ns.NSStringWithUTF8String(ns.CharWithGoString("hi there"))
|
2019-04-29 11:46:48 -04:00
|
|
|
c1 := n1.CapitalizedString()
|
|
|
|
gs := c1.UTF8String().String()
|
|
|
|
fmt.Println(gs)
|
2019-05-06 13:21:36 -04:00
|
|
|
n2 := ns.NSStringAlloc()
|
|
|
|
n2 = n2.InitWithGoString("hi world")
|
2019-05-03 13:14:30 -04:00
|
|
|
n3 := ns.NSStringWithGoString("ok bye")
|
2019-05-24 15:40:01 -04:00
|
|
|
fmt.Printf("%s\n",n3)
|
2019-05-01 12:32:42 -04:00
|
|
|
a := ns.NSMutableArrayWithObjects(n1,n2,n3)
|
2019-04-29 16:14:45 -04:00
|
|
|
fmt.Println("Length(a) = ",a.Count())
|
2019-04-30 10:34:56 -04:00
|
|
|
fmt.Println("is n2 in a?",a.ContainsObject(n2))
|
|
|
|
fmt.Println("is c1 in a?",a.ContainsObject(c1))
|
2019-05-01 10:58:29 -04:00
|
|
|
n4 := n2.SubstringFromIndex(3)
|
|
|
|
n5 := n3.SubstringToIndex(4)
|
|
|
|
a.AddObject(n4)
|
|
|
|
a.AddObject(n5)
|
|
|
|
fmt.Println("Length(a) = ",a.Count())
|
2019-05-01 12:32:42 -04:00
|
|
|
a2 := a.SubarrayWithRange(ns.NSMakeRange(1,3))
|
|
|
|
fmt.Println("Length(a2) = ",a2.Count())
|
|
|
|
i1 := a.ObjectAtIndex(1).NSString()
|
2019-05-23 16:31:47 -04:00
|
|
|
fmt.Printf("i1 = %@\n",i1)
|
|
|
|
fmt.Printf("i1.Ptr() = %p\n",i1.Ptr())
|
|
|
|
a.ObjectEnumerator().ForIn(func(o ns.Id) bool {
|
2019-05-24 15:40:01 -04:00
|
|
|
fmt.Println(o.NSString())
|
2019-05-02 14:14:29 -04:00
|
|
|
return true
|
|
|
|
})
|
2019-05-23 16:31:47 -04:00
|
|
|
s1 := ns.NSSetWithObjects(n1,n2)
|
|
|
|
a = ns.NSMutableArrayWithObjects(n1,s1)
|
|
|
|
a.ObjectEnumerator().ForIn(func(o ns.Id) bool {
|
|
|
|
fmt.Printf("%s -- ",o.ClassName().UTF8String())
|
|
|
|
switch {
|
|
|
|
case o.IsKindOfClass(ns.NSStringClass()):
|
|
|
|
fmt.Printf("It's a string\n")
|
|
|
|
case o.IsKindOfClass(ns.NSSetClass()):
|
|
|
|
fmt.Printf("It's a set\n")
|
|
|
|
default:
|
|
|
|
fmt.Printf("I don't know what it is!\n")
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
a2 = ns.NSArrayWithObjects(n1,n2,n3,s1)
|
|
|
|
a2.ObjectEnumerator().ForIn(func (o ns.Id) bool {
|
|
|
|
switch {
|
|
|
|
case o.IsKindOfClass(ns.NSStringClass()):
|
|
|
|
fmt.Println(o.NSString().UTF8String())
|
|
|
|
return true // continue enumeration
|
|
|
|
default:
|
|
|
|
fmt.Println("Unknown class")
|
|
|
|
return false // terminate enumeration
|
|
|
|
}
|
|
|
|
})
|
2019-04-29 11:46:48 -04:00
|
|
|
}
|