Skip to content

Commit

Permalink
Merge pull request #162 from Rightpoint/bugfix/tinting-crash
Browse files Browse the repository at this point in the history
Guard against crashes when there are issues getting graphics context
  • Loading branch information
minimusic authored Apr 19, 2019
2 parents 8117c56 + 0d1d868 commit 21b4cb1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions Pod/Classes/ImageHelpers/UIImage+Tinting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public extension UIImage {
let originalAlignmentRectInsets = alignmentRectInsets

UIGraphicsBeginImageContextWithOptions(size, false, scale)
let context = UIGraphicsGetCurrentContext()!
guard let context = UIGraphicsGetCurrentContext() else {
return self
}

// Flip the context vertically
context.translateBy(x: 0.0, y: size.height)
Expand All @@ -45,7 +47,9 @@ public extension UIImage {
context.fill(imageRect)

// Get new image
var image = UIGraphicsGetImageFromCurrentImageContext()!
guard var image = UIGraphicsGetImageFromCurrentImageContext() else {
return self
}
UIGraphicsEndImageContext()

// Prevent further tinting
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


[![Swift 4.2](https://img.shields.io/badge/Swift-4.2-orange.svg?style=flat)](https://swift.org)
[![CircleCI](https://img.shields.io/circleci/project/github/Raizlabs/Swiftilities.svg)](https://circleci.com/gh/Raizlabs/Swiftilities/tree/develop)
[![CircleCI](https://img.shields.io/circleci/project/github/Rightpoint/Swiftilities.svg)](https://circleci.com/gh/Rightpoint/Swiftilities/tree/master)
[![Version](https://img.shields.io/cocoapods/v/Swiftilities.svg?style=flat)](https://cocoapods.org/pods/Swiftilities)
[![License](https://img.shields.io/cocoapods/l/Swiftilities.svg?style=flat)](https://cocoapods.org/pods/Swiftilities)
[![Platform](https://img.shields.io/cocoapods/p/Swiftilities.svg?style=flat)](https://cocoapods.org/pods/Swiftilities)
Expand Down
2 changes: 1 addition & 1 deletion Swiftilities.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Swiftilities"
s.version = "0.22.0"
s.version = "0.22.1"
s.summary = "A collection of useful Swift utilities."
s.swift_version = '4.2'

Expand Down

0 comments on commit 21b4cb1

Please sign in to comment.