Skip to content

allevato/icu4c-swift

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Low-level ICU C APIs for Swift

⚠️ tl;dr: This package contains low-level C APIs. You probably want icu-swift instead.

This package defines a module named ICU4C that exposes the C API of the ICU library to Swift.

The APIs are exposed without renaming (that is, they do not contain the library version number as a suffix); see the ICU documentation on architectural design for more information about this.

This package exposes only the raw C API; because of Swift's stricter type conversions compared to C, it's fairly verbose to use (see the example below). If you're reading this, you probably want the companion icu-swift package instead, which imports ICU4C but wraps it in a much more convenient Swift API to use ICU functionality.

Usage

If you really want to use the bare C API:

  1. Add this package as a dependency in your Package.swift file.

    let package = Package(
      ...,
      dependencies: [
        .Package(url: "https://github.com/allevato/icu4c-swift.git", majorVersion: 1, minor: 0),
      ]
      ...,
    )
  2. Import ICU4C and call the C functions.

    import ICU4C
    
    let x: UnicodeScalar = "x"
    let category = u_getIntPropertyValue(Int32(bitPattern: x.value),
                                         UCHAR_GENERAL_CATEGORY)
    print(UInt32(bitPattern: category) == U_LOWERCASE_LETTER.rawValue)  // "true"