This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIColor { | |
class func randomColor() -> UIColor { | |
let red = CGFloat(arc4random() % 256) / 256.0 | |
let green = CGFloat(arc4random() % 256) / 256.0 | |
let blue = CGFloat(arc4random() % 256) / 256.0 | |
let alpha = CGFloat(arc4random() % 256) / 256.0 | |
return UIColor(red: red, green: green, blue: blue, alpha: alpha) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension UIImage { | |
subscript (x: Int, y: Int) -> UIColor? { | |
guard x >= 0 && x < Int(size.width) && y >= 0 && y < Int(size.height), | |
let cgImage = cgImage, | |
let provider = cgImage.dataProvider, | |
let providerData = provider.data, | |
let data = CFDataGetBytePtr(providerData) else { | |
return nil |