Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package nslog
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation
#import <Foundation/Foundation.h>
void Log(const char *text) {
NSString *nss = [NSString stringWithUTF8String:text];
NSLog(@"%@", nss);
}
*/
import "C"
import (
"io"
"unsafe"
)
type nslog struct{}
func New() io.Writer {
return new(nslog)
}
func (l *nslog) Write(p []byte) (n int, err error) {
msg := append(p[:], 0)
C.Log((*C.char)(unsafe.Pointer(&msg[0])))
return len(p), nil
}
func (l *nslog) WriteString(s string) (n int, err error) {
cs := C.CString(s)
defer C.free(unsafe.Pointer(cs))
C.Log(cs)
return len(s), nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment