一些实操面试题

"持续学习"

Posted by littleplayer on November 25, 2020

前行的路一定是修行的路,停留在远离,不会有人施舍你,大家都在负重前行,除非你自己有矿,有资本。

start

1. xib
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
xib中一个CustomView中用自定义类的table-> MMTable, CustomView.m中
override func awakeFromNib() {
   super.awakeFromNib()
   table.backgrundColor = .white
}

MMTable.swift
override func awakeFromNib() {
   super.awakeFromNib()
   self.backgrundColor = .gray
}

let customView = Bundle.main.load....
customView.frame = self.frame
self.view.addSubview(customView)

customView.table.backgrundColor = ?
  1. UIView 加载顺序
  2. UIViewController加载顺序
  3. Appelegate加载顺序

  4. 模型解析了解吗? 请说说你用过的模型解析库?有手动写过吗? 请问swift如何做模型解析呢? 下面的json解析成 user - cat - book结构
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
user
{
	"nm": "mm",
	"age": 16,
	"cat": {
		"nm": "small cat",
		"color": "white"
	},
	"books": [
		{
			"nm": "book1",
			"price": 10.0,
		},
		{
			"nm": "book2",
			"price": 92.0,
		},
	]
}

1
为何不用struct呢? 为何要使用class
  1. properties ```swift struct ShopItem { var eggs: Int let price: Int }

let shop = ShopItem(eggs: 10, price: 4) shop.eggs = 5

class CshopItem { var eggs: Int let price: Int init(_ e: Int, p: Int) { eggs = e price = p } } let cshop = CshopItem(10, p: 4) cshop.eggs = 5

eggs各为多少呢? 或者有其他解释呢?

1

This behavior is due to structures being value types. When an instance of a value type is marked as a constant, so are all of its properties.

The same isn’t true for classes, which are reference types. If you assign an instance of a reference type to a constant, you can still change that instance’s variable properties.

1
2
3
4
5
6
7
8
9
10
7. ??
```swift

var a: String?

let moreThan5 = a?.count ?? 0 > 5

?? 与 > 号的优先级是?

  1. swift 合并两个数组为元组(a,b) ```swift zip(A, B)