Skip to content

Commit

Permalink
October 10th lecture
Browse files Browse the repository at this point in the history
  • Loading branch information
kingst committed Oct 10, 2018
1 parent b63f051 commit 804d1ec
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
23 changes: 23 additions & 0 deletions playgrounds/extensions/UIImage+crop.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import UIKit

var str = "Hello, playground"

extension UIImage {
// add a crop function to UIImage
func crop(to: CGRect) -> UIImage? {
switch (self.cgImage, self.ciImage) {
// check if cgImage is some, ciImage is nil and unwrap self.cgImage, storing it in cgImage
case (.some(let cgImage), nil):
let image = cgImage.cropping(to: to)
return image.map { UIImage(cgImage: $0) }
case (nil, .some(let ciImage)):
return UIImage(ciImage: ciImage.cropped(to: to))
default:
print("I don't know why cgImage and ciImage are equal")
return nil
}
}
}

var image: UIImage = UIImage() // assume set elsewhere
let croppedImage = image.crop(to: CGRect(x: 0.0, y: 0.0, width: 25.0, height: 25.0))
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios' executeOnSourceChanges='false'>
<timeline fileName='timeline.xctimeline'/>
</playground>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

0 comments on commit 804d1ec

Please sign in to comment.