5.17 Cocoa Foundation

► |  | The Racket Foreign Interface

1 | Overview
2 | Loading Foreign Libraries
3 | C Types
4 | Pointer Functions
5 | Derived Utilities
6 | Miscellaneous Support
7 | Unexported Primitive Functions
| Bibliography
| Index

▼ | 5 | Derived Utilities

5.1 | Safe Homogenous Vectors
5.2 | Safe C Vectors
5.3 | Tagged C Pointer Types
5.4 | Serializable C Struct Types
5.5 | Static Callout and Callback Cores
5.6 | Defining Bindings
5.7 | Allocation and Finalization
5.8 | Custodian Shutdown Registration
5.9 | Atomic Execution
5.10 | Speculatively Atomic Execution
5.11 | Thread Scheduling
5.12 | Ports
5.13 | Process-Wide and Place-Wide Registration
5.14 | Operating System Threads
5.15 | Garbage Collection Callbacks
5.16 | Objective-C FFI
5.17 | Cocoa Foundation
5.18 | COM (Common Object Model)
5.19 | File Security-Guard Checks
5.20 | Windows API Helpers
5.21 | Virtual Machine Primitives
5.22 | Declaring Foreign Libraries Needed at Run Time

► | 5.17 | Cocoa Foundation

5.17.1 | Strings
5.17.2 | Allocation Pools

On this page:

5.17.1 Strings
_ NSString
5.17.2 Allocation Pools
call-with-autorelease
with-autorelease

Racket
top contents ← prev up next →

### 5.17 Cocoa Foundation🔗ℹ

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

#### 5.17.1 Strings🔗ℹ

(require ffi/unsafe/nsstring) | package: base

> value _NSString : ctype?

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

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

#### 5.17.2 Allocation Pools🔗ℹ

(require ffi/unsafe/nsalloc) | package: base

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

> procedure (call-with-autorelease thunk) → any
> thunk : (-> any)

Calls thunk in atomic mode and with a fresh NSAutoreleasePool that is released after thunk returns.

> syntax (with-autorelease expr)

A shorthand for (call-with-autorelease (lambda () expr)).
top contents ← prev up next →