CRUD紀錄 — 食物紀錄app

蔡秉峻
海大 SwiftUI iOS / Flutter App 程式設計
4 min readNov 23, 2020

(一)模擬器 Gif

(二)Github連結

(三)App畫面截圖

(四)作品說明

常常去很多地方吃小吃,但總是不知道自己到底在什麼時間吃了什麼美食,有了這個app後就可以輕鬆查看自己過去的飲食紀錄,讓自己很清楚的知道過去到底去哪裡吃了什麼食物

(五)加分程式碼片段

  1. 使用onMove調整順序
List {    ForEach(countriesData.countries){ (country) in        NavigationLink(destination: CountryEditor(countriesData:
self.countriesData, editCountry: country)) {
CountryRow(country1: country) } } .onMove { (indexSet, index) in self.countriesData.countries.move(fromOffsets: indexSet, toOffset: index) } .onDelete{ (index) in self.countriesData.countries.remove(atOffsets: index) }}

2.使用 disabled

Form {}.navigationBarItems(trailing: Button("save"){let country = Country(country: self.country, selectedRegion: self.selectedRegion, score: Int(self.score), day: Int(self.day), favorite: self.favorite)if let editCountry = self.editCountry{    let index = self.countriesData.countries.firstIndex{        $0.id == editCountry.id    }!      // 因為必有值,所以用驚嘆號    self.countriesData.countries[index] = country} else{    self.countriesData.countries.insert(country, at: 0)}self.presentationMode.wrappedValue.dismiss()}.disabled(disableForm))

3. 柱狀圖的onAppear動畫

Capsule().frame(width: 30, height: 220)    .foregroundColor(Color(white: 0.805))VStack(spacing: 3) {    Text("\(Int(self.Width))")        .foregroundColor(.black)    Capsule()        .frame(width: 30, height: width*20)        .animation(.linear(duration: 1))        .onAppear{            self.width = CGFloat(self.Width)    }}

--

--