NsdkUtils
Utility functions for NSDK string management and memory handling....
Declaration
struct NsdkUtilsSummary
Utility functions for NSDK string management and memory handling.
NsdkUtils provides helper methods for safely managing C string conversions
and memory allocation when working with the NSDK C API.
Overview
The utilities in this struct help manage the complexity of converting between Swift strings and C strings while ensuring proper memory cleanup and avoiding memory leaks.
Methods
| Name | Type | Summary |
|---|---|---|
| static withNsdkStrings<Result>(_ body | Result | ## Memory Management The function automatically: - Allocates memory for each string using strdup- Tracks all allocated pointers - Frees all memory when the scope exits (even if an error is thrown) - Handles nil and empty strings gracefully |
This function provides a convenient way to work with multiple C strings in a single scope
while ensuring proper memory management. It automatically allocates memory for C strings
and cleans up all allocated memory when the scope exits.
Use this function when you need to have multiple C strings in a single scope and
the number of nested scopes gets too messy. Otherwise, prefer Swift's built-in
String.withCStringfor simpler cases.- Parameter body: A closure that receives a function for creating NSDK strings
- Returns: The result of executing the body closure
- Throws: Any error thrown by the body closure
## Example