Doc updates.

This commit is contained in:
Greg 2020-06-25 16:56:55 -04:00
parent 1704be1cbc
commit 0bc23404da
3 changed files with 16 additions and 18 deletions

View File

@ -379,8 +379,8 @@ An example in Core Foundation is the `getObjects:andKeys:count` method for
ns.NSArrayWithObjects(nst("key1"),nst("key2")), ns.NSArrayWithObjects(nst("key1"),nst("key2")),
) )
va,ka := make([]*ns.Id,0,5), make([]*ns.Id,0,5) // length 0, capacity 5 slices va,ka := make([]*ns.Id,0,5), make([]*ns.Id,0,5) // length 0, capacity 5 slices
dict.GetObjects(&va,&ka,5) dict.GetObjectsAndKeysCount(&va,&ka,5)
// last parameter to GetObjects is the count, must be less than or equal to the input slice capacity // last parameter is the count, must be less than or equal to the input slice capacity
fmt.Printf("Length of va is now %d\n",len(va)) // va and ka slices are now length = 2 fmt.Printf("Length of va is now %d\n",len(va)) // va and ka slices are now length = 2
for i,k := range ka { for i,k := range ka {
fmt.Printf("-- %s -> %s\n",k.NSString(),va[i].NSString()) fmt.Printf("-- %s -> %s\n",k.NSString(),va[i].NSString())
@ -469,10 +469,9 @@ results in:
```go ```go
//ns/main.go //ns/main.go
... ...
type NSWindowOrderingMode C.enum_NSWindowOrderingMode const NSWindowAbove NSInteger = C.NSWindowAbove
const NSWindowAbove NSWindowOrderingMode = C.NSWindowAbove const NSWindowBelow NSInteger = C.NSWindowBelow
const NSWindowBelow NSWindowOrderingMode = C.NSWindowBelow const NSWindowOut NSInteger = C.NSWindowOut
const NSWindowOut NSWindowOrderingMode = C.NSWindowOut
const _CLOCK_REALTIME = C._CLOCK_REALTIME const _CLOCK_REALTIME = C._CLOCK_REALTIME
const _CLOCK_MONOTONIC = C._CLOCK_MONOTONIC const _CLOCK_MONOTONIC = C._CLOCK_MONOTONIC
@ -534,7 +533,7 @@ registers a callback for `centralManagerDidUpdateState`, allocates
a `CBCentralManager` object, and installs our delegate: a `CBCentralManager` object, and installs our delegate:
```go ```go
func cb(c ns.CBCentralManager) { func cb(self ns.CBDelegate, c *ns.CBCentralManager) {
... ...
} }
@ -558,8 +557,8 @@ messages will point you in the right direction.
``` ```
$ go build $ go build
./main.go:127:43: cannot use didFinishLaunching (type func(*ns.NSNotification, bool)) as type ./main.go:127:43: cannot use didFinishLaunching (type func(ns.CBDelegate, *ns.NSNotification, bool)) as type
func(*ns.NSNotification) in argument to del.ApplicationDidFinishLaunchingCallback func(ns.CBDelegate, *ns.NSNotification) in argument to del.ApplicationDidFinishLaunchingCallback
``` ```
In the above example, the build failed because an extra `bool` parameter was In the above example, the build failed because an extra `bool` parameter was
included in the callback function. The compiler is telling you that the right included in the callback function. The compiler is telling you that the right
@ -648,7 +647,7 @@ func main() {
} }
``` ```
Pretty simple right? Not really, NSWrap just generated over 39,000 lines of Pretty simple right? Not really, NSWrap just generated 114,000 lines of
code. See `examples/app` for a slightly more complex example with working code. See `examples/app` for a slightly more complex example with working
menus, visual format-based auto layout, and a custom button class. menus, visual format-based auto layout, and a custom button class.
@ -683,12 +682,11 @@ name, its return type, and the names and types of its parameters if any.
Since multiple inheritance is not permitted in Objective-C, it is not possible Since multiple inheritance is not permitted in Objective-C, it is not possible
to specify more than one superclass in a `subclasses` entry. to specify more than one superclass in a `subclasses` entry.
Go callbacks for overridden methods are passed a special struct Go callbacks for overridden methods are passed a special struct filled with
as their first parameter. This struct is filled with superclass methods, which superclass methods, which allows you to do things like this:
allows you to do things like this:
```go ```go
func methodCallback(super ns.MyClassSupermethods, param NSString) { func methodCallback(self ns.MyClass, super ns.MyClassSupermethods, param NSString) {
... ...
super.Method(param) super.Method(param)
} }
@ -709,7 +707,7 @@ subclasses:
``` ```
```go ```go
func pressed() { func pressed(self ns.GButton, super ns.GButtonSupermethods) {
fmt.Println("Button pressed!") fmt.Println("Button pressed!")
} }
... ...

View File

@ -10,7 +10,7 @@ import (
"time" "time"
) )
func updateState(self ns.CBDelegate, c *ns.CBCentralManager) { func updateState(self ns.CBDelegate, c *ns.CBCentralManager, b bool) {
fmt.Printf("Go: did update state\n") fmt.Printf("Go: did update state\n")
switch ns.NSInteger(cm.CBManager.State()) { switch ns.NSInteger(cm.CBManager.State()) {
case ns.CBManagerStateUnknown: case ns.CBManagerStateUnknown:

View File

@ -852,7 +852,7 @@ func (w *Wrapper) AddTypedef(n, t string) {
w._processType(tp) w._processType(tp)
} else { } else {
cgt := tp.CGoType() cgt := tp.CGoType()
if Debug && false { if Debug {
fmt.Printf(" processing un-wrapped type for %s -> %s\n", n, cgt) fmt.Printf(" processing un-wrapped type for %s -> %s\n", n, cgt)
} }
types.AddTypedef(n, tp) types.AddTypedef(n, tp)
@ -1372,7 +1372,7 @@ type %s %s
fmt.Printf(" gtp = %s; ctp = %s\n", gtp, ctp) fmt.Printf(" gtp = %s; ctp = %s\n", gtp, ctp)
} }
for _, c := range e.Constants { for _, c := range e.Constants {
w.goConst.WriteString(fmt.Sprintf(`const %s %s= C.%s w.goConst.WriteString(fmt.Sprintf(`const %s %s = C.%s
`, c.name, gtp, c.name)) `, c.name, gtp, c.name))
} }
w.goConst.WriteString("\n") w.goConst.WriteString("\n")