From 4d23bec20d3d026efad44b97e24e2cefd40276bb Mon Sep 17 00:00:00 2001 From: mcrkgus Date: Fri, 17 May 2024 15:18:57 +0900 Subject: [PATCH 1/8] CalculatorButton --- .gitignore | 140 ++++++++++++++++++ .../AccentColor.colorset/Contents.json | 11 ++ .../AppIcon.appiconset/Contents.json | 13 ++ .../Assets.xcassets/Contents.json | 6 + .../SwiftUIStudy/CalculatorButton.swift | 57 +++++++ SwiftUIStudy/SwiftUIStudy/ContentView.swift | 24 +++ .../Preview Assets.xcassets/Contents.json | 6 + .../SwiftUIStudy/SwiftUIStudyApp.swift | 17 +++ 8 files changed, 274 insertions(+) create mode 100644 .gitignore create mode 100644 SwiftUIStudy/SwiftUIStudy/Assets.xcassets/AccentColor.colorset/Contents.json create mode 100644 SwiftUIStudy/SwiftUIStudy/Assets.xcassets/AppIcon.appiconset/Contents.json create mode 100644 SwiftUIStudy/SwiftUIStudy/Assets.xcassets/Contents.json create mode 100644 SwiftUIStudy/SwiftUIStudy/CalculatorButton.swift create mode 100644 SwiftUIStudy/SwiftUIStudy/ContentView.swift create mode 100644 SwiftUIStudy/SwiftUIStudy/Preview Content/Preview Assets.xcassets/Contents.json create mode 100644 SwiftUIStudy/SwiftUIStudy/SwiftUIStudyApp.swift diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0325cae --- /dev/null +++ b/.gitignore @@ -0,0 +1,140 @@ +# Created by https://www.toptal.com/developers/gitignore/api/xcode,swift,swiftpackagemanager,macos +# Edit at https://www.toptal.com/developers/gitignore?templates=xcode,swift,swiftpackagemanager,macos + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### Swift ### +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +*.xcscmblueprint +*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +build/ +DerivedData/ +*.moved-aside +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 + +## Obj-C/Swift specific +*.hmap + +## App packaging +*.ipa +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +playground.xcworkspace + +# Swift Package Manager +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +# Package.pins +# Package.resolved +# *.xcodeproj +# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata +# hence it is not needed unless you have added a package configuration file to your project +# .swiftpm + +.build/ + +# CocoaPods +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# Pods/ +# Add this line if you want to avoid checking in source code from the Xcode workspace +# *.xcworkspace + +# Carthage +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build/ + +# Accio dependency management +Dependencies/ +.accio/ + +# fastlane +# It is recommended to not store the screenshots in the git repo. +# Instead, use fastlane to re-generate the screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/#source-control + +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots/**/*.png +fastlane/test_output + +# Code Injection +# After new code Injection tools there's a generated folder /iOSInjectionProject +# https://github.com/johnno1962/injectionforxcode + +iOSInjectionProject/ + +### SwiftPackageManager ### +Packages +xcuserdata +*.xcodeproj + + +### Xcode ### + +## Xcode 8 and earlier + +### Xcode Patch ### +*.xcodeproj/* +!*.xcodeproj/project.pbxproj +!*.xcodeproj/xcshareddata/ +!*.xcodeproj/project.xcworkspace/ +!*.xcworkspace/contents.xcworkspacedata +/*.gcno +**/xcshareddata/WorkspaceSettings.xcsettings + +# End of https://www.toptal.com/developers/gitignore/api/xcode,swift,swiftpackagemanager,macos \ No newline at end of file diff --git a/SwiftUIStudy/SwiftUIStudy/Assets.xcassets/AccentColor.colorset/Contents.json b/SwiftUIStudy/SwiftUIStudy/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000..eb87897 --- /dev/null +++ b/SwiftUIStudy/SwiftUIStudy/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SwiftUIStudy/SwiftUIStudy/Assets.xcassets/AppIcon.appiconset/Contents.json b/SwiftUIStudy/SwiftUIStudy/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..13613e3 --- /dev/null +++ b/SwiftUIStudy/SwiftUIStudy/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,13 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SwiftUIStudy/SwiftUIStudy/Assets.xcassets/Contents.json b/SwiftUIStudy/SwiftUIStudy/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/SwiftUIStudy/SwiftUIStudy/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SwiftUIStudy/SwiftUIStudy/CalculatorButton.swift b/SwiftUIStudy/SwiftUIStudy/CalculatorButton.swift new file mode 100644 index 0000000..7e7f986 --- /dev/null +++ b/SwiftUIStudy/SwiftUIStudy/CalculatorButton.swift @@ -0,0 +1,57 @@ +// +// CalculatorButton.swift +// SwiftUIStudy +// +// Created by Gahyun Kim on 2024/05/17. +// + +import SwiftUI + +enum CalculatorButton: String { + // 숫자 + case one = "1" + case two = "2" + case three = "3" + case four = "4" + case five = "5" + case six = "6" + case seven = "7" + case eight = "8" + case nine = "9" + case zero = "0" + + // 연산자 + case subtract = "\u{2212}" + case add = "\u{002B}" + case divide = "\u{00F7}" + case multiply = "\u{00D7}" + case equal = "=" + case clear = "AC" + case decimal = "." + case percent = "%" + case negative = "\u{002B}/-" + + var buttonColor: Color { + switch self { + case .add, .subtract, .divide, .multiply, .equal: + return Color(.cyan) + case .clear, .negative, .percent: + return Color(.magenta) + default: + return Color(.systemPink) + } + } + + var foregroundColor: Color { + switch self { + case .clear, .negative, .percent: + return Color(.black) + default: + return Color(.white) + } + } +} + +enum Operation { + case add, subtract, divide, multiply, none +} diff --git a/SwiftUIStudy/SwiftUIStudy/ContentView.swift b/SwiftUIStudy/SwiftUIStudy/ContentView.swift new file mode 100644 index 0000000..9cfcdb3 --- /dev/null +++ b/SwiftUIStudy/SwiftUIStudy/ContentView.swift @@ -0,0 +1,24 @@ +// +// ContentView.swift +// SwiftUIStudy +// +// Created by Gahyun Kim on 2024/05/17. +// + +import SwiftUI + +struct ContentView: View { + var body: some View { + VStack { + Image(systemName: "globe") + .imageScale(.large) + .foregroundStyle(.tint) + Text("Hello, world!") + } + .padding() + } +} + +#Preview { + ContentView() +} diff --git a/SwiftUIStudy/SwiftUIStudy/Preview Content/Preview Assets.xcassets/Contents.json b/SwiftUIStudy/SwiftUIStudy/Preview Content/Preview Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/SwiftUIStudy/SwiftUIStudy/Preview Content/Preview Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/SwiftUIStudy/SwiftUIStudy/SwiftUIStudyApp.swift b/SwiftUIStudy/SwiftUIStudy/SwiftUIStudyApp.swift new file mode 100644 index 0000000..0a144fe --- /dev/null +++ b/SwiftUIStudy/SwiftUIStudy/SwiftUIStudyApp.swift @@ -0,0 +1,17 @@ +// +// SwiftUIStudyApp.swift +// SwiftUIStudy +// +// Created by Gahyun Kim on 2024/05/17. +// + +import SwiftUI + +@main +struct SwiftUIStudyApp: App { + var body: some Scene { + WindowGroup { + ContentView() + } + } +} From 5a47f765cb26f6309fed30ce2c8768708d8ed531 Mon Sep 17 00:00:00 2001 From: mcrkgus Date: Fri, 17 May 2024 15:45:43 +0900 Subject: [PATCH 2/8] =?UTF-8?q?UI=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwiftUIStudy/SwiftUIStudy/MainView.swift | 67 ++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 SwiftUIStudy/SwiftUIStudy/MainView.swift diff --git a/SwiftUIStudy/SwiftUIStudy/MainView.swift b/SwiftUIStudy/SwiftUIStudy/MainView.swift new file mode 100644 index 0000000..2989dff --- /dev/null +++ b/SwiftUIStudy/SwiftUIStudy/MainView.swift @@ -0,0 +1,67 @@ +// +// MainView.swift +// SwiftUIStudy +// +// Created by Gahyun Kim on 2024/05/17. +// + +import SwiftUI + +struct MainView: View { + + // HStack이 5개니깐... 일단 이러케... + private let buttons: [[CalculatorButton]] = [ + [.clear, .negative, .percent, .divide], + [.seven, .eight, .nine, .multiply], + [.four, .five, .six, .subtract], + [.one, .two, .three, .add], + [.zero, .decimal, .equal] + ] + + var body: some View { + VStack { + Spacer() + ForEach(buttons, id: \.self) { button in + HStack(spacing: 10) { + ForEach(button, id: \.self) { item in + Button { + calculate(button: item) + } label: { + Text(item.rawValue) + .font(.system(size: 40) .bold()) + .frame(width: buttonWidth(item: item), height: buttonHeight()) + .background(item.buttonColor) + // clipShape 와 rect의 활용에 대해서 다시 공부 + .clipShape(.rect(cornerRadius: buttonWidth(item: item) / 2)) + .foregroundColor(item.foregroundColor) + } + } + } + } + .padding(.bottom, 7) + } + } + + /// Button Width + func buttonWidth(item: CalculatorButton) -> CGFloat { + // 0일 경우에만 넓은 width를 준다! + if item == .zero { + return ((UIScreen.main.bounds.width - (4 * 12)) / 4) * 2 + } + return (UIScreen.main.bounds.width - (5 * 12)) / 4 + } + + /// Button Height + func buttonHeight() -> CGFloat { + return (UIScreen.main.bounds.width - (5 * 12)) / 4 + } + + /// 계산은 차차... 해볼게요 + func calculate(button: CalculatorButton) { + print("") + } +} + +#Preview { + MainView() +} From 25373a6837a0b4289ef91bfdc25f0b5bf3db5912 Mon Sep 17 00:00:00 2001 From: mcrkgus Date: Fri, 17 May 2024 15:58:18 +0900 Subject: [PATCH 3/8] Button Size --- SwiftUIStudy/SwiftUIStudy/ButtonSize.swift | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 SwiftUIStudy/SwiftUIStudy/ButtonSize.swift diff --git a/SwiftUIStudy/SwiftUIStudy/ButtonSize.swift b/SwiftUIStudy/SwiftUIStudy/ButtonSize.swift new file mode 100644 index 0000000..e39463e --- /dev/null +++ b/SwiftUIStudy/SwiftUIStudy/ButtonSize.swift @@ -0,0 +1,22 @@ +// +// ButtonSize.swift +// SwiftUIStudy +// +// Created by Gahyun Kim on 2024/05/17. +// + +import SwiftUI + +/// Button Width +func buttonWidth(item: CalculatorButton) -> CGFloat { + // 0일 경우에만 넓은 width를 준다! + if item == .zero { + return ((UIScreen.main.bounds.width - (4 * 12)) / 4) * 2 + } + return (UIScreen.main.bounds.width - (5 * 12)) / 4 +} + +/// Button Height +func buttonHeight() -> CGFloat { + return (UIScreen.main.bounds.width - (5 * 12)) / 4 +} From a3d9bf545904a1da7639833160f5de6dcc473d16 Mon Sep 17 00:00:00 2001 From: mcrkgus Date: Fri, 17 May 2024 15:58:49 +0900 Subject: [PATCH 4/8] =?UTF-8?q?Button=20Color=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwiftUIStudy/SwiftUIStudy/CalculatorButton.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SwiftUIStudy/SwiftUIStudy/CalculatorButton.swift b/SwiftUIStudy/SwiftUIStudy/CalculatorButton.swift index 7e7f986..9bf3edb 100644 --- a/SwiftUIStudy/SwiftUIStudy/CalculatorButton.swift +++ b/SwiftUIStudy/SwiftUIStudy/CalculatorButton.swift @@ -34,11 +34,11 @@ enum CalculatorButton: String { var buttonColor: Color { switch self { case .add, .subtract, .divide, .multiply, .equal: - return Color(.cyan) + return Color(red: 244 / 255, green: 196 / 255, blue: 230 / 255) case .clear, .negative, .percent: - return Color(.magenta) + return Color(red: 196 / 255, green: 244 / 255, blue: 239 / 255) default: - return Color(.systemPink) + return Color(red: 215 / 255, green: 196 / 255, blue: 244 / 255) } } From 40d449cb05bc9c048c10a68f0bad87d094a3cb63 Mon Sep 17 00:00:00 2001 From: mcrkgus Date: Fri, 17 May 2024 16:45:12 +0900 Subject: [PATCH 5/8] =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9D=BC=EB=B6=80=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwiftUIStudy/SwiftUIStudy/MainView.swift | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/SwiftUIStudy/SwiftUIStudy/MainView.swift b/SwiftUIStudy/SwiftUIStudy/MainView.swift index 2989dff..c88bdf5 100644 --- a/SwiftUIStudy/SwiftUIStudy/MainView.swift +++ b/SwiftUIStudy/SwiftUIStudy/MainView.swift @@ -41,21 +41,9 @@ struct MainView: View { .padding(.bottom, 7) } } - - /// Button Width - func buttonWidth(item: CalculatorButton) -> CGFloat { - // 0일 경우에만 넓은 width를 준다! - if item == .zero { - return ((UIScreen.main.bounds.width - (4 * 12)) / 4) * 2 - } - return (UIScreen.main.bounds.width - (5 * 12)) / 4 - } - - /// Button Height - func buttonHeight() -> CGFloat { - return (UIScreen.main.bounds.width - (5 * 12)) / 4 - } - +} + +extension MainView { /// 계산은 차차... 해볼게요 func calculate(button: CalculatorButton) { print("") From 0ff7275d245f76c99dd700302f64213c4de13d34 Mon Sep 17 00:00:00 2001 From: mcrkgus Date: Fri, 17 May 2024 17:03:01 +0900 Subject: [PATCH 6/8] =?UTF-8?q?.gitignore=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 8 +- .../SwiftUIStudy.xcodeproj/project.pbxproj | 361 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../SwiftUIStudy/SwiftUIStudyApp.swift | 2 +- 5 files changed, 378 insertions(+), 8 deletions(-) create mode 100644 SwiftUIStudy/SwiftUIStudy.xcodeproj/project.pbxproj create mode 100644 SwiftUIStudy/SwiftUIStudy.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 SwiftUIStudy/SwiftUIStudy.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/.gitignore b/.gitignore index 0325cae..1eda4f9 100644 --- a/.gitignore +++ b/.gitignore @@ -118,12 +118,6 @@ fastlane/test_output iOSInjectionProject/ -### SwiftPackageManager ### -Packages -xcuserdata -*.xcodeproj - - ### Xcode ### ## Xcode 8 and earlier @@ -137,4 +131,4 @@ xcuserdata /*.gcno **/xcshareddata/WorkspaceSettings.xcsettings -# End of https://www.toptal.com/developers/gitignore/api/xcode,swift,swiftpackagemanager,macos \ No newline at end of file +# End of https://www.toptal.com/developers/gitignore/api/xcode,swift,macos \ No newline at end of file diff --git a/SwiftUIStudy/SwiftUIStudy.xcodeproj/project.pbxproj b/SwiftUIStudy/SwiftUIStudy.xcodeproj/project.pbxproj new file mode 100644 index 0000000..364b39d --- /dev/null +++ b/SwiftUIStudy/SwiftUIStudy.xcodeproj/project.pbxproj @@ -0,0 +1,361 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + 832A44C22BF72D8100D5AF48 /* SwiftUIStudyApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 832A44C12BF72D8100D5AF48 /* SwiftUIStudyApp.swift */; }; + 832A44C42BF72D8100D5AF48 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 832A44C32BF72D8100D5AF48 /* ContentView.swift */; }; + 832A44C62BF72D8200D5AF48 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 832A44C52BF72D8200D5AF48 /* Assets.xcassets */; }; + 832A44C92BF72D8200D5AF48 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 832A44C82BF72D8200D5AF48 /* Preview Assets.xcassets */; }; + 832A44D22BF72DD000D5AF48 /* CalculatorButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 832A44D12BF72DD000D5AF48 /* CalculatorButton.swift */; }; + 832A44D42BF72E6100D5AF48 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 832A44D32BF72E6100D5AF48 /* MainView.swift */; }; + 832A44D62BF7371600D5AF48 /* ButtonSize.swift in Sources */ = {isa = PBXBuildFile; fileRef = 832A44D52BF7371600D5AF48 /* ButtonSize.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 832A44BE2BF72D8100D5AF48 /* SwiftUIStudy.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwiftUIStudy.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 832A44C12BF72D8100D5AF48 /* SwiftUIStudyApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIStudyApp.swift; sourceTree = ""; }; + 832A44C32BF72D8100D5AF48 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; + 832A44C52BF72D8200D5AF48 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 832A44C82BF72D8200D5AF48 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; + 832A44D12BF72DD000D5AF48 /* CalculatorButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalculatorButton.swift; sourceTree = ""; }; + 832A44D32BF72E6100D5AF48 /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = ""; }; + 832A44D52BF7371600D5AF48 /* ButtonSize.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonSize.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 832A44BB2BF72D8100D5AF48 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 832A44B52BF72D8100D5AF48 = { + isa = PBXGroup; + children = ( + 832A44C02BF72D8100D5AF48 /* SwiftUIStudy */, + 832A44BF2BF72D8100D5AF48 /* Products */, + ); + sourceTree = ""; + }; + 832A44BF2BF72D8100D5AF48 /* Products */ = { + isa = PBXGroup; + children = ( + 832A44BE2BF72D8100D5AF48 /* SwiftUIStudy.app */, + ); + name = Products; + sourceTree = ""; + }; + 832A44C02BF72D8100D5AF48 /* SwiftUIStudy */ = { + isa = PBXGroup; + children = ( + 832A44C12BF72D8100D5AF48 /* SwiftUIStudyApp.swift */, + 832A44C32BF72D8100D5AF48 /* ContentView.swift */, + 832A44C52BF72D8200D5AF48 /* Assets.xcassets */, + 832A44C72BF72D8200D5AF48 /* Preview Content */, + 832A44D12BF72DD000D5AF48 /* CalculatorButton.swift */, + 832A44D32BF72E6100D5AF48 /* MainView.swift */, + 832A44D52BF7371600D5AF48 /* ButtonSize.swift */, + ); + path = SwiftUIStudy; + sourceTree = ""; + }; + 832A44C72BF72D8200D5AF48 /* Preview Content */ = { + isa = PBXGroup; + children = ( + 832A44C82BF72D8200D5AF48 /* Preview Assets.xcassets */, + ); + path = "Preview Content"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 832A44BD2BF72D8100D5AF48 /* SwiftUIStudy */ = { + isa = PBXNativeTarget; + buildConfigurationList = 832A44CC2BF72D8200D5AF48 /* Build configuration list for PBXNativeTarget "SwiftUIStudy" */; + buildPhases = ( + 832A44BA2BF72D8100D5AF48 /* Sources */, + 832A44BB2BF72D8100D5AF48 /* Frameworks */, + 832A44BC2BF72D8100D5AF48 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = SwiftUIStudy; + productName = SwiftUIStudy; + productReference = 832A44BE2BF72D8100D5AF48 /* SwiftUIStudy.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 832A44B62BF72D8100D5AF48 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1520; + LastUpgradeCheck = 1520; + TargetAttributes = { + 832A44BD2BF72D8100D5AF48 = { + CreatedOnToolsVersion = 15.2; + }; + }; + }; + buildConfigurationList = 832A44B92BF72D8100D5AF48 /* Build configuration list for PBXProject "SwiftUIStudy" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 832A44B52BF72D8100D5AF48; + productRefGroup = 832A44BF2BF72D8100D5AF48 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 832A44BD2BF72D8100D5AF48 /* SwiftUIStudy */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 832A44BC2BF72D8100D5AF48 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 832A44C92BF72D8200D5AF48 /* Preview Assets.xcassets in Resources */, + 832A44C62BF72D8200D5AF48 /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 832A44BA2BF72D8100D5AF48 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 832A44C42BF72D8100D5AF48 /* ContentView.swift in Sources */, + 832A44D42BF72E6100D5AF48 /* MainView.swift in Sources */, + 832A44C22BF72D8100D5AF48 /* SwiftUIStudyApp.swift in Sources */, + 832A44D22BF72DD000D5AF48 /* CalculatorButton.swift in Sources */, + 832A44D62BF7371600D5AF48 /* ButtonSize.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 832A44CA2BF72D8200D5AF48 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 17.2; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 832A44CB2BF72D8200D5AF48 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 17.2; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 832A44CD2BF72D8200D5AF48 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"SwiftUIStudy/Preview Content\""; + DEVELOPMENT_TEAM = KT2Q6HC762; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.SwiftUIStudy; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 832A44CE2BF72D8200D5AF48 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"SwiftUIStudy/Preview Content\""; + DEVELOPMENT_TEAM = KT2Q6HC762; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.SwiftUIStudy; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 832A44B92BF72D8100D5AF48 /* Build configuration list for PBXProject "SwiftUIStudy" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 832A44CA2BF72D8200D5AF48 /* Debug */, + 832A44CB2BF72D8200D5AF48 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 832A44CC2BF72D8200D5AF48 /* Build configuration list for PBXNativeTarget "SwiftUIStudy" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 832A44CD2BF72D8200D5AF48 /* Debug */, + 832A44CE2BF72D8200D5AF48 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 832A44B62BF72D8100D5AF48 /* Project object */; +} diff --git a/SwiftUIStudy/SwiftUIStudy.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/SwiftUIStudy/SwiftUIStudy.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/SwiftUIStudy/SwiftUIStudy.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/SwiftUIStudy/SwiftUIStudy.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/SwiftUIStudy/SwiftUIStudy.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/SwiftUIStudy/SwiftUIStudy.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/SwiftUIStudy/SwiftUIStudy/SwiftUIStudyApp.swift b/SwiftUIStudy/SwiftUIStudy/SwiftUIStudyApp.swift index 0a144fe..047b8a8 100644 --- a/SwiftUIStudy/SwiftUIStudy/SwiftUIStudyApp.swift +++ b/SwiftUIStudy/SwiftUIStudy/SwiftUIStudyApp.swift @@ -11,7 +11,7 @@ import SwiftUI struct SwiftUIStudyApp: App { var body: some Scene { WindowGroup { - ContentView() + MainView() } } } From 8cc3f45c226543a409f74b5939a7b374cb5fcb99 Mon Sep 17 00:00:00 2001 From: mcrkgus Date: Sat, 25 May 2024 13:55:01 +0900 Subject: [PATCH 7/8] =?UTF-8?q?Display=20Number=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwiftUIStudy/SwiftUIStudy/MainView.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/SwiftUIStudy/SwiftUIStudy/MainView.swift b/SwiftUIStudy/SwiftUIStudy/MainView.swift index c88bdf5..1a6a6fb 100644 --- a/SwiftUIStudy/SwiftUIStudy/MainView.swift +++ b/SwiftUIStudy/SwiftUIStudy/MainView.swift @@ -9,6 +9,12 @@ import SwiftUI struct MainView: View { + @State private var displayNumber = "0" + @State private var computeNumber = 0 + @State private var currentOperator: Operation = .none + @State private var shouldClearDisplay = false + @State private var history = [] + // HStack이 5개니깐... 일단 이러케... private let buttons: [[CalculatorButton]] = [ [.clear, .negative, .percent, .divide], @@ -21,6 +27,14 @@ struct MainView: View { var body: some View { VStack { Spacer() + HStack { + Spacer() + Text("\(displayNumber)") + .bold() + .font(.system(size: 80)) + .foregroundColor(.white) + } + .padding() ForEach(buttons, id: \.self) { button in HStack(spacing: 10) { ForEach(button, id: \.self) { item in From f827aea72b41918c0227a873a47b67d1f019145f Mon Sep 17 00:00:00 2001 From: mcrkgus Date: Sat, 1 Jun 2024 01:31:26 +0900 Subject: [PATCH 8/8] =?UTF-8?q?[Feat]=20Calcurator=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SwiftUIStudy/SwiftUIStudy/MainView.swift | 65 ++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/SwiftUIStudy/SwiftUIStudy/MainView.swift b/SwiftUIStudy/SwiftUIStudy/MainView.swift index 1a6a6fb..e6e0bf5 100644 --- a/SwiftUIStudy/SwiftUIStudy/MainView.swift +++ b/SwiftUIStudy/SwiftUIStudy/MainView.swift @@ -10,12 +10,11 @@ import SwiftUI struct MainView: View { @State private var displayNumber = "0" - @State private var computeNumber = 0 + @State private var runningNumber = 0 @State private var currentOperator: Operation = .none @State private var shouldClearDisplay = false - @State private var history = [] + - // HStack이 5개니깐... 일단 이러케... private let buttons: [[CalculatorButton]] = [ [.clear, .negative, .percent, .divide], [.seven, .eight, .nine, .multiply], @@ -54,13 +53,69 @@ struct MainView: View { } .padding(.bottom, 7) } + .padding() + .background(Color.black) + .edgesIgnoringSafeArea(.all) } + } extension MainView { - /// 계산은 차차... 해볼게요 func calculate(button: CalculatorButton) { - print("") + switch button { + case .add, .subtract, .multiply, .divide, .equal: + if button == .add { + currentOperator = .add + runningNumber = Int(displayNumber) ?? 0 + } + else if button == .subtract { + currentOperator = .subtract + runningNumber = Int(displayNumber) ?? 0 + } + else if button == .multiply { + currentOperator = .multiply + runningNumber = Int(displayNumber) ?? 0 + } + else if button == .divide { + currentOperator = .divide + runningNumber = Int(displayNumber) ?? 0 + } + else if button == .equal { + let runningValue = runningNumber + let currentValue = Int(displayNumber) ?? 0 + + switch self.currentOperator { + case .add: displayNumber = "\(runningValue + currentValue)" + case .subtract: displayNumber = "\(runningValue - currentValue)" + case .multiply: displayNumber = "\(runningValue * currentValue)" + case .divide: displayNumber = "\(runningValue / currentValue)" + case .none: + break + } + } + shouldClearDisplay = true + + case .clear: + displayNumber = "0" + runningNumber = 0 + currentOperator = .none + shouldClearDisplay = false + case .decimal, .negative, .percent: + break + default: // 숫자일 경우 + if shouldClearDisplay { + displayNumber = button.rawValue + shouldClearDisplay = false + } else { + let number = button.rawValue + if displayNumber == "0" { + displayNumber = number + } + else { + displayNumber = "\(displayNumber)\(number)" + } + } + } } }