This library is mean to be a general grab bag of Swift methods made by the engineers at IntrepidPursuits. As this library goes, useful components will be isolated into separate podspecs where appropriate.
The reason for the grab bag approach is to make it easier to facilitate the adding of materials and encourage componentization and sharing of common functionality.
pod 'Intrepid'
pod 'Intrepid/Rx' # Intrepid's RxSwift Extensions
source 'https://github.com/IntrepidPursuits/intrepid-wisdom.git'
target 'SwiftWisdomTests',
use_frameworks!
pod 'IntrepidSwiftWisdomTesting'
end
A basic wrapper for dispatch operations in Swift. Syntax example:
Qu.Background {
// Sleep for long operation
sleep(4)
log("1")
} .Also {
sleep(4)
log("2")
} .Also {
sleep(1)
log("3")
} .Also {
sleep(1)
log("4")
} .Also {
sleep(1)
log("5")
} .ThenAfter(.Previous(3)) {
log("6: After 5, 4, & 3")
} .Then {
sleep(1)
log("7: After 6")
} .FinallyOn(.Main) {
sleep(1)
log("Finished: After All")
}
A simple way to perform or repeat future operations:
After(2.5) {
print("Two and a half seconds later")
}
RepeatAtInterval(1.0, numberOfTimes: 5) {
print("Once a second, 5 times")
}
Load views from nibs:
let myCustomView = MyCustomView.fromNib()
Setup Easy Color Schemes. Note, if you're using Zeplin that it auto generates color schemes if you'd like
enum ColorPalette : ColorDescriptor {
case White = "254,216,130,255"
case DarkGreen = "51,58,24,255"
case DarkGray = "64,48,56,255"
case BrightWhite = "#ffffff"
var color: UIColor {
return rawValue.color
}
}
And use:
someView.backgroundColor = ColorPalette.White.color
A simple way to cover most table view registering / dequeing
tableView.ip_registerCell(YourCell.self)
tableView.ip_registerHeader(YourHeader.self)
let cell: YourCell = tableView.ip_dequeueCell(indexPath)
//
let header: YourHeader = tableView.ip_dequeueHeader(section)
A way to read and write from defaults simply and type-safe
enum Setting : String, EnumSettingsKeyAccessible {
case DisplayName
case LastOpenDate
}
let displayName: String? = Setting.DisplayName.readFromDefaults
Setting.DisplayName.writeToDefaults(displayName)
struct ApplicationSettings {
var displayName: String {
get {
return Setting.DisplayName.readFromDefaults ?? ""
}
set {
Setting.DisplayName.writeToDefaults(newValue)
}
}
}
As opposed to using objective-c style async completion blocks like (possibleObject: AnyObject?, error: NSError?)
, Result types are preferable:
func fetchName(completion: Result<String> -> Void)
And use:
fetchName { result in
switch result {
case let .Success(name):
print("Successfully got name: \(name)")
case let .Failure(error):
print("Failed to get name: \(error)")
}
}
Used to convert times of day back and forth from NSDate
To Time
let date = ...
let timeOfDay = TimeOfDay(date)
// or
let timeOfDay = TimeOfDay("1:30")
To Date:
let timeOfDay = ...
// Time Today
let todayAtThatTime = timeOfDay.timeToday()
// Time on given date
let someDate = ...
let timeOnThatDate = timeOfDay.timeOnDate(someDate)
All contributions and updates are welcome! Here's some basic guidelines when submitting an addition:
- Submit via a Pull Request documenting the addition
- Follow appropriate folder conventions
- Prefix all extension methods and variables with
ip_
to avoid namespacing. Swift namespacing doesn't apply the same way to extensions and prefixes help avoid issues. - Document functionality if it is ambiguous
- Bump podspec and tag on branch before merging
- On approval, push the podspec to trunk using
pod trunk push Intrepid.podspec
.