Swiftpack.co - ddddxxx/SwiftCF as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by ddddxxx.
ddddxxx/SwiftCF v0.2.1
Use CoreFoundation based framework in Swift painlessly.
⭐️ 19
🕓 2 years ago
.package(url: "https://github.com/ddddxxx/SwiftCF.git", from: "v0.2.1")

SwiftCF

Github CI Status

Using CoreFoundation based framework in Swift painlessly.

Wrapped frameworks:

  • ☑ CoreFoundation
  • ☑ CoreGraphics
  • ☑ CoreText
  • ☑ ImageIO
  • ☑ IOKit
    • ☑ HID
  • ☑ ApplicationServices
    • ☑ Accessibility (AXUIElement)
  • ☐ CoreMedia
  • ☐ CoreVideo
  • ☐ CFNetwork
  • ☐ Security
  • ☐ CoreServices
  • ☐ VideoToolbox
  • ☐ SystemConfiguration

Usage

Dynamic casting to CoreFoundation types via the type-id mechanism.

import SwiftCF

let str: Any = "foo" as CFString

let s0 = str as? CFString
// ❗️ Conditional downcast to CoreFoundation type 'CFString' will always succeed

let s1: CFString = cfCast(str) // or
let s2 = cfCast(str, to: CFString.self) // or
let s3 = CFString.cast(str)
// ✅

Toll-Free-Bridging

let cfStr: CFString = .from("foo")
let nsStr: NSString = cfStr.asNS()
let str: String = cfStr.asSwift()

Convenient Extensions

let str = "foo" as CFString

str.length
// Replace CFStringGetLength(str)

CFStringTokenizer.create(string: str)
// Replace 😱 CFStringTokenizerCreate(kCFAllocatorDefault, str, CFRange(location: 0, length: CFStringGetLength(str)), kCFStringTokenizerUnitWord, CFLocaleGetSystem())

Swift Protocol Conformance

let arr = [1, 3.14, "foo"] as CFArray

for item in arr {
    // 😃 CFArray now conforms to RandomAccessCollection.
}

Requirements

  • Swift 5.0+

License

SwiftCF is available under the MIT license. See the LICENSE file.

GitHub

link
Stars: 19
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics