You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<ahref="https://twitter.com/progrium"title="@progrium on Twitter"><imgsrc="https://img.shields.io/badge/twitter-@progrium-55acee.svg"alt="@progrium on Twitter"></a>
> June 13, 2024: **MacDriver is now DarwinKit and we're about to release 0.5.0!** The [legacy branch](https://github.com/progrium/macdriver/tree/legacy) and [previous releases](https://github.com/progrium/macdriver/releases) are still available for existing code to work against. Use `main` until 0.5.0 is released.
12
+
> June 13, 2024: **MacDriver is now DarwinKit and we're about to release 0.5.0!** The [legacy branch](https://github.com/progrium/darwinkit/tree/legacy) and [previous releases](https://github.com/progrium/darwinkit/releases) are still available for existing code to work against. Use `main` until 0.5.0 is released.
13
13
14
14
------
15
15
16
-
DarwinKit lets you work with [supported Apple frameworks](https://pkg.go.dev/github.com/progrium/macdriver/macos@main#section-directories) and build native applications using Go. With XCode and Go 1.18+ installed, you can write this program in a `main.go` file:
16
+
DarwinKit lets you work with [supported Apple frameworks](https://pkg.go.dev/github.com/progrium/darwinkit/macos@main#section-directories) and build native applications using Go. With XCode and Go 1.18+ installed, you can write this program in a `main.go` file:
17
17
18
18
```go
19
19
package main
20
20
21
21
import (
22
-
"github.com/progrium/macdriver/objc"
23
-
"github.com/progrium/macdriver/macos"
24
-
"github.com/progrium/macdriver/macos/appkit"
25
-
"github.com/progrium/macdriver/macos/foundation"
26
-
"github.com/progrium/macdriver/macos/webkit"
22
+
"github.com/progrium/darwinkit/objc"
23
+
"github.com/progrium/darwinkit/macos"
24
+
"github.com/progrium/darwinkit/macos/appkit"
25
+
"github.com/progrium/darwinkit/macos/foundation"
26
+
"github.com/progrium/darwinkit/macos/webkit"
27
27
)
28
28
29
29
funcmain() {
@@ -60,7 +60,7 @@ Then in this directory run:
60
60
61
61
```
62
62
go mod init helloworld
63
-
go get github.com/progrium/macdriver@main
63
+
go get github.com/progrium/darwinkit@main
64
64
go run main.go
65
65
```
66
66
@@ -74,7 +74,7 @@ Although currently outside the scope of this project, if you wanted you could pu
74
74
* Your programs link against the actual Apple frameworks using [cgo](https://pkg.go.dev/cmd/cgo), so XCode needs to be installed for the framework headers.
75
75
* You will be using two memory management systems. Framework objects are managed by [Objective-C memory management](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html#//apple_ref/doc/uid/10000011-SW1), so be sure to read our docs on [memory management](docs/memorymanagement.md) with DarwinKit.
76
76
* Exceptions in frameworks will segfault, giving you both an Objective-C stacktrace and a Go panic stacktrace. You will be debugging a hybrid Go and Objective-C program.
77
-
* Goroutines that interact with GUI objects need to [dispatch](https://pkg.go.dev/github.com/progrium/macdriver@main/dispatch) operations on the main thread otherwise it will segfault.
77
+
* Goroutines that interact with GUI objects need to [dispatch](https://pkg.go.dev/github.com/progrium/darwinkit@main/dispatch) operations on the main thread otherwise it will segfault.
78
78
79
79
This is all tenable for simple programs, but these are the reasons we don't *recommend* large/complex programs using DarwinKit.
80
80
@@ -131,7 +131,7 @@ call in Go, the `objc` package receives it as a raw pointer, which it first puts
131
131
bindings for a class define a struct type that embeds an `objc.Object` struct, which contains a single
132
132
field to hold the `unsafe.Pointer`. So unless working with a primitive type, you're working with an `unsafe.Pointer` wrapped in an `objc.Object` wrapped in a struct type that has the methods for the class of the object of the pointer. Be sure to read our documentation on [memory management](docs/memorymanagement.md).
133
133
134
-
If you have questions, feel free to ask in the [discussion forums](https://github.com/progrium/macdriver/discussions).
134
+
If you have questions, feel free to ask in the [discussion forums](https://github.com/progrium/darwinkit/discussions).
Copy file name to clipboardExpand all lines: docs/memorymanagement.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -6,9 +6,9 @@ Working with Objective-C from Go requires understanding how [Objective-C memory
6
6
7
7
ARC is a feature of the Objective-C compiler, which does not compile Go code. Therefore memory management of Objective-C objects in Go is done with MMR. DarwinKit continues the policy of "the code that allocates is the code responsible for releasing" so unless you explicitly call the `Alloc()` method, you can assume `Autorelease()` has been called on the object unless documented otherwise.
8
8
9
-
This applies to the Go-style constructors made for classes, which are the functions prefixed with "New". This also means all code should be run in an autorelease pool. This is already the case for most delegates and callbacks since these are called from the AppKit event loop, which has an autorelease pool for every cycle of the loop. Code outside this loop (such as code run before appkit.Application is run, or code in a goroutine) should be wrapped in [objc.WithAutoreleasePool](https://pkg.go.dev/github.com/progrium/macdriver@main/objc#WithAutoreleasePool).
9
+
This applies to the Go-style constructors made for classes, which are the functions prefixed with "New". This also means all code should be run in an autorelease pool. This is already the case for most delegates and callbacks since these are called from the AppKit event loop, which has an autorelease pool for every cycle of the loop. Code outside this loop (such as code run before appkit.Application is run, or code in a goroutine) should be wrapped in [objc.WithAutoreleasePool](https://pkg.go.dev/github.com/progrium/darwinkit@main/objc#WithAutoreleasePool).
10
10
11
-
Objects that you want to retain should be passed by reference to [objc.Retain](https://pkg.go.dev/github.com/progrium/macdriver@main/objc#Retain). Using this instead of the object's `Retain()` method directly will let the Go GC know it should release the object before cleaning it up. Objects that only need to exist within the current event cycle don't need to be retained. Objects passed to other objects that need to be retained by them should be retained by the receiving object. If you get an unexplained segfault, chances are an object needed to be retained. A common situation for this are appkit.Windows you create.
11
+
Objects that you want to retain should be passed by reference to [objc.Retain](https://pkg.go.dev/github.com/progrium/darwinkit@main/objc#Retain). Using this instead of the object's `Retain()` method directly will let the Go GC know it should release the object before cleaning it up. Objects that only need to exist within the current event cycle don't need to be retained. Objects passed to other objects that need to be retained by them should be retained by the receiving object. If you get an unexplained segfault, chances are an object needed to be retained. A common situation for this are appkit.Windows you create.
0 commit comments