{"size": 1723, "ext": "scrbl", "max_stars_repo_path": "pkgs/racket-doc/scribblings/foreign/ns.scrbl", "max_stars_repo_name": "lkh01/racket", "max_stars_repo_stars_event_min_datetime": "2018-07-29T04:13:52.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-14T16:11:17.000Z", "max_issues_repo_path": "pkgs/racket-doc/scribblings/foreign/ns.scrbl", "max_issues_repo_name": "lkh01/racket", "max_issues_repo_issues_event_min_datetime": "2017-08-25T20:26:37.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-26T17:48:40.000Z", "max_forks_repo_path": "pkgs/racket-doc/scribblings/foreign/ns.scrbl", "max_forks_repo_name": "lkh01/racket", "max_forks_repo_forks_event_min_datetime": "2016-04-25T11:47:57.000Z", "max_forks_repo_forks_event_max_datetime": "2017-05-09T14:52:48.000Z"}
{"max_stars_count": 10, "max_issues_count": 15, "max_forks_count": 3, "avg_line_length": 31.9074074074, "max_line_length": 68, "alphanum_fraction": 0.7103888566}
#lang scribble/doc
@(require scribble/manual
          (for-label racket/base
                     ffi/unsafe/nsalloc
                     ffi/unsafe/nsstring))

@title[#:tag "ns"]{Cocoa Foundation}

The @racketmodname[ffi/unsafe/nsalloc] and
@racketmodname[ffi/unsafe/nsstring] libraries provide basic
facilities for working with Cocoa and/or Mac OS Foundation
libraries (usually along with @racket[ffi/objc]).

@; ----------------------------------------

@section{Strings}

@defmodule[ffi/unsafe/nsstring]

@defthing[_NSString ctype?]{

A type that converts between Racket strings and
@as-index{@tt{NSString*}} (a.k.a. @as-index{@tt{CFStringRef}})
values. That is, use @tt{_NSString} as a type for a foreign-function
@tt{NSString*} argument or result.

The @racket[_NSString] conversion keeps a weak mapping from Racket
strings to converted strings, so that converting the same string (in
the @racket[equal?] sense) multiple times may avoid allocating
multiple @tt{NSString} objects.}


@; ----------------------------------------

@section{Allocation Pools}

@defmodule[ffi/unsafe/nsalloc]{Calling any Foundation API that
allocates requires an @tt{NSAutoreleasePool} installed. The
@racketmodname[ffi/unsafe/nsalloc] library provides a function and
shorthand syntactic form for setting up such a context. (The
@racket[_NSString] type creates an autorelease pool implicitly while
converting from/to a Racket string, however.)}

@defproc[(call-with-autorelease [thunk (-> any)]) any]{

Calls @racket[thunk] in atomic mode and with a fresh
@tt{NSAutoreleasePool} that is @tt{releas}ed after @racket[thunk]
returns.}


@defform[(with-autorelease expr)]{

A shorthand for @racket[(call-with-autorelease (lambda () expr))].}
