ThemeDictionaryPicker.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // ThemeDictionaryPicker.swift
  3. // SwiftTheme
  4. //
  5. // Created by Gesen on 2017/1/28.
  6. // Copyright © 2017年 Gesen. All rights reserved.
  7. //
  8. import Foundation
  9. @objc public final class ThemeDictionaryPicker: ThemePicker {
  10. public convenience init<T>(keyPath: String, map: @escaping (Any?) -> [T: AnyObject]?) {
  11. self.init(v: { map(O2ThemeManager.value(for: keyPath)) })
  12. }
  13. public convenience init<T>(dicts: [T: AnyObject]...) {
  14. self.init(v: { O2ThemeManager.element(for: dicts) })
  15. }
  16. public required convenience init(arrayLiteral elements: [String: AnyObject]...) {
  17. self.init(v: { O2ThemeManager.element(for: elements) })
  18. }
  19. }
  20. @objc public extension ThemeDictionaryPicker {
  21. class func pickerWithKeyPath(_ keyPath: String, map: @escaping (Any?) -> [String: AnyObject]?) -> ThemeDictionaryPicker {
  22. return ThemeDictionaryPicker(v: { map(O2ThemeManager.value(for: keyPath)) })
  23. }
  24. class func pickerWithKeyPath(_ keyPath: String, mapAttributes: @escaping (Any?) -> [NSAttributedString.Key: AnyObject]?) -> ThemeDictionaryPicker {
  25. return ThemeDictionaryPicker(v: { mapAttributes(O2ThemeManager.value(for: keyPath)) })
  26. }
  27. class func pickerWithDicts(_ dicts: [[String: AnyObject]]) -> ThemeDictionaryPicker {
  28. return ThemeDictionaryPicker(v: { O2ThemeManager.element(for: dicts) })
  29. }
  30. class func pickerWithAttributes(_ attributes: [[NSAttributedString.Key: AnyObject]]) -> ThemeDictionaryPicker {
  31. return ThemeDictionaryPicker(v: { O2ThemeManager.element(for: attributes) })
  32. }
  33. }
  34. extension ThemeDictionaryPicker: ExpressibleByArrayLiteral {}