diff --git a/LeadKit.podspec b/LeadKit.podspec index b6fc1ebe..d5a31e84 100644 --- a/LeadKit.podspec +++ b/LeadKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "LeadKit" - s.version = "0.3.1" + s.version = "0.3.2" s.summary = "iOS framework with a bunch of tools for rapid development" s.homepage = "https://github.com/TouchInstinct/LeadKit" s.license = "Apache License, Version 2.0" diff --git a/LeadKit/LeadKit/Extensions/CGContext/CGContext+Initializers.swift b/LeadKit/LeadKit/Extensions/CGContext/CGContext+Initializers.swift index dce4dcce..4f2c7cb4 100644 --- a/LeadKit/LeadKit/Extensions/CGContext/CGContext+Initializers.swift +++ b/LeadKit/LeadKit/Extensions/CGContext/CGContext+Initializers.swift @@ -25,22 +25,23 @@ import CoreGraphics public extension CGContext { /** - creates an instance of CGContext with parameters taken from a given image + method which creates an instance of CGContext with parameters taken from a given image - parameter forCGImage: CGImage instance from which the parameters will be taken - parameter fallbackColorSpace: fallback color space if image doesn't have it */ - public convenience init?(forCGImage cgImage: CGImage, - fallbackColorSpace: CGColorSpace = CGColorSpaceCreateDeviceRGB()) { - self.init(width: cgImage.width, - height: cgImage.height, - bitmapInfo: cgImage.bitmapInfo, - colorSpace: cgImage.colorSpace ?? fallbackColorSpace, - bitsPerComponent: cgImage.bitsPerComponent) + public static func create(forCGImage cgImage: CGImage, + fallbackColorSpace: CGColorSpace = CGColorSpaceCreateDeviceRGB()) -> CGContext? { + + return create(width: cgImage.width, + height: cgImage.height, + bitmapInfo: cgImage.bitmapInfo, + colorSpace: cgImage.colorSpace ?? fallbackColorSpace, + bitsPerComponent: cgImage.bitsPerComponent) } /** - creates an instance of CGContext + method which creates an instance of CGContext - parameter width: The width, in pixels, of the required bitmap. - parameter height: The height, in pixels, of the required bitmap. @@ -50,18 +51,19 @@ public extension CGContext { - parameter colorSpace: The color space to use for the bitmap context. - parameter bitsPerComponent: The number of bits to use for each component of a pixel in memory. */ - public convenience init?(width: Int, - height: Int, - bitmapInfo: CGBitmapInfo = alphaBitmapInfo, - colorSpace: CGColorSpace = CGColorSpaceCreateDeviceRGB(), - bitsPerComponent: Int = 8) { - self.init(data: nil, - width: width, - height: height, - bitsPerComponent: bitsPerComponent, - bytesPerRow: 0, - space: colorSpace, - bitmapInfo: bitmapInfo.rawValue) - } + public static func create(width: Int, + height: Int, + bitmapInfo: CGBitmapInfo = alphaBitmapInfo, + colorSpace: CGColorSpace = CGColorSpaceCreateDeviceRGB(), + bitsPerComponent: Int = 8) -> CGContext? { + return CGContext(data: nil, + width: width, + height: height, + bitsPerComponent: bitsPerComponent, + bytesPerRow: 0, + space: colorSpace, + bitmapInfo: bitmapInfo.rawValue) + } + } diff --git a/LeadKit/LeadKit/Extensions/CGImage/CGImage+Alpha.swift b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Alpha.swift index 658d8bc7..a72a6e7b 100644 --- a/LeadKit/LeadKit/Extensions/CGImage/CGImage+Alpha.swift +++ b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Alpha.swift @@ -44,7 +44,7 @@ public extension CGImage { return self } - let ctx = CGContext(width: width, height: height, bitmapInfo: alphaBitmapInfo) + let ctx = CGContext.create(width: width, height: height, bitmapInfo: alphaBitmapInfo) ctx?.draw(self, in: bounds) return ctx?.makeImage() diff --git a/LeadKit/LeadKit/Extensions/CGImage/CGImage+Creation.swift b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Creation.swift index 19c74096..1df358b1 100644 --- a/LeadKit/LeadKit/Extensions/CGImage/CGImage+Creation.swift +++ b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Creation.swift @@ -39,9 +39,9 @@ public extension CGImage { height: Int, opaque: Bool = false) -> CGImage? { - let context = CGContext(width: width, - height: height, - bitmapInfo: opaque ? opaqueBitmapInfo : alphaBitmapInfo) + let context = CGContext.create(width: width, + height: height, + bitmapInfo: opaque ? opaqueBitmapInfo : alphaBitmapInfo) guard let ctx = context else { return nil @@ -66,7 +66,7 @@ public extension CGImage { let ctxWidth = Int(ceil(size.width)) let ctxHeight = Int(ceil(size.height)) - guard let ctx = CGContext(width: ctxWidth, height: ctxHeight) else { + guard let ctx = CGContext.create(width: ctxWidth, height: ctxHeight) else { return nil } diff --git a/LeadKit/LeadKit/Extensions/CGImage/CGImage+Template.swift b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Template.swift index 5679f1f5..6af76bf0 100644 --- a/LeadKit/LeadKit/Extensions/CGImage/CGImage+Template.swift +++ b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Template.swift @@ -32,7 +32,7 @@ public extension CGImage { - returns: new CGImage rendered with given color or nil if something goes wrong */ public func renderTemplate(withColor color: CGColor) -> CGImage? { - guard let ctx = CGContext(forCGImage: self) ?? CGContext(width: width, height: height) else { + guard let ctx = CGContext.create(forCGImage: self) ?? CGContext.create(width: width, height: height) else { return nil } diff --git a/LeadKit/LeadKit/Extensions/CGImage/CGImage+Transform.swift b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Transform.swift index 488aa7b0..929a0d94 100644 --- a/LeadKit/LeadKit/Extensions/CGImage/CGImage+Transform.swift +++ b/LeadKit/LeadKit/Extensions/CGImage/CGImage+Transform.swift @@ -32,7 +32,7 @@ public extension CGImage { - returns: A new image */ public func round(withRadius radius: CGFloat) -> CGImage? { - guard let ctx = CGContext(forCGImage: self) ?? CGContext(width: width, height: height) else { + guard let ctx = CGContext.create(forCGImage: self) ?? CGContext.create(width: width, height: height) else { return nil } @@ -68,13 +68,13 @@ public extension CGImage { let ctxRect: CGRect = CGRect(origin: CGPoint.zero, size: CGSize(width: newWidth, height: newHeight)) - let context = CGContext(width: ctxWidth, - height: ctxHeight, - bitmapInfo: bitmapInfo, - colorSpace: colorSpace ?? CGColorSpaceCreateDeviceRGB(), - bitsPerComponent: bitsPerComponent) + let context = CGContext.create(width: ctxWidth, + height: ctxHeight, + bitmapInfo: bitmapInfo, + colorSpace: colorSpace ?? CGColorSpaceCreateDeviceRGB(), + bitsPerComponent: bitsPerComponent) - guard let ctx = context ?? CGContext(width: width, height: height) else { + guard let ctx = context ?? CGContext.create(width: width, height: height) else { return nil } @@ -110,13 +110,13 @@ public extension CGImage { let ctxWidth = Int(ceil(newSize.width)) let ctxHeight = Int(ceil(newSize.height)) - let context = CGContext(width: ctxWidth, - height: ctxHeight, - bitmapInfo: bitmapInfo, - colorSpace: colorSpace ?? CGColorSpaceCreateDeviceRGB(), - bitsPerComponent: bitsPerComponent) + let context = CGContext.create(width: ctxWidth, + height: ctxHeight, + bitmapInfo: bitmapInfo, + colorSpace: colorSpace ?? CGColorSpaceCreateDeviceRGB(), + bitsPerComponent: bitsPerComponent) - guard let ctx = context ?? CGContext(width: ctxWidth, height: ctxHeight) else { + guard let ctx = context ?? CGContext.create(width: ctxWidth, height: ctxHeight) else { return nil } @@ -176,13 +176,13 @@ public extension CGImage { let ctxWidth = Int(ceil(CGFloat(width) + padding * 2)) let ctxHeight = Int(ceil(CGFloat(height) + padding * 2)) - let context = CGContext(width: ctxWidth, - height: ctxHeight, - bitmapInfo: bitmapInfo, - colorSpace: colorSpace ?? CGColorSpaceCreateDeviceRGB(), - bitsPerComponent: bitsPerComponent) + let context = CGContext.create(width: ctxWidth, + height: ctxHeight, + bitmapInfo: bitmapInfo, + colorSpace: colorSpace ?? CGColorSpaceCreateDeviceRGB(), + bitsPerComponent: bitsPerComponent) - guard let ctx = context ?? CGContext(width: ctxWidth, height: ctxHeight) else { + guard let ctx = context ?? CGContext.create(width: ctxWidth, height: ctxHeight) else { return nil } diff --git a/LeadKit/LeadKit/Extensions/UIDevice/UIDevice+Extensions.swift b/LeadKit/LeadKit/Extensions/UIDevice/UIDevice+Extensions.swift index 9f8ffe2d..36b2379e 100644 --- a/LeadKit/LeadKit/Extensions/UIDevice/UIDevice+Extensions.swift +++ b/LeadKit/LeadKit/Extensions/UIDevice/UIDevice+Extensions.swift @@ -22,10 +22,10 @@ import UIKit -extension UIDevice { +public extension UIDevice { /// Returns true if the current device is simulator - open static var isSimulator: Bool { + public static var isSimulator: Bool { return ProcessInfo.processInfo.environment["SIMULATOR_DEVICE_NAME"] != nil }