A collection of useful Swift extensions, macros, and utilities to reduce boilerplate and improve productivity in your Swift projects.
- GenerateDTO Macro - Automatically generate Data Transfer Objects from your classes
- SkipEncode Property Wrapper - Skip encoding while still supporting decoding
- Foundation Extensions - Helpful extensions for
Date,Array,Double, and more - Concurrency Utilities - Task timeout helpers and sleep conveniences
- SwiftUI Extensions - Conditional view modifiers, content centering, and frame tracking
- Cross-Platform Device Metrics - Unified device dimension access across platforms
- iOS 12.0+ / macOS 10.15+ / watchOS 6.0+ / tvOS 13.0+ / visionOS 1.0+
- Swift 6.2+
Add Screws to your Package.swift dependencies:
dependencies: [
.package(url: "https://github.com/rafaelfrancisco-dev/Screws.git", from: "1.0.0")
]Or add it directly in Xcode:
- File → Add Packages...
- Enter the repository URL:
https://github.com/rafaelfrancisco-dev/Screws.git - Select the version you want to use
Automatically generate a Data Transfer Object (DTO) from your classes:
import Screws
@GenerateDTO(codable: true)
class User {
var name: String = ""
var age: Int = 0
var email: String = ""
}
// Usage
let user = User()
user.name = "John Doe"
user.age = 30
user.email = "john@example.com"
let dto = UserDTO(from: user)
let newUser = User()
dto.copyTo(newUser)The generated DTO:
- Mirrors all properties from the source class
- Is always
Sendablefor safe concurrency - Optionally conforms to
Codablefor serialization - Includes initialization from source class
- Provides method to copy data back to source
Skip encoding while still supporting decoding:
import Screws
struct Config: Codable {
var name: String
@SkipEncode var temporaryValue: String
}import Screws
let date = Date.dateFromDayAndMonth(day: 15, month: 3)
let dayInYear = date?.getDayInYear()
let month = date?.get(.month)
let months = Date.months()import Screws
let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
let chunks = numbers.chunked(into: 3)
// [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]
let diff = [1, 2, 3].difference(from: [2, 3, 4])
// [1, 4]import Screws
let pi = 3.14159
let formatted = pi.format(f: 2.0)
let rounded = pi.rounded(toPlaces: 2)import Screws
Task {
try await Task.sleep(seconds: 2.0)
}
let result = try await Task.withTimeout(duration: .seconds(5)) {
try await someAsyncOperation()
}import SwiftUI
import Screws
struct ContentView: View {
@State private var frameSize: CGSize = .zero
@State private var showDetails = false
var body: some View {
VStack {
Text("Hello")
.if(showDetails) { view in
view.background(Color.blue)
}
.centerContentsHorizontally()
}
.frameTracker(size: $frameSize)
}
}import Screws
let width = Convenience.deviceWidth
let height = Convenience.deviceHeightEach feature includes comprehensive inline documentation. Option-click any symbol in Xcode to see detailed usage information.
Contributions are welcome! Please feel free to submit a Pull Request.
Screws is available under the MIT license. See the LICENSE file for more info.
Rafael Francisco