https://github.com/leoho0722/swifthelpers
Use Swift to create some amazing things!
https://github.com/leoho0722/swifthelpers
ios macos swift swift-package-manager
Last synced: 15 days ago
JSON representation
Use Swift to create some amazing things!
- Host: GitHub
- URL: https://github.com/leoho0722/swifthelpers
- Owner: leoho0722
- License: mit
- Created: 2023-06-13T17:55:30.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-04T16:35:56.000Z (over 1 year ago)
- Last Synced: 2026-03-27T18:53:39.539Z (3 months ago)
- Topics: ios, macos, swift, swift-package-manager
- Language: Swift
- Homepage: https://swiftpackageindex.com/leoho0722/SwiftHelpers
- Size: 1.1 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwiftHelpers
[](https://swiftpackageindex.com/leoho0722/SwiftHelpers)
[](https://swiftpackageindex.com/leoho0722/SwiftHelpers)

Use Swift to create some amazing things!
## Minimum Requirement
* iOS 15.0 or above
* macOS 12.0 or above
* Xcode 14.0 or above
## Package Development Environment
* macOS Sonoma 14.4.1 (23E224)
* Xcode 15.3 (15E204a)
* Swift 5.9.2 (5.9.2.2.56)
## Install
Currently only installation using Swift Package Manager is supported.
```git
https://github.com/leoho0722/SwiftHelpers.git
```

## How to use
### Example: Convert to JSON Data
```swift
import Foundation
import SwiftHelpers
func createURLRequest(with url: URL,
method: HTTP.Method,
parameters: E) -> URLRequest where E: Encodable {
var request = URLRequest(url: url)
request.httpMethod = method.rawValue
request.allHTTPHeaderFields = [
HTTP.HeaderFields.contentType.rawValue : HTTP.ContentType.json.rawValue
]
if method != .get {
request.httpBody = try? JSON.toJsonData(data: parameters)
}
return request
}
```
### Example: Safely use SF Symbols with UIKit and AppKit and SwiftUI
#### UIKit
```swift
import SwiftHelpers
import UIKit
class ViewController: UIViewController {
private let imageView = UIImageView()
override func viewDidLoad() {
super.viewDidLoad()
imageView.image = UIImage(symbols: .applelogo) // Use SwiftHelpers
// imageView.image = UIImage(systemName: "applelogo") // Use UIKit
view.addSubView(imageView)
// ...
}
}
```
#### AppKit
```swift
import Cocoa
import SwiftHelpers
class ViewController: NSViewController {
private let imageView = NSImageView()
override func viewDidLoad() {
super.viewDidLoad()
imageView.image = NSImage(symbols: .applelogo) // Use SwiftHelpers
// imageView.image = NSImage(systemSymbolName: "applelogo", accessibilityDescription: nil) // Use AppKit
view.addSubView(imageView)
// ...
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
}
```
#### SwiftUI
```swift
import SwiftHelpers
import SwiftUI
struct ContentView: View {
var body: some View {
Image(symbols: .applelogo) // Use SwiftHelpers
// Image(systemName: "applelogo") // Use SwiftUI
Label("Safely use SF Symobols with SwiftUI", symbols: .applelogo) // Use SwiftHelpers
// Label("Use SF Symobols with SwiftUI", systemImage: "applelogo") // Use SwiftUI
// ...
}
}
```