Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
704 changes: 704 additions & 0 deletions CountApp/CountApp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "90D5615E-7108-48BC-8096-B19D28D113E2"
type = "1"
version = "2.0">
</Bucket>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>CountApp.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
13 changes: 13 additions & 0 deletions CountApp/CountApp/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
6 changes: 6 additions & 0 deletions CountApp/CountApp/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
40 changes: 40 additions & 0 deletions CountApp/CountApp/CountAppApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// CountAppApp.swift
// CountApp
//
// Created by Leo on 1/13/24.
//

import SwiftUI
import ComposableArchitecture

@main
struct CountAppApp: App {
var body: some Scene {
WindowGroup {
ContentView(store: Store(initialState: Vitamins.State(vitamins: .mocks)) {
Vitamins()._printChanges()
})
}
}
}

struct ContentView: View {
let store: StoreOf<Vitamins>

var body: some View {
TabView {
VitaminsView(store: store) // store 하나로 다수 뷰 사용
.tabItem {
Image(systemName: "pills.fill")
Text("비타민")
}

StatisticsView(store: store)
.tabItem {
Image(systemName: "chart.bar.doc.horizontal")
Text("먹은 횟수")
}
}
}
}
14 changes: 14 additions & 0 deletions CountApp/CountApp/Extension/Numeric+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Numeric+Extension.swift
// CountApp
//
// Created by Leo on 1/14/24.
//

import Foundation

extension Numeric {
var toString: String {
String("\(self)")
}
}
33 changes: 33 additions & 0 deletions CountApp/CountApp/Extension/View+Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// View+Extension.swift
// CountApp
//
// Created by Leo on 1/14/24.
//

import SwiftUI

// MARK: ViewModifier
struct VitaminCell: ViewModifier {
let color: Color
let height: CGFloat

func body(content: Content) -> some View {
content
.frame(maxWidth: .infinity, maxHeight: height)
.contentShape(.contextMenuPreview, // contextmenu radius
RoundedRectangle(cornerRadius: 15))
.background(color)
.clipShape(RoundedRectangle(cornerRadius: 15))
.overlay {
RoundedRectangle(cornerRadius: 15)
.stroke(Color.gray.opacity(0.5), lineWidth: 0.5)
}
}
}

extension View {
func vitaminCellFrame(color: Color, height: CGFloat = 70) -> some View {
modifier(VitaminCell(color: color, height: height))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
42 changes: 42 additions & 0 deletions CountApp/CountApp/Vitamin/Reducer/Vitamin.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// Vitamin.swift
// CountApp
//
// Created by Leo on 1/13/24.
//

import SwiftUI
import ComposableArchitecture

@Reducer
struct Vitamin {

struct State: Equatable, Identifiable {
let id: UUID
let name: String
let color: Color
@BindingState var count: Int = 0
}

enum Action: BindableAction, Sendable {
case binding(BindingAction<State>)
case increaseCount(Int)
case decreaseToZero
}

var body: some Reducer<State, Action> {
BindingReducer()
Reduce { state, action in
switch action {
case .binding:
return .none
case .increaseCount(let count):
state.count += count
return .none
case .decreaseToZero:
state.count = 0
return .none
}
}
}
}
68 changes: 68 additions & 0 deletions CountApp/CountApp/Vitamin/Reducer/Vitamins.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// Vitamins.swift
// CountApp
//
// Created by Leo on 1/14/24.
//

import SwiftUI
import ComposableArchitecture

@Reducer
struct Vitamins {

struct State: Equatable {
var vitamins: IdentifiedArrayOf<Vitamin.State> = []
}

enum Action {
case vitamins(IdentifiedActionOf<Vitamin>)
case resetAllVitamins
case resetVitamins(name: String)
}

var body: some Reducer<State, Action> {
Reduce { state, action in
switch action {
case .vitamins:
return .none
case .resetAllVitamins:
state.vitamins.forEach {
var vitamin = $0
vitamin.count = 0
state.vitamins.updateOrAppend(vitamin)
}
return .none
case .resetVitamins(let name):
if var selectedVitamin = state.vitamins.first(where: { $0.name == name }) {
selectedVitamin.count = 0
state.vitamins.updateOrAppend(selectedVitamin)
}
return .none
}
}
.forEach(\.vitamins, action: \.vitamins) {
Vitamin()
}
}
}

extension IdentifiedArray where ID == Vitamin.State.ID, Element == Vitamin.State {
static let mocks: Self = [
Vitamin.State(id: UUID(),
name: "비타민 C",
color: Color.yellow.opacity(0.5)),
Vitamin.State(id: UUID(),
name: "비타민 D",
color: Color.red.opacity(0.5)),
Vitamin.State(id: UUID(),
name: "비타민 B",
color: Color.blue.opacity(0.5)),
Vitamin.State(id: UUID(),
name: "루테인",
color: Color.pink.opacity(0.5)),
Vitamin.State(id: UUID(),
name: "유산균",
color: Color.green.opacity(0.5)),
]
}
Loading