Latest 0.3.1
Homepage https://github.com/TintPoint/Resource
License MIT
Platforms ios 10.0
Frameworks UIKit
Authors

Build Status
Carthage Compatible
CocoaPods Compatible

Resource helps you to manage your project resources.

Note: Resource is still under development and many things are subject to change.

Features

Requirements

iOS 10+ / Xcode 9+ / Swift 4+

Installation

Carthage

Carthage is a decentralized dependency manager. To install Resource, add the following line to your Cartfile:

github "TintPoint/Resource" ~> 0.3

CocoaPods

CocoaPods is a centralized dependency manager. To install Resource, add the following line to your Podfile:

pod 'Resource', '~> 0.3'

Getting Started

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)

Generic Methods for View Controllers

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

Reference

Available Protocols

  • AlertActionDescribing
  • AlertControllerDescribing
  • LocalizedStringDescribing
  • LocalizedUserNotificationStringDescribing
  • StoryboardDescribing
  • StringDescribing
  • ViewControllerDescribing

Available Structs

  • AlertActionDescription
  • AlertControllerDescription
  • LocalizedStringDescription
  • LocalizedUserNotificationStringDescription
  • StoryboardDescription
  • StringDescription
  • ViewControllerDescription

Latest podspec

{
    "name": "Resource",
    "version": "0.3.1",
    "summary": "Resource helps you to manage your project resources.",
    "homepage": "https://github.com/TintPoint/Resource",
    "authors": {
        "Justin Jia": "[email protected]"
    },
    "license": "MIT",
    "platforms": {
        "ios": "10.0"
    },
    "source": {
        "git": "https://github.com/TintPoint/Resource.git",
        "tag": "0.3.1"
    },
    "source_files": "Sources/**/*.swift",
    "frameworks": "UIKit"
}

Pin It on Pinterest

Share This