https://github.com/ddddxxx/swiftcf
Use CoreFoundation based framework in Swift painlessly.
https://github.com/ddddxxx/swiftcf
corefoundation coregraphics coretext imageio iokit
Last synced: 8 months ago
JSON representation
Use CoreFoundation based framework in Swift painlessly.
- Host: GitHub
- URL: https://github.com/ddddxxx/swiftcf
- Owner: ddddxxx
- License: mit
- Created: 2019-08-27T13:43:22.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-05-27T12:20:42.000Z (about 5 years ago)
- Last Synced: 2025-04-04T19:32:59.784Z (about 1 year ago)
- Topics: corefoundation, coregraphics, coretext, imageio, iokit
- Language: Swift
- Homepage:
- Size: 369 KB
- Stars: 18
- Watchers: 2
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwiftCF
[](https://github.com/ddddxxx/SwiftCF/actions)
Using CoreFoundation based framework in Swift painlessly.
Wrapped frameworks:
- [x] CoreFoundation
- [x] CoreGraphics
- [x] CoreText
- [x] ImageIO
- [x] IOKit
- [x] HID
- [x] ApplicationServices
- [x] Accessibility (`AXUIElement`)
- [ ] CoreMedia
- [ ] CoreVideo
- [ ] CFNetwork
- [ ] Security
- [ ] CoreServices
- [ ] VideoToolbox
- [ ] SystemConfiguration
## Usage
### Dynamic casting to CoreFoundation types via the type-id mechanism.
```swift
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
```swift
let cfStr: CFString = .from("foo")
let nsStr: NSString = cfStr.asNS()
let str: String = cfStr.asSwift()
```
### Convenient Extensions
```swift
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
```swift
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](LICENSE).