Use Swift to create some amazing things!
- iOS 15.0 or above
- macOS 12.0 or above
- Xcode 14.0 or above
- macOS Sonoma 14.4.1 (23E224)
- Xcode 15.3 (15E204a)
- Swift 5.9.2 (5.9.2.2.56)
Currently only installation using Swift Package Manager is supported.
https://github.com/leoho0722/SwiftHelpers.git
import Foundation
import SwiftHelpers
func createURLRequest<E>(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
}
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)
// ...
}
}
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.
}
}
}
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
// ...
}
}