Resource helps you to manage your project resources.
Note: Resource is still under development and many things are subject to change.
- Protocol oriented design
- Comprehensive unit test coverage
- Complete documentation
iOS 10+ / Xcode 9+ / Swift 4+
Carthage is a decentralized dependency manager. To install Resource, add the following line to your Cartfile
:
github "TintPoint/Resource" ~> 0.3
CocoaPods is a centralized dependency manager. To install Resource, add the following line to your Podfile
:
pod 'Resource', '~> 0.3'
Define a custom enum that conforms to protocols with Describing
postfix (list of available protocols can be found here). For example, to manage alert controllers, write the following code.
enum Alert: AlertControllerDescribing {
case databaseError, networkError
var title: String {
switch self {
case .databaseError: return "Database Error"
case .networkError: return "Network Error"
}
}
var message: String {
switch self {
case .databaseError: return "Please try again."
case .networkError: return "Please check your network connection."
}
}
var actions: [UIAlertAction] {
return [UIAlertAction(title: "OK", style: .default)]
}
}
let alert = Resource.of(Alert.databaseError)
present(alert, animated: true)
Define a UIViewController
subclass that conforms to CustomViewController
protocol.
class AppController: UIViewController, CustomViewController {
static let representedBy: ViewControllerDescribing = ViewControllerDescription(name: "Main", storyboard: UIStoryboard(name: "Main", bundle: Bundle.main))
}
let controller = Resource.of(AppController.self)
print(type(of: controller)) // AppController
Type-safe dependency injection is also supported.
class AppController: UIViewController, DataReceivingController {
static let representedBy: ViewControllerDescribing = ViewControllerDescription(name: "Main", storyboard: UIStoryboard(name: "Main", bundle: Bundle.main))
var controllerData: (text: String, number: Int)?
}
let controller = Resource.of(AppController.self, passing: (text: "Text", number: 10))
print(controller.controllerData?.text) // "Text"
print(controller.controllerData?.number) // 10
- AlertActionDescribing
- AlertControllerDescribing
- LocalizedStringDescribing
- LocalizedUserNotificationStringDescribing
- StoryboardDescribing
- StringDescribing
- ViewControllerDescribing
- AlertActionDescription
- AlertControllerDescription
- LocalizedStringDescription
- LocalizedUserNotificationStringDescription
- StoryboardDescription
- StringDescription
- ViewControllerDescription