版本记录
版本号 | 时间 |
---|---|
V1.0 | 2020.11.12 星期四 |
前言
Continuous Integration (CI)
可以让你的开发流程更加的迅速,并具有持续性,下面我们就一起学习下如何使用Xcode Server
。感兴趣的可以看下面几篇文章。
1. Xcode Server简单介绍(一) —— Xcode Server的安装和配置(一)
源码
1. Swift
首先看下工程组织结构
下面就是源码啦
1. SceneDelegate.swift
import SwiftUI
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: ContentView())
self.window = window
window.makeKeyAndVisible()
}
}
}
2. ContentView.swift
import SwiftUI
struct FruitRow: View {
let fruit: Fruit
var body: some View {
Text(fruit.name)
}
}
struct ContentView: View {
@ObservedObject var viewModel = FruitListViewModel()
var body: some View {
NavigationView {
List(viewModel.fruits) { fruit in
FruitRow(fruit: fruit)
}
.onAppear {
viewModel.loadFruits()
}
.navigationBarTitle("Fruits")
}.navigationViewStyle(StackNavigationViewStyle())
}
}
#if DEBUG
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif
3. Fruit.swift
import Foundation
struct Fruit: Identifiable, Decodable {
let name: String
let id = UUID()
private enum CodingKeys: String, CodingKey {
case name
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
name = try container.decode(String.self, forKey: .name)
}
}
4. FruitListViewModel.swift
import Foundation
class FruitListViewModel: ObservableObject {
@Published private(set) var fruits: [Fruit] = []
func loadFruits() {
fruits = loadJson(filename: "mock")
}
private func loadJson(filename fileName: String) -> [Fruit] {
if let url = Bundle.main.url(forResource: fileName, withExtension: "json") {
do {
let data = try Data(contentsOf: url)
let decoder = JSONDecoder()
let jsonData = try decoder.decode([Fruit].self, from: data)
return jsonData
} catch {
print("Error getting JSON:\(error)")
}
}
return []
}
}
后记
本篇主要讲述了
Xcode Server
的安装和配置,感兴趣的给个赞或者关注~~~