[Swift]クラス拡張

クラス拡張 objective-cにおけるカテゴリ

extension UIView {
    var left:CGFloat{
        get{
            return self.frame.origin.x
        }
        set{
            self.frame = CGRectMake(newValue, self.frame.origin.y, self.frame.size.width, self.frame.size.height)
        }
    }
    func toUIImage() -> UIImage{
        UIGraphicsBeginImageContextWithOptions(self.bounds.size, false, 0.0)
        self.layer.renderInContext(UIGraphicsGetCurrentContext())
        let image:UIImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return image
    }
}