Skip to content

Commit

Permalink
revised bk 2 chapters 1 thru 5 for Xcode 8 seed 6
Browse files Browse the repository at this point in the history
  • Loading branch information
mattneub committed Aug 20, 2016
1 parent 69fd0d9 commit b699532
Show file tree
Hide file tree
Showing 72 changed files with 196 additions and 195 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import UIKit

func delay(_ delay:Double, closure:()->()) {
func delay(_ delay:Double, closure:@escaping ()->()) {
let when = DispatchTime.now() + delay
DispatchQueue.main.asyncAfter(deadline: when, execute: closure)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import UIKit

func delay(_ delay:Double, closure:()->()) {
func delay(_ delay:Double, closure:@escaping ()->()) {
let when = DispatchTime.now() + delay
DispatchQueue.main.asyncAfter(deadline: when, execute: closure)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit

func delay(_ delay:Double, closure:()->()) {
func delay(_ delay:Double, closure:@escaping ()->()) {
let when = DispatchTime.now() + delay
DispatchQueue.main.asyncAfter(deadline: when, execute: closure)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11191" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11198.2" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11156"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion bk2ch02p052mars/ch15p406mars/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extension CGRect {
}
}

func delay(_ delay:Double, closure:()->()) {
func delay(_ delay:Double, closure:@escaping ()->()) {
let when = DispatchTime.now() + delay
DispatchQueue.main.asyncAfter(deadline: when, execute: closure)
}
Expand Down
10 changes: 5 additions & 5 deletions bk2ch02p059sixBlueCircles/ch15p411sixBlueCircles/Views.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit

func imageOfSize(_ size:CGSize, opaque:Bool = false, closure: @noescape () -> ()) -> UIImage {
func imageOfSize(_ size:CGSize, opaque:Bool = false, closure: () -> ()) -> UIImage {
if #available(iOS 10.0, *) {
let f = UIGraphicsImageRendererFormat.default()
f.opaque = opaque
Expand Down Expand Up @@ -48,7 +48,7 @@ class MyView1 : UIView {
class MyView2 : UIView {
override func draw(_ rect: CGRect) {
let con = UIGraphicsGetCurrentContext()!
con.addEllipse(inRect:CGRect(0,0,100,100))
con.addEllipse(in:CGRect(0,0,100,100))
con.setFillColor(UIColor.blue.cgColor)
con.fillPath()
}
Expand All @@ -66,7 +66,7 @@ class MyView3 : UIView {
class MyView4 : UIView {
override func draw(_ rect: CGRect) {}
override func draw(_ layer: CALayer, in con: CGContext) {
con.addEllipse(inRect:CGRect(0,0,100,100))
con.addEllipse(in:CGRect(0,0,100,100))
con.setFillColor(UIColor.blue.cgColor)
con.fillPath()
}
Expand Down Expand Up @@ -110,14 +110,14 @@ class MyImageView2 : UIImageView {
// let con = ctx.cgContext
// could say that, but the old way works still
let con = UIGraphicsGetCurrentContext()!
con.addEllipse(inRect:CGRect(0,0,100,100))
con.addEllipse(in:CGRect(0,0,100,100))
con.setFillColor(UIColor.blue.cgColor)
con.fillPath()
}
case 1: // just showing how to use my utility
self.image = imageOfSize(CGSize(100, 100)) {
let con = UIGraphicsGetCurrentContext()!
con.addEllipse(inRect:CGRect(0,0,100,100))
con.addEllipse(in:CGRect(0,0,100,100))
con.setFillColor(UIColor.blue.cgColor)
con.fillPath()
}
Expand Down
26 changes: 13 additions & 13 deletions bk2ch02p061imageDrawing/ch15p412imageDrawing/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ class ViewController : UIViewController {
let r = UIGraphicsImageRenderer(size:CGSize(sz.width*1.5, sz.height))
self.iv4.image = r.image { ctx in
let con = ctx.cgContext
con.draw(in:CGRect(0,0,sz.width/2.0,sz.height), image: marsLeft)
con.draw(in:
CGRect(sz.width,0,sz.width/2.0,sz.height), image:marsRight)
con.draw(marsLeft, in:CGRect(0,0,sz.width/2.0,sz.height))
con.draw(marsRight, in:
CGRect(sz.width,0,sz.width/2.0,sz.height))
}
// flipped!
}
Expand Down Expand Up @@ -149,10 +149,10 @@ class ViewController : UIViewController {
self.iv5.image = r.image {
ctx in
let con = ctx.cgContext
con.draw(in:
CGRect(0,0,sz.width/2.0,sz.height), image:flip(marsLeft!))
con.draw(in:
CGRect(sz.width,0,sz.width/2.0,sz.height), image:flip(marsRight!))
con.draw(flip(marsLeft!), in:
CGRect(0,0,sz.width/2.0,sz.height))
con.draw(flip(marsRight!), in:
CGRect(sz.width,0,sz.width/2.0,sz.height))
}
}

Expand Down Expand Up @@ -186,10 +186,10 @@ class ViewController : UIViewController {
self.iv6.image = r.image {
ctx in
let con = ctx.cgContext
con.draw(in:
CGRect(0,0,sz.width/2.0,sz.height), image:flip(marsLeft!))
con.draw(in:
CGRect(sz.width,0,sz.width/2.0,sz.height), image:flip(marsRight!))
con.draw(flip(marsLeft!), in:
CGRect(0,0,sz.width/2.0,sz.height))
con.draw(flip(marsRight!), in:
CGRect(sz.width,0,sz.width/2.0,sz.height))
}
}

Expand Down Expand Up @@ -246,7 +246,7 @@ func flip (_ im: CGImage) -> CGImage {

let r = UIGraphicsImageRenderer(size:sz)
return r.image { ctx in
ctx.cgContext.draw(in:
CGRect(0, 0, sz.width, sz.height), image:im)
ctx.cgContext.draw(im, in:
CGRect(0, 0, sz.width, sz.height))
}.cgImage!
}
88 changes: 44 additions & 44 deletions bk2ch02p077drawingInUIView/ch15p427drawingInUIView/MyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ class MyView : UIView {
let con = UIGraphicsGetCurrentContext()!

// draw a black (by default) vertical line, the shaft of the arrow
con.moveTo(x: 100, y: 100)
con.addLineTo(x: 100, y: 19)
con.move(to:CGPoint(x: 100, y: 100))
con.addLine(to:CGPoint(x: 100, y: 19))
con.setLineWidth(20)
con.strokePath()

// draw a red triangle, the point of the arrow
con.setFillColor(UIColor.red.cgColor)
con.moveTo(x:80, y: 25)
con.addLineTo(x:100, y: 0)
con.addLineTo(x:120, y: 25)
con.move(to:CGPoint(x:80, y: 25))
con.addLine(to:CGPoint(x:100, y: 0))
con.addLine(to:CGPoint(x:120, y: 25))
con.fillPath()

// snip a triangle out of the shaft by drawing in Clear blend mode
con.moveTo(x:90, y: 101)
con.addLineTo(x:100, y: 90)
con.addLineTo(x:110, y: 101)
con.move(to:CGPoint(x:90, y: 101))
con.addLine(to:CGPoint(x:100, y: 90))
con.addLine(to:CGPoint(x:110, y: 101))
con.setBlendMode(.clear)
con.fillPath()

Expand Down Expand Up @@ -89,24 +89,24 @@ class MyView : UIView {
let con = UIGraphicsGetCurrentContext()!

// punch triangular hole in context clipping region
con.moveTo(x: 90, y: 100)
con.addLineTo(x: 100, y: 90)
con.addLineTo(x: 110, y: 100)
con.move(to:CGPoint(x: 90, y: 100))
con.addLine(to:CGPoint(x: 100, y: 90))
con.addLine(to:CGPoint(x: 110, y: 100))
con.closePath()
con.addRect(con.boundingBoxOfClipPath)
con.eoClip()
con.clip(using:.evenOdd)

// draw the vertical line
con.moveTo(x: 100, y: 100)
con.addLineTo(x: 100, y: 19)
con.move(to:CGPoint(x: 100, y: 100))
con.addLine(to:CGPoint(x: 100, y: 19))
con.setLineWidth(20)
con.strokePath()

// draw the red triangle, the point of the arrow
con.setFillColor(UIColor.red.cgColor)
con.moveTo(x: 80, y: 25)
con.addLineTo(x: 100, y: 0)
con.addLineTo(x: 120, y: 25)
con.move(to:CGPoint(x:80, y: 25))
con.addLine(to:CGPoint(x:100, y: 0))
con.addLine(to:CGPoint(x:120, y: 25))
con.fillPath()

case 4:
Expand All @@ -115,16 +115,16 @@ class MyView : UIView {
con.saveGState()

// punch triangular hole in context clipping region
con.moveTo(x: 90, y: 100)
con.addLineTo(x: 100, y: 90)
con.addLineTo(x: 110, y: 100)
con.move(to:CGPoint(x: 90, y: 100))
con.addLine(to:CGPoint(x: 100, y: 90))
con.addLine(to:CGPoint(x: 110, y: 100))
con.closePath()
con.addRect(con.boundingBoxOfClipPath)
con.eoClip()
con.clip(using:.evenOdd)

// draw the vertical line, add its shape to the clipping region
con.moveTo(x: 100, y: 100)
con.addLineTo(x: 100, y: 19)
con.move(to:CGPoint(x: 100, y: 100))
con.addLine(to:CGPoint(x: 100, y: 19))
con.setLineWidth(20)
con.replacePathWithStrokedPath()
con.clip()
Expand All @@ -139,16 +139,16 @@ class MyView : UIView {
let sp = CGColorSpaceCreateDeviceGray()
// print(CGColorSpaceGetNumberOfComponents(sp))
let grad =
CGGradient(colorComponentsSpace:sp, components: colors, locations: locs, count: 3)!
CGGradient(colorSpace:sp, colorComponents: colors, locations: locs, count: 3)!
con.drawLinearGradient(grad, start: CGPoint(89,0), end: CGPoint(111,0), options:[])

con.restoreGState() // done clipping

// draw the red triangle, the point of the arrow
con.setFillColor(UIColor.red.cgColor)
con.moveTo(x: 80, y: 25)
con.addLineTo(x: 100, y: 0)
con.addLineTo(x: 120, y: 25)
con.move(to:CGPoint(x:80, y: 25))
con.addLine(to:CGPoint(x:100, y: 0))
con.addLine(to:CGPoint(x:120, y: 25))
con.fillPath()

case 5:
Expand All @@ -157,16 +157,16 @@ class MyView : UIView {
con.saveGState()

// punch triangular hole in context clipping region
con.moveTo(x: 90, y: 100)
con.addLineTo(x: 100, y: 90)
con.addLineTo(x: 110, y: 100)
con.move(to:CGPoint(x: 90, y: 100))
con.addLine(to:CGPoint(x: 100, y: 90))
con.addLine(to:CGPoint(x: 110, y: 100))
con.closePath()
con.addRect(con.boundingBoxOfClipPath)
con.eoClip()
con.clip(using:.evenOdd)

// draw the vertical line, add its shape to the clipping region
con.moveTo(x: 100, y: 100)
con.addLineTo(x: 100, y: 19)
con.move(to:CGPoint(x: 100, y: 100))
con.addLine(to:CGPoint(x: 100, y: 19))
con.setLineWidth(20)
con.replacePathWithStrokedPath()
con.clip()
Expand All @@ -180,7 +180,7 @@ class MyView : UIView {
]
let sp = CGColorSpaceCreateDeviceGray()
let grad =
CGGradient(colorComponentsSpace:sp, components: colors, locations: locs, count: 3)!
CGGradient(colorSpace:sp, colorComponents: colors, locations: locs, count: 3)!
con.drawLinearGradient(grad, start: CGPoint(89,0), end: CGPoint(111,0), options: [])

con.restoreGState() // done clipping
Expand Down Expand Up @@ -220,16 +220,16 @@ class MyView : UIView {
con.saveGState()

// punch triangular hole in context clipping region
con.moveTo(x: 90, y: 100)
con.addLineTo(x: 100, y: 90)
con.addLineTo(x: 110, y: 100)
con.move(to:CGPoint(x: 90, y: 100))
con.addLine(to:CGPoint(x: 100, y: 90))
con.addLine(to:CGPoint(x: 110, y: 100))
con.closePath()
con.addRect(con.boundingBoxOfClipPath)
con.eoClip()
con.clip(using:.evenOdd)

// draw the vertical line, add its shape to the clipping region
con.moveTo(x: 100, y: 100)
con.addLineTo(x: 100, y: 19)
con.move(to:CGPoint(x: 100, y: 100))
con.addLine(to:CGPoint(x: 100, y: 19))
con.setLineWidth(20)
con.replacePathWithStrokedPath()
con.clip()
Expand All @@ -243,7 +243,7 @@ class MyView : UIView {
]
let sp = CGColorSpaceCreateDeviceGray()
let grad =
CGGradient(colorComponentsSpace:sp, components: colors, locations: locs, count: 3)!
CGGradient(colorSpace:sp, colorComponents: colors, locations: locs, count: 3)!
con.drawLinearGradient (grad, start: CGPoint(89,0), end: CGPoint(111,0), options: [])

con.restoreGState() // done clipping
Expand Down Expand Up @@ -271,9 +271,9 @@ class MyView : UIView {
con.setFillPattern(patt, colorComponents: &alph)


con.moveTo(x: 80, y: 25)
con.addLineTo(x: 100, y: 0)
con.addLineTo(x: 120, y: 25)
con.move(to:CGPoint(x:80, y: 25))
con.addLine(to:CGPoint(x:100, y: 0))
con.addLine(to:CGPoint(x:120, y: 25))
con.fillPath()


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import UIKit

func delay(_ delay:Double, closure:()->()) {
func delay(_ delay:Double, closure:@escaping ()->()) {
let when = DispatchTime.now() + delay
DispatchQueue.main.asyncAfter(deadline: when, execute: closure)
}
Expand All @@ -27,7 +27,7 @@ class ViewController : UIViewController {
NSLayoutConstraint(item: mv, attribute: .centerY, relatedBy: .equal, toItem: mv.superview, attribute: .centerY, multiplier: 1, constant: 0)
)

// return; // comment out to experiment with resizing
return; // comment out to experiment with resizing

delay(0.1) {
mv.bounds.size.height *= 2
Expand Down
16 changes: 8 additions & 8 deletions bk2ch02p086drawingInUIView2/ch15p427drawingInUIView/MyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ class MyView : UIView {
con.saveGState()

// punch triangular hole in context clipping region
con.moveTo(x: 10, y: 100)
con.addLineTo(x: 20, y: 90)
con.addLineTo(x: 30, y: 100)
con.move(to: CGPoint(x: 10, y: 100))
con.addLine(to: CGPoint(x: 20, y: 90))
con.addLine(to: CGPoint(x: 30, y: 100))
con.closePath()
con.addRect(con.boundingBoxOfClipPath)
con.eoClip()
con.clip(using: .evenOdd)

// draw the vertical line, add its shape to the clipping region
con.moveTo(x: 20, y: 100)
con.addLineTo(x: 20, y: 19)
con.move(to: CGPoint(x: 20, y: 100))
con.addLine(to: CGPoint(x: 20, y: 19))
con.setLineWidth(20)
con.replacePathWithStrokedPath()
con.clip()
Expand All @@ -68,7 +68,7 @@ class MyView : UIView {
]
let sp = CGColorSpaceCreateDeviceGray()
let grad =
CGGradient(colorComponentsSpace:sp, components: colors, locations: locs, count: 3)!
CGGradient(colorSpace:sp, colorComponents: colors, locations: locs, count: 3)!
con.drawLinearGradient(grad, start: CGPoint(9,0), end: CGPoint(31,0), options: [])

con.restoreGState() // done clipping
Expand Down Expand Up @@ -99,7 +99,7 @@ class MyView : UIView {
//
}

let which = 2
let which = 3

override func draw(_ rect: CGRect) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit

func delay(_ delay:Double, closure:()->()) {
func delay(_ delay:Double, closure:@escaping ()->()) {
let when = DispatchTime.now() + delay
DispatchQueue.main.asyncAfter(deadline: when, execute: closure)
}
Expand Down
Loading

0 comments on commit b699532

Please sign in to comment.