Skip to content

Latest commit

 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

SwiftHelper

Convenience classes wrapped with Swift features and useful Swift extensions

AttributedStringBuilder

AttributedString Builder encapsulated using the Swift resultBuilder feature

Screenshot 2023-06-03 at 21 38 06

Before:

let build1 = NSMutableAttributedString()
let start = NSAttributedString(string: "Hello", attributes: [
    NSAttributedString.Key.foregroundColor: UIColor.red
])
build1.append(start)
build1.append(NSAttributedString(string: " "))
let end = NSAttributedString(string: "World", attributes: [
    NSAttributedString.Key.foregroundColor: UIColor.yellow,
    NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 18)
])
build1.append(end)

Now:

let build = NSAttributedString {
    Text("Hello").color(.red)
    SpecialCharacters.space
    Text("World").color(.yellow).font(.boldSystemFont(ofSize: 18))
}

Building Alert using DSL

 let alertController = ActionSheet(title: "", message: nil) {
            Action.default("Share") {  }
            Action.default("Download") { }
            Action.cancel("Cancel") {  }
        }
 present(alertController, animated: true, completion: nil)
 

UserDefaults

extension UserDefaults {
    @UserDefault(key: "username", defaultValue: "Antoine van der Lee")
    static var username: String
}

let subscription = UserDefaults.$username.sink { username in
    print("New username: \(username)")
}
UserDefaults.username = "Test"

About

Convenience classes wrapped with Swift features and useful Swift extensions

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages