From 43855be06411fd2ba93ccfda8883e43d7af4b864 Mon Sep 17 00:00:00 2001 From: Sam Rayner Date: Mon, 4 Sep 2017 15:40:51 +0100 Subject: [PATCH] Add docs and make CatalogAssetManager public Closes #1 --- .gitignore | 4 ++-- ColorAssetCatalog.podspec | 2 +- .../Classes/ColorAssetManager.swift | 19 ++++++++++++++----- .../Classes/UIColor+ColorAssetCatalog.swift | 14 ++++++++++++++ Example/Podfile.lock | 4 ++-- .../ColorAssetCatalog.podspec.json | 8 ++++---- Example/Pods/Manifest.lock | 4 ++-- .../ColorAssetCatalog/Info.plist | 2 +- 8 files changed, 40 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index e7b722d..369f932 100644 --- a/.gitignore +++ b/.gitignore @@ -26,8 +26,8 @@ Carthage # We recommend against adding the Pods directory to your .gitignore. However # you should judge for yourself, the pros and cons are mentioned at: # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control -# +# # Note: if you ignore the Pods directory, make sure to uncomment # `pod install` in .travis.yml # -# Pods/ +Example/Pods/ diff --git a/ColorAssetCatalog.podspec b/ColorAssetCatalog.podspec index 76f94a1..3391fa9 100644 --- a/ColorAssetCatalog.podspec +++ b/ColorAssetCatalog.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'ColorAssetCatalog' - s.version = '0.3.0' + s.version = '0.4.0' s.summary = 'Adds iOS 9+ compatibility for named colors in asset catalogs.' # This description is used to generate tags and improve search results. diff --git a/ColorAssetCatalog/Classes/ColorAssetManager.swift b/ColorAssetCatalog/Classes/ColorAssetManager.swift index 9bd942c..9a81829 100644 --- a/ColorAssetCatalog/Classes/ColorAssetManager.swift +++ b/ColorAssetCatalog/Classes/ColorAssetManager.swift @@ -5,17 +5,26 @@ // Created by Sam Rayner on 12/06/2017. // -class ColorAssetManager { - static let shared = ColorAssetManager() - var catalogName = "Colors" - var cachingEnabled = true +///Provides access to and caching of colors in an asset catalog. +///For general use, use UIColor(asset:) rather than this class. +public class ColorAssetManager { + ///The singleton instance to change settings on. + public static let shared = ColorAssetManager() + + ///The name of the asset catalog to fetch colors from. + public var catalogName = "Colors" + + ///Whether to cache colors in memory as they are accessed. + public var cachingEnabled = true + var cgColors: [String: CGColor] = [:] private init() { NotificationCenter.default.addObserver(self, selector: #selector(clearCache), name: .UIApplicationDidReceiveMemoryWarning, object: nil) } - @objc func clearCache() { + ///Clear all used color objects from memory. + @objc public func clearCache() { cgColors.removeAll() } diff --git a/ColorAssetCatalog/Classes/UIColor+ColorAssetCatalog.swift b/ColorAssetCatalog/Classes/UIColor+ColorAssetCatalog.swift index f5a4b1e..14364a5 100644 --- a/ColorAssetCatalog/Classes/UIColor+ColorAssetCatalog.swift +++ b/ColorAssetCatalog/Classes/UIColor+ColorAssetCatalog.swift @@ -6,6 +6,20 @@ // public extension UIColor { + /** + Loads a color from an asset catalog. + On iOS 11 this aliases init(named:). + On iOS 9 or 10 this uses ColorAssetManager. + + You can configure the asset catalog to look for colors: + + ``` + ColorAssetManager.shared.catalogName = "MyColors" + ``` + + - Parameter name: The name of the color in the asset catalog. + - Returns: A UIColor or nil if a color is not found of that name. + */ public convenience init?(asset name: String) { if #available(iOS 11.0, *) { self.init(named: name) diff --git a/Example/Podfile.lock b/Example/Podfile.lock index d62408c..492af39 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - ColorAssetCatalog (0.3.0) + - ColorAssetCatalog (0.4.0) DEPENDENCIES: - ColorAssetCatalog (from `../`) @@ -9,7 +9,7 @@ EXTERNAL SOURCES: :path: "../" SPEC CHECKSUMS: - ColorAssetCatalog: 9c76c2cc967a38ee13dc05278edf86eedf82484f + ColorAssetCatalog: 1ba2a22174491585f217e4c8cb617221dd4ec8a2 PODFILE CHECKSUM: 89fa1c485c40cfe868239bf0487f00e30a7e49da diff --git a/Example/Pods/Local Podspecs/ColorAssetCatalog.podspec.json b/Example/Pods/Local Podspecs/ColorAssetCatalog.podspec.json index c15b024..f3fc0ee 100644 --- a/Example/Pods/Local Podspecs/ColorAssetCatalog.podspec.json +++ b/Example/Pods/Local Podspecs/ColorAssetCatalog.podspec.json @@ -1,9 +1,9 @@ { "name": "ColorAssetCatalog", - "version": "0.3.0", + "version": "0.4.0", "summary": "Adds iOS 9+ compatibility for named colors in asset catalogs.", "description": "This Pod adds iOS 9+ compatibility for named colors in asset catalogs. It extends UIColor with a new optional initializer: `UIColor(asset:)` that works in the same way as `UIColor(named:)`.", - "homepage": "https://github.com/Sam Rayner/ColorAssetCatalog", + "homepage": "https://github.com/samrayner/ColorAssetCatalog", "license": { "type": "MIT", "file": "LICENSE" @@ -12,8 +12,8 @@ "Sam Rayner": "sam@samrayner.com" }, "source": { - "git": "https://github.com/Sam Rayner/ColorAssetCatalog.git", - "tag": "0.3.0" + "git": "https://github.com/samrayner/ColorAssetCatalog.git", + "tag": "0.4.0" }, "social_media_url": "https://twitter.com/samrayner", "platforms": { diff --git a/Example/Pods/Manifest.lock b/Example/Pods/Manifest.lock index d62408c..492af39 100644 --- a/Example/Pods/Manifest.lock +++ b/Example/Pods/Manifest.lock @@ -1,5 +1,5 @@ PODS: - - ColorAssetCatalog (0.3.0) + - ColorAssetCatalog (0.4.0) DEPENDENCIES: - ColorAssetCatalog (from `../`) @@ -9,7 +9,7 @@ EXTERNAL SOURCES: :path: "../" SPEC CHECKSUMS: - ColorAssetCatalog: 9c76c2cc967a38ee13dc05278edf86eedf82484f + ColorAssetCatalog: 1ba2a22174491585f217e4c8cb617221dd4ec8a2 PODFILE CHECKSUM: 89fa1c485c40cfe868239bf0487f00e30a7e49da diff --git a/Example/Pods/Target Support Files/ColorAssetCatalog/Info.plist b/Example/Pods/Target Support Files/ColorAssetCatalog/Info.plist index f92230d..53e4061 100644 --- a/Example/Pods/Target Support Files/ColorAssetCatalog/Info.plist +++ b/Example/Pods/Target Support Files/ColorAssetCatalog/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.3.0 + 0.4.0 CFBundleSignature ???? CFBundleVersion