StanfordiOS8

1.参数名

Snip20200620_1

这个from后面还要有冒号

Snip20200620_2

2.static, type method以前的类class方法,现在叫类型type方法

3.can set constant property in init

4.designated initializer must set properties introduced in the calss then call immediate super’s designated initializer

5.failable init?

6.initilizer can inherit

7.AnyObject Casting use “as?” “as!”

8. +=[T]

9.splice(Array,atIndex:Int)

10.String

1
2
var s = "hello"
let index = advance(s.startIndex,2)

subString use advance,改了

1
2
3
4
5
let num = "56.25"
if let decimalRange = num.rangeOfString(".") {
let wholeNumberPart = num[num.startIndex.decimalRange.startIndex]
}
join(Array) -> String

11.Type conversion

1
2
3
4
5
6
7
8
let d:Double = 37.5
let x = Int(d)

let a = Array("abc") //a = ["a","b","c"]
let s = String(["a","b","c"]) // s = "abc"

let s = String(52)
let s = "\(37.5)"

12.Assertions

1
2
assert(() -> Bool, "message")
assert(validation() != nil, "the validation function returned nil")

13.Objective-C Compatability

NSString is bridged to String

NSArray -> Array

NSDictionary -> Dictionary

NSNumber -> Int Float Double

1
let length = (aSring as NSString).length //Casting use "as"

14.Property List

1
2
//collection of 
NSString,NSArray,NSDictionary,NSNumber,NSData,NSDate

15.NSUserDefaults

1
let defaults = UserDefaults.standard

16.View

1
2
init(frame:CGRect) // added via code
init(coder:NSCoder) // added via storyboard

17.Coordinate System Data Stucture

CGFloat

CGSize

CGPoint

CGRect

Origin is upper left

Units are Points, two pixel per point

1
var contentScaleFator: CGFloat	// how many pixels in a point

center

frame

18.Creating Views

1.storyboard drag and set class to my subclass

2.by code

1
let view = UIView(frame:myFrame)

19.Custom Views

1.To draw:

a.create a subclass of UIView

b.override func drawRect(regionThatNeedsToBeRedrawn:CGRect)

c. Call setNeedsDisplay() or setNeedsDispalyInRect(regionThatNeedsToBeRedrawn:CGRect)

d. DO NOT call drawRect, NEVER call it

2.implement drawRect

a.Core Graphic

b.UIBezierPath

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
let path = UIBezierPath()

// 定义路线
path.move(to: CGPoint(x: 80,y: 50))
path.addLine(to: CGPoint(x: 140,y: 150))
path.addLine(to: CGPoint(x: 10,y: 150))
path.close()

// 设置颜色和宽
UIColor.green.setFill()
UIColor.red.setStroke()
path.lineWidth = 3.0

// 实际画
path.stroke()
path.fill()

3.draw common shapes

1
2
3
let aCGFloat:CGFloat = 5.0
let roundRect = UIBezierPath(roundedRect:myFrame,cornerRadius:aCGFloat)
let oval = UIBezierPath(ovalIn:myFrame)

4.Clip

1
addClip()

5.Hit detection

1
func containsPoint(CGPoint:point) -> Bool

19.UIColor

1
2
3
4
let transparentYellow = UIColor.yellow().colorWithAlphaComponet(0.5)
var opaque = false
var alpha: CGFloat
var hidden: Bool

20.Drawing Text

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// 20 Drawing Text -> AttributedString
let text = NSAttributedString(string: "Hello")
text.draw(at: point1)
let textSize: CGSize = text.size()

let mutableText = NSMutableAttributedString(string: "mutable string")
// let is enough

//Fonts
//class func preferredFontForTextStyle(UIFont.TextStyle) -> UIFont
UIFont.TextStyle.headline
UIFont.TextStyle.body
UIFont.TextStyle.footnote

let sysFont = UIFont.systemFont(ofSize: 10.0)
let sysBoldFont = UIFont.boldSystemFont(ofSize: 10.0)

21.draw images

1
2
3
4
5
6
7
8
9
10
11
12
13
// 21.drawing Images
let image: UIImage? = UIImage(named: "foo")

let image1: UIImage? = UIImage(contentsOfFile: "foo")
let image2: UIImage? = UIImage(data: NSData() as Data)
// drawing image
image?.draw(at: point1)
image1?.draw(in: myFrame)
image2?.drawAsPattern(in: myFrame)
// redraw on bounds change
// default scaleToFill
//var contentMode:UIViewContentMode
// redraw

22.Happiness

1.@IBDesignable show in storyboard

2.@IBInspectable can set in storyboard

23.Extensions

1.Only ADD new method

24.Protocol

1
2
setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key faceView.'
// 默认创建的ViewControllerView没法换绑,删了再建好了

1.定义协议

Snip20200621_1

2.添加实现协议的属性

Snip20200621_2

3.使用数据源协议属性

Snip20200621_3

4.宣布遵守协议

Snip20200621_4

5.实现协议

Snip20200621_5

6.设置数据源协议对象

Snip20200621_6

7.刷新显示

Snip20200621_7

25.Gesture

1
2
3
4
5
6
var scale: CGFloat = 0.9 {
didSet {
self.setNeedsLayout() //没调用draw(_ rect:)
}

}

26.MultiMVC TabBar Navi Split

27.Phycologist

1.auto shrink font size not working

2.bug unkown class in Interface Builder,设置模块好了

Snip20200622_1

28.View Controller Lifecycle

29.SrcollView

30.Cassini

31.Closure

32.MultiThread

33.UITextView

34.Tableview

1.高度自动计算

Snip20200623_1

35.final project

36.unwind segue

37.Alert and Action sheet

38.NSTimer

39.View Animation

40.DynamicAnimation

41.Dropit Demo

Snip20200624_1

42.Lesson13.NSNotification