diff --git a/MovieDabang/MovieDabang.xcodeproj/project.pbxproj b/MovieDabang/MovieDabang.xcodeproj/project.pbxproj index 488556f..cf672b5 100644 --- a/MovieDabang/MovieDabang.xcodeproj/project.pbxproj +++ b/MovieDabang/MovieDabang.xcodeproj/project.pbxproj @@ -14,6 +14,8 @@ 09E7DC912AF37232004DE546 /* MovieDabangTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09E7DC902AF37232004DE546 /* MovieDabangTests.swift */; }; 09E7DC9B2AF37232004DE546 /* MovieDabangUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09E7DC9A2AF37232004DE546 /* MovieDabangUITests.swift */; }; 09E7DC9D2AF37232004DE546 /* MovieDabangUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09E7DC9C2AF37232004DE546 /* MovieDabangUITestsLaunchTests.swift */; }; + 61BABE562AF38C7200ADBD59 /* MovieDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61BABE552AF38C7200ADBD59 /* MovieDetailView.swift */; }; + 61BABE5C2AF3EBC600ADBD59 /* SwiftUIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61BABE5B2AF3EBC600ADBD59 /* SwiftUIView.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -44,6 +46,8 @@ 09E7DC962AF37232004DE546 /* MovieDabangUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MovieDabangUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 09E7DC9A2AF37232004DE546 /* MovieDabangUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieDabangUITests.swift; sourceTree = ""; }; 09E7DC9C2AF37232004DE546 /* MovieDabangUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieDabangUITestsLaunchTests.swift; sourceTree = ""; }; + 61BABE552AF38C7200ADBD59 /* MovieDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieDetailView.swift; sourceTree = ""; }; + 61BABE5B2AF3EBC600ADBD59 /* SwiftUIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftUIView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -96,6 +100,8 @@ children = ( 09E7DC7F2AF3722E004DE546 /* MovieDabangApp.swift */, 09E7DC812AF3722E004DE546 /* ContentView.swift */, + 61BABE552AF38C7200ADBD59 /* MovieDetailView.swift */, + 61BABE5B2AF3EBC600ADBD59 /* SwiftUIView.swift */, 09E7DC832AF37232004DE546 /* Assets.xcassets */, 09E7DC852AF37232004DE546 /* Preview Content */, ); @@ -257,7 +263,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 61BABE562AF38C7200ADBD59 /* MovieDetailView.swift in Sources */, 09E7DC822AF3722E004DE546 /* ContentView.swift in Sources */, + 61BABE5C2AF3EBC600ADBD59 /* SwiftUIView.swift in Sources */, 09E7DC802AF3722E004DE546 /* MovieDabangApp.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/MovieDabang/MovieDabang/Assets.xcassets/common.imageset/Contents.json b/MovieDabang/MovieDabang/Assets.xcassets/common.imageset/Contents.json new file mode 100644 index 0000000..e82c570 --- /dev/null +++ b/MovieDabang/MovieDabang/Assets.xcassets/common.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "common.jpeg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/MovieDabang/MovieDabang/Assets.xcassets/common.imageset/common.jpeg b/MovieDabang/MovieDabang/Assets.xcassets/common.imageset/common.jpeg new file mode 100644 index 0000000..b30fa01 Binary files /dev/null and b/MovieDabang/MovieDabang/Assets.xcassets/common.imageset/common.jpeg differ diff --git a/MovieDabang/MovieDabang/ContentView.swift b/MovieDabang/MovieDabang/ContentView.swift index 30cc3e8..1df8a44 100644 --- a/MovieDabang/MovieDabang/ContentView.swift +++ b/MovieDabang/MovieDabang/ContentView.swift @@ -10,7 +10,7 @@ import SwiftUI struct ContentView: View { var body: some View { VStack { - Image(systemName: "globe") + Image(systemName: "mug") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") diff --git a/MovieDabang/MovieDabang/MovieDetailView.swift b/MovieDabang/MovieDabang/MovieDetailView.swift new file mode 100644 index 0000000..d031cf6 --- /dev/null +++ b/MovieDabang/MovieDabang/MovieDetailView.swift @@ -0,0 +1,73 @@ +// +// MovieDetailView.swift +// MovieDabang +// +// Created by 박선구 on 11/2/23. +// + +import SwiftUI + +struct Movie: Codable, Identifiable { + let id: Int + let title: String + let overview: String + let posterPath: String + let releaseDate: String + let voteAverage: Double +} + +struct MovieDetailView: View { + @State var like : Bool = false + @Binding var movie : Movie +// @State private var movie : Movie + +// let Movie = ["name" : "과속스캔들", "date" : "2007.11.14", "people" : "264K", "imageName" : "testImage"] + + + var body: some View { + Form { + Section(content: { + Image(movie.overview) + .resizable() + .cornerRadius(12.0) + .aspectRatio(contentMode: .fit) + .padding() + + Text(movie.title) + .font(.largeTitle) + + Text(movie.releaseDate) + .font(.headline) + + Text("\(movie.voteAverage)") + .font(.headline) + Spacer() + HStack{ + Spacer() + Text("좋아요") +// Spacer() + Image(systemName: like == false ? "heart" : "heart.fill") + .resizable() + .frame(width: 30,height: 30) + .onTapGesture { + touchHeart() + } + .foregroundStyle(like ? .red : .gray) + .symbolEffect(.bounce, value: like) + } + .padding(15) + }) + } + } + func touchHeart() { + if like == false{ + like = true + }else{ + like = false + } + } +} + +//#Preview { +// MovieDetailView() +//} diff --git a/MovieDabang/MovieDabang/SwiftUIView.swift b/MovieDabang/MovieDabang/SwiftUIView.swift new file mode 100644 index 0000000..5215838 --- /dev/null +++ b/MovieDabang/MovieDabang/SwiftUIView.swift @@ -0,0 +1,55 @@ +// +// SwiftUIView.swift +// MovieDabang +// +// Created by 박선구 on 11/2/23. +// + +import SwiftUI + +struct SwiftUIView: View { + var body: some View { + List{ + HStack{ + Text("Hello, World!afwafafwag") + Spacer() + Image(systemName: "star") + Text("5.55") + } + HStack{ + Text("Hello, Worlag") + Spacer() + Image(systemName: "star") + Text("1.11") + } + HStack{ + Text("Hellwag") + Spacer() + Image(systemName: "star") + Text("9.99") + } + HStack{ + Text("Hello, Woaag") + Spacer() + Image(systemName: "star") + Text("1.25") + } + HStack{ + Text("Hello, Worlwag") + Spacer() + Image(systemName: "star") + Text("1.25") + } + HStack{ + Text("Hellowfawafffwfafawgawafwag") + Spacer() + Image(systemName: "star") + Text("1.25") + } + } + } +} + +#Preview { + SwiftUIView() +} diff --git a/Weather/Weather.xcodeproj/project.pbxproj b/Weather/Weather.xcodeproj/project.pbxproj new file mode 100644 index 0000000..575cdac --- /dev/null +++ b/Weather/Weather.xcodeproj/project.pbxproj @@ -0,0 +1,391 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + 614776A22B048B1A000D0C88 /* WeatherApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 614776A12B048B1A000D0C88 /* WeatherApp.swift */; }; + 614776A42B048B1A000D0C88 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 614776A32B048B1A000D0C88 /* ContentView.swift */; }; + 614776A62B048B1B000D0C88 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 614776A52B048B1B000D0C88 /* Assets.xcassets */; }; + 614776A92B048B1B000D0C88 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 614776A82B048B1B000D0C88 /* Preview Assets.xcassets */; }; + 614776B02B048CA0000D0C88 /* AddTodoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 614776AF2B048CA0000D0C88 /* AddTodoView.swift */; }; + 614776B22B048CD1000D0C88 /* MapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 614776B12B048CD1000D0C88 /* MapView.swift */; }; + 614776B62B048CDA000D0C88 /* todoDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 614776B32B048CDA000D0C88 /* todoDetailView.swift */; }; + 614776B72B048CDA000D0C88 /* WeatherView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 614776B42B048CDA000D0C88 /* WeatherView.swift */; }; + 614776B82B048CDA000D0C88 /* todoListVIew.swift in Sources */ = {isa = PBXBuildFile; fileRef = 614776B52B048CDA000D0C88 /* todoListVIew.swift */; }; + 614776BD2B048CE3000D0C88 /* Network.swift in Sources */ = {isa = PBXBuildFile; fileRef = 614776BA2B048CE3000D0C88 /* Network.swift */; }; + 614776BE2B048CE3000D0C88 /* Weather.swift in Sources */ = {isa = PBXBuildFile; fileRef = 614776BB2B048CE3000D0C88 /* Weather.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 6147769E2B048B1A000D0C88 /* Weather.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Weather.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 614776A12B048B1A000D0C88 /* WeatherApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeatherApp.swift; sourceTree = ""; }; + 614776A32B048B1A000D0C88 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; + 614776A52B048B1B000D0C88 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 614776A82B048B1B000D0C88 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; + 614776AF2B048CA0000D0C88 /* AddTodoView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AddTodoView.swift; sourceTree = ""; }; + 614776B12B048CD1000D0C88 /* MapView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapView.swift; sourceTree = ""; }; + 614776B32B048CDA000D0C88 /* todoDetailView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = todoDetailView.swift; sourceTree = ""; }; + 614776B42B048CDA000D0C88 /* WeatherView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WeatherView.swift; sourceTree = ""; }; + 614776B52B048CDA000D0C88 /* todoListVIew.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = todoListVIew.swift; sourceTree = ""; }; + 614776BA2B048CE3000D0C88 /* Network.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Network.swift; sourceTree = ""; }; + 614776BB2B048CE3000D0C88 /* Weather.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Weather.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 6147769B2B048B1A000D0C88 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 614776952B048B19000D0C88 = { + isa = PBXGroup; + children = ( + 614776A02B048B1A000D0C88 /* Weather */, + 6147769F2B048B1A000D0C88 /* Products */, + ); + sourceTree = ""; + }; + 6147769F2B048B1A000D0C88 /* Products */ = { + isa = PBXGroup; + children = ( + 6147769E2B048B1A000D0C88 /* Weather.app */, + ); + name = Products; + sourceTree = ""; + }; + 614776A02B048B1A000D0C88 /* Weather */ = { + isa = PBXGroup; + children = ( + 614776C02B048DE9000D0C88 /* NetworkSetting */, + 614776BF2B048D8F000D0C88 /* UIView */, + 614776A12B048B1A000D0C88 /* WeatherApp.swift */, + 614776A32B048B1A000D0C88 /* ContentView.swift */, + 614776A52B048B1B000D0C88 /* Assets.xcassets */, + 614776A72B048B1B000D0C88 /* Preview Content */, + ); + path = Weather; + sourceTree = ""; + }; + 614776A72B048B1B000D0C88 /* Preview Content */ = { + isa = PBXGroup; + children = ( + 614776A82B048B1B000D0C88 /* Preview Assets.xcassets */, + ); + path = "Preview Content"; + sourceTree = ""; + }; + 614776BF2B048D8F000D0C88 /* UIView */ = { + isa = PBXGroup; + children = ( + 614776B32B048CDA000D0C88 /* todoDetailView.swift */, + 614776B52B048CDA000D0C88 /* todoListVIew.swift */, + 614776B42B048CDA000D0C88 /* WeatherView.swift */, + 614776B12B048CD1000D0C88 /* MapView.swift */, + 614776AF2B048CA0000D0C88 /* AddTodoView.swift */, + ); + path = UIView; + sourceTree = ""; + }; + 614776C02B048DE9000D0C88 /* NetworkSetting */ = { + isa = PBXGroup; + children = ( + 614776BA2B048CE3000D0C88 /* Network.swift */, + 614776BB2B048CE3000D0C88 /* Weather.swift */, + ); + path = NetworkSetting; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 6147769D2B048B1A000D0C88 /* Weather */ = { + isa = PBXNativeTarget; + buildConfigurationList = 614776AC2B048B1B000D0C88 /* Build configuration list for PBXNativeTarget "Weather" */; + buildPhases = ( + 6147769A2B048B1A000D0C88 /* Sources */, + 6147769B2B048B1A000D0C88 /* Frameworks */, + 6147769C2B048B1A000D0C88 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Weather; + productName = Weather; + productReference = 6147769E2B048B1A000D0C88 /* Weather.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 614776962B048B19000D0C88 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1500; + LastUpgradeCheck = 1500; + TargetAttributes = { + 6147769D2B048B1A000D0C88 = { + CreatedOnToolsVersion = 15.0; + }; + }; + }; + buildConfigurationList = 614776992B048B19000D0C88 /* Build configuration list for PBXProject "Weather" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 614776952B048B19000D0C88; + productRefGroup = 6147769F2B048B1A000D0C88 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 6147769D2B048B1A000D0C88 /* Weather */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 6147769C2B048B1A000D0C88 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 614776A92B048B1B000D0C88 /* Preview Assets.xcassets in Resources */, + 614776A62B048B1B000D0C88 /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 6147769A2B048B1A000D0C88 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 614776B62B048CDA000D0C88 /* todoDetailView.swift in Sources */, + 614776A42B048B1A000D0C88 /* ContentView.swift in Sources */, + 614776B22B048CD1000D0C88 /* MapView.swift in Sources */, + 614776B72B048CDA000D0C88 /* WeatherView.swift in Sources */, + 614776BE2B048CE3000D0C88 /* Weather.swift in Sources */, + 614776B82B048CDA000D0C88 /* todoListVIew.swift in Sources */, + 614776BD2B048CE3000D0C88 /* Network.swift in Sources */, + 614776A22B048B1A000D0C88 /* WeatherApp.swift in Sources */, + 614776B02B048CA0000D0C88 /* AddTodoView.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 614776AA2B048B1B000D0C88 /* 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.0; + 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; + }; + 614776AB2B048B1B000D0C88 /* 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.0; + 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; + }; + 614776AD2B048B1B000D0C88 /* 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 = "\"Weather/Preview Content\""; + 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 = skp.318.Weather; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 614776AE2B048B1B000D0C88 /* 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 = "\"Weather/Preview Content\""; + 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 = skp.318.Weather; + 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 */ + 614776992B048B19000D0C88 /* Build configuration list for PBXProject "Weather" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 614776AA2B048B1B000D0C88 /* Debug */, + 614776AB2B048B1B000D0C88 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 614776AC2B048B1B000D0C88 /* Build configuration list for PBXNativeTarget "Weather" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 614776AD2B048B1B000D0C88 /* Debug */, + 614776AE2B048B1B000D0C88 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 614776962B048B19000D0C88 /* Project object */; +} diff --git a/Weather/Weather.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Weather/Weather.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/Weather/Weather.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Weather/Weather.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Weather/Weather.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Weather/Weather.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Weather/Weather/Assets.xcassets/AccentColor.colorset/Contents.json b/Weather/Weather/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000..eb87897 --- /dev/null +++ b/Weather/Weather/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Weather/Weather/Assets.xcassets/AppIcon.appiconset/Contents.json b/Weather/Weather/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..13613e3 --- /dev/null +++ b/Weather/Weather/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/Weather/Weather/Assets.xcassets/Contents.json b/Weather/Weather/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/Weather/Weather/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Weather/Weather/ContentView.swift b/Weather/Weather/ContentView.swift new file mode 100644 index 0000000..2127521 --- /dev/null +++ b/Weather/Weather/ContentView.swift @@ -0,0 +1,22 @@ +// +// ContentView.swift +// WeatherApp +// +// Created by 박선구 on 11/13/23. +// + +import SwiftUI + +struct ContentView: View { + + var body: some View { + VStack{ + + } + } +} + +#Preview { + ContentView() + .environmentObject(Network()) +} diff --git a/Weather/Weather/NetworkSetting/Network.swift b/Weather/Weather/NetworkSetting/Network.swift new file mode 100644 index 0000000..77a04f1 --- /dev/null +++ b/Weather/Weather/NetworkSetting/Network.swift @@ -0,0 +1,46 @@ +// +// Network.swift +// WeatherApp +// +// Created by 박선구 on 11/13/23. +// + +import Foundation +import SwiftUI + +class Network: ObservableObject { + @Published var weather: Instruction = Instruction.sample + + let apiKey = "apiKey" + + func getWeather() { + guard let url = URL(string: "https://api.openweathermap.org/data/2.5/weather?q=seoul&appid=\(apiKey)") else { fatalError("Missing URL") } + + let urlRequest = URLRequest(url: url) + + // Task 만들기 + let dataTask = URLSession.shared.dataTask(with: urlRequest) { (data, response, error) in + if let error = error { + print("Request error: ", error) + return + } + + guard let response = response as? HTTPURLResponse else { return } + + // 응답 상태코드가 200(성공)일 경우에만 디코딩 + if response.statusCode == 200 { + guard let data = data else { return } + DispatchQueue.main.async { + do { + let decodedWeather = try JSONDecoder().decode(Instruction.self, from: data) + self.weather = decodedWeather + } catch let error { + print("Error decoding: ", error) + } + } + } + } + // Task 수행하기 + dataTask.resume() + } +} diff --git a/Weather/Weather/NetworkSetting/Weather.swift b/Weather/Weather/NetworkSetting/Weather.swift new file mode 100644 index 0000000..9cc9831 --- /dev/null +++ b/Weather/Weather/NetworkSetting/Weather.swift @@ -0,0 +1,88 @@ +// +// Weather.swift +// WeatherApp +// +// Created by 박선구 on 11/13/23. +// + +import Foundation + +// MARK: - Welcome +struct Welcome: Codable { + let greeting: String + let instructions: [Instruction] +} + +// MARK: - Instruction +struct Instruction: Codable { + let coord: Coord + let weather: [Weather] + let base: String + let main: Main + let visibility: Int + let wind: Wind + let clouds: Clouds + let dt: Int + let sys: Sys + let timezone, id: Int + let name: String + let cod: Int + + static let sample = Instruction( + coord: Coord(lon: 0, lat: 0), + weather: [], + base: "", + main: Main(temp: 0, feelsLike: 0, tempMin: 0, tempMax: 0, pressure: 0, humidity: 0), + visibility: 0, + wind: Wind(speed: 0, deg: 0), + clouds: Clouds(all: 0), + dt: 0, + sys: Sys(type: 0, id: 0, country: "", sunrise: 0, sunset: 0), + timezone: 0, + id: 0, + name: "", + cod: 0) +} + +// MARK: - Clouds +struct Clouds: Codable { + let all: Int +} + +// MARK: - Coord +struct Coord: Codable { + let lon, lat: Double +} + +// MARK: - Main +struct Main: Codable { + let temp, feelsLike, tempMin, tempMax: Double + let pressure, humidity: Int + + enum CodingKeys: String, CodingKey { + case temp + case feelsLike = "feels_like" + case tempMin = "temp_min" + case tempMax = "temp_max" + case pressure, humidity + } +} + +// MARK: - Sys +struct Sys: Codable { + let type, id: Int + let country: String + let sunrise, sunset: Int +} + +// MARK: - Weather +struct Weather: Codable { + let id: Int + let main, description, icon: String +} + +// MARK: - Wind +struct Wind: Codable { + let speed: Double + let deg: Int +} diff --git a/Weather/Weather/Preview Content/Preview Assets.xcassets/Contents.json b/Weather/Weather/Preview Content/Preview Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/Weather/Weather/Preview Content/Preview Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Weather/Weather/Property List.plist b/Weather/Weather/Property List.plist new file mode 100644 index 0000000..86f0207 --- /dev/null +++ b/Weather/Weather/Property List.plist @@ -0,0 +1,8 @@ + + + + + OPENWEATHERMAP_KEY + + + diff --git a/Weather/Weather/UIView/AddTodoView.swift b/Weather/Weather/UIView/AddTodoView.swift new file mode 100644 index 0000000..ba72115 --- /dev/null +++ b/Weather/Weather/UIView/AddTodoView.swift @@ -0,0 +1,67 @@ +// +// AddTodoView.swift +// WeatherApp +// +// Created by 박선구 on 11/15/23. +// + +import SwiftUI + +struct AddTodoView: View { + @ObservedObject var todayListStore: TodoListStore = TodoListStore() + + @State var title: String = "" + @State var content: String = "" + + var body: some View { + VStack(alignment: .leading){ + Text(dateFormatter()) + .font(.largeTitle) + + Text("일정 추가") + .font(.title) + + Spacer() + + Text("Title") + TextField("title", text: $title) + + Text("Detail") + TextField("detail", text: $content) + + Spacer() + } + .textFieldStyle(.roundedBorder) + .padding() + + VStack(alignment: .center){ + Button(action: addContent, label: { + Text("추가") + }) + } + } + + func addContent() { + if !title.isEmpty && !content.isEmpty { + todayListStore.addList(title: title, content: content) +// TodoListStore.addList(title: title, content: content) + title = "" + content = "" + } else { + title = "" + content = "" + } + } + + func dateFormatter() -> String{ + let nowDate = Date() + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "yyyy년 MM월 dd일" + let str = dateFormatter.string(from: nowDate) + return str + } +} + +#Preview { + AddTodoView() +} diff --git a/Weather/Weather/UIView/MapView.swift b/Weather/Weather/UIView/MapView.swift new file mode 100644 index 0000000..6fd0d54 --- /dev/null +++ b/Weather/Weather/UIView/MapView.swift @@ -0,0 +1,29 @@ +// +// MapView.swift +// WeatherApp +// +// Created by 박선구 on 11/14/23. +// + +import SwiftUI +import MapKit + + + + +struct MapView: View { + + @State private var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 37.5666791, longitude: 126.9782914), span: MKCoordinateSpan(latitudeDelta: 0.5, longitudeDelta: 0.5)) + + + + var body: some View { + Map(coordinateRegion: $region, interactionModes: []) + .frame(width: 350, height: 300) + .cornerRadius(10) + } +} + +#Preview { + MapView() +} diff --git a/Weather/Weather/UIView/WeatherView.swift b/Weather/Weather/UIView/WeatherView.swift new file mode 100644 index 0000000..c3e49ac --- /dev/null +++ b/Weather/Weather/UIView/WeatherView.swift @@ -0,0 +1,173 @@ +// +// WeatherView.swift +// WeatherApp +// +// Created by 박선구 on 11/14/23. +// + +import SwiftUI + +struct WeatherView: View { + + @EnvironmentObject var network: Network + @State private var selection = 1 + @State private var title = "일정 추가" + + var bgColor : Color = .black + + //국가 + var country: String {network.weather.sys.country} + + //좌표 + var coord1: Double {network.weather.coord.lat} + var coord2: Double {network.weather.coord.lon} + + //날씨 + var clouds: String { String(format: "%.1f", (network.weather.clouds.all))} + var wind: String { String(format: "%.1f", (network.weather.wind.speed))} + + // + var weatherMain: String {network.weather.weather.first?.main ?? ""} + var weatherDescription: String {network.weather.weather.first?.description ?? ""} + + + //온도 + var temp: String { String(format: "%.1f", (network.weather.main.temp - 273.15)) } + var tempMin: String { String(format: "%.1f", (network.weather.main.tempMin - 273.15)) } + var tempMax: String { String(format: "%.1f", (network.weather.main.tempMax - 273.15)) } + + //아이콘 + var icon: String {network.weather.weather.first?.icon ?? "" } + var humidity: Int {network.weather.main.humidity} + + + var body: some View { + NavigationStack{ + Text("\(country)") + Text("서울특별시") + .font(.headline) + + HStack{ + Text("\(coord1)") + Text("\(coord2)") + } + .font(.subheadline) + + TabView(selection: $selection) { + VStack{ + Spacer() + + VStack{ + HStack{ + Image(systemName: SelectIcon()) + .resizable() + .frame(width: 50, height: 50) + .foregroundColor(SelectColor()) + Text("\(weatherMain)") + .font(.largeTitle) + } + .padding() + + VStack{ + Text("\(temp) ℃") + .font(.largeTitle) + HStack{ + Text("\(tempMin)℃") + Text(" ~ ") + Text("\(tempMax)℃") + } + } + } + .padding() + + Spacer() + + HStack{ + Spacer() + Image(systemName: "cloud") + Text("\(clouds)") + Spacer() + Image(systemName: "wind") + Text("\(wind)m/s") + Spacer() + Image(systemName: "humidity") + Text("\(humidity)") + Spacer() + } + } + .tag(1) + .onAppear{ + network.getWeather() + } + + MapView() + .tag(2) + } + .tabViewStyle(PageTabViewStyle()) + + Text("") + .frame(width: 350, height: 2) + .background(SelectColor()) + + todoListVIew() + } + } + + func SelectIcon () -> String{ + + if icon == "01d" || icon == "01n" { + return "sun.max.fill" + } else if icon == "02d" || icon == "02n" { + return "cloud.sun.fill" + } else if icon == "03d" || icon == "03n"{ + return "cloud.fill" + } else if icon == "04d" || icon == "04n"{ + return "cloud.fill" + } else if icon == "09d" || icon == "09n"{ + return "cloud.heavyrain.fill" + } else if icon == "10d" || icon == "10n"{ + return "sun.rain.fill" + } else if icon == "11d" || icon == "11n"{ + return "cloud.bolt.fill" + } else if icon == "13d" || icon == "13n"{ + return "cloud.snow.fill" + } else if icon == "50d" || icon == "50n"{ + return "cloud.fog.fill" + } else { + return "sun.horizon.fill" + } + } + + func SelectColor () -> Color{ + + if icon == "01d" || icon == "01n" { + return .red + } else if icon == "02d" || icon == "02n" { + return .blue + } else if icon == "03d" || icon == "03n"{ + return .gray + } else if icon == "04d" || icon == "04n"{ + return .gray + } else if icon == "09d" || icon == "09n"{ + return .blue + } else if icon == "10d" || icon == "10n"{ + return .yellow + } else if icon == "11d" || icon == "11n"{ + return .orange + } else if icon == "13d" || icon == "13n"{ + return .gray + } else if icon == "50d" || icon == "50n"{ + return .gray + } else { + return .black + } + } + +} + + + +#Preview { + WeatherView() + .environmentObject(Network()) +} diff --git a/Weather/Weather/UIView/todoDetailView.swift b/Weather/Weather/UIView/todoDetailView.swift new file mode 100644 index 0000000..87cd2f3 --- /dev/null +++ b/Weather/Weather/UIView/todoDetailView.swift @@ -0,0 +1,41 @@ +// +// todoDetailView.swift +// WeatherApp +// +// Created by 박선구 on 11/14/23. +// + +import SwiftUI + +struct todoDetailView: View { + + let selectedList: TodoList + + + var body: some View { + Form{ + Section(content: { + Text(selectedList.title) + .font(.largeTitle) + + Text(selectedList.content) + .font(.title) + }, header: { + Text(dateFormatter()) + }) + + } + } + func dateFormatter() -> String{ + let nowDate = Date() + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "yyyy년 MM월 dd일" + let str = dateFormatter.string(from: nowDate) + return str + } +} + +//#Preview { +// todoDetailView(selectedList: TodoList[0]) +//} + diff --git a/Weather/Weather/UIView/todoListVIew.swift b/Weather/Weather/UIView/todoListVIew.swift new file mode 100644 index 0000000..547367f --- /dev/null +++ b/Weather/Weather/UIView/todoListVIew.swift @@ -0,0 +1,98 @@ +// +// todoListVIew.swift +// WeatherApp +// +// Created by 박선구 on 11/14/23. +// + +import SwiftUI + +struct TodoList: Hashable, Identifiable { + var id: UUID = UUID() + var title: String + var content: String +} + +class TodoListStore: ObservableObject { + @Published var todayList: [TodoList] + + init() { + self.todayList = [ + TodoList(title: "오늘의 할일 1", content: "오늘 해야할 일을 입력"), + TodoList(title: "오늘의 할일 2", content: "오늘 해야할 일을 입력") + ] + } + + func addList(title: String, content: String) { + let linklist: TodoList = TodoList(title: title, content: content) + todayList.append(linklist) + } + +} + + + +struct todoListVIew: View { + + @StateObject var todayListStore = TodoListStore() + @State private var stackPath = NavigationPath() + @State var title: String = "" + @State var content: String = "" + + var body: some View { + Text("\(dateFormatter())") + .padding() + .foregroundColor(.black) + .font(.largeTitle) + NavigationStack(path: $stackPath){ + List{ + ForEach(todayListStore.todayList){ item in + VStack(alignment: .leading){ + Text(item.title).font(.title2) + Text(item.content).foregroundStyle(.gray) + } + .listRowSeparatorTint(.black) + } + .onDelete { item in + todayListStore.todayList.remove(atOffsets: item) + } + .onMove { from , to in + todayListStore.todayList.move(fromOffsets: from, toOffset: to) + } + } + .navigationDestination(for: Int.self) { i in todoDetailView(selectedList: todayListStore.todayList[i]) + } + .listStyle(.inset) + + NavigationLink(destination: AddTodoView(todayListStore: self.todayListStore), label: { + VStack{ + Text("일정추가").font(.body) + } + }) + } + + } + + func dateFormatter() -> String{ + let nowDate = Date() + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "yyyy년 MM월 dd일" + let str = dateFormatter.string(from: nowDate) + return str + } +} + +struct ListCell: View { + + var list: TodoList + var body: some View { + VStack{ + Text(list.title) + } + } +} + + +#Preview { + todoListVIew() +} diff --git a/Weather/Weather/WeatherApp.swift b/Weather/Weather/WeatherApp.swift new file mode 100644 index 0000000..6036ec7 --- /dev/null +++ b/Weather/Weather/WeatherApp.swift @@ -0,0 +1,18 @@ +// +// WeatherApp.swift +// Weather +// +// Created by 박선구 on 11/15/23. +// + +import SwiftUI + +@main +struct WeatherApp: App { + var body: some Scene { + WindowGroup { + WeatherView() + .environmentObject(Network()) + } + } +} diff --git a/Weather/Weather/WeatherAppApp.swift b/Weather/Weather/WeatherAppApp.swift new file mode 100644 index 0000000..e134255 --- /dev/null +++ b/Weather/Weather/WeatherAppApp.swift @@ -0,0 +1,20 @@ +// +// WeatherAppApp.swift +// WeatherApp +// +// Created by 박선구 on 11/13/23. +// + +import SwiftUI + +@main +struct WeatherAppApp: App { + var network = Network() + + var body: some Scene { + WindowGroup { + WeatherView() + .environmentObject(network) + } + } +} diff --git a/lecture/23.09.21.swift b/lecture/23.09.21.swift new file mode 100644 index 0000000..b3e80a1 --- /dev/null +++ b/lecture/23.09.21.swift @@ -0,0 +1,365 @@ +// Created by 박선구 on 2023/09/21. + +import Foundation + +//MARK: - + +//print("아무말 입력: ", terminator: "") +// +//var input = Int(readLine()!)! +//print(input) + +//MARK: - + +//let orange: Int = 3729 +//let number: Int = 52 +// +//var box: Int = orange / number +//var left: Int = orange % number +//print("김모씨가 귤 박스를 줄 수 있는 박스의 수는? ",box) +//print("박스에 담고 남은 귤의 수는? ", left) + +//MARK: - + +//let num : Int = 456; +//var numnum : Int? +// +//numnum = ((num / 10) * 10) + 1 +//print(numnum!) + + +//MARK: - + +//print("swift", terminator: " ") +//print("ios", terminator: " ") +//print("web: ", terminator: " ") +// +//let swift : Int = Int(readLine()!)! +//let ios : Int = Int(readLine()!)! +//let web : Int = Int(readLine()!)! +//var sum = (swift + ios + web) +//var num = sum / 3 +// +//print("합계: ",sum) +//print("평균: ",num) + +//MARK: - + +//끔하게 (읽기 쉽게) +//print("swift", terminator: " ") +//let ios = Int(readLine()!)! +//print("ios", terminator: " ") +//let swift = Int(readLine()!)! +//print("web ", terminator: " ") +//let web = Int(readLine()!)! +// +//var sum: Int = ios + swift + web +//var avg = Float(sum) / 3.0 +// +//print("합", sum) +//print("평", avg) + +//MARK: - + +////연습 +//let x = 10 +//let y = 20 +// +//print("result", x > y ? "안녕" : "잘가") + + +//MARK: - + +////시간구하기 +//print("초 입력: ", terminator: " ") +//var stime = Int(readLine()!)! +//var mtime : Int = 0 +//var htime : Int = 0 +// +//mtime = (stime / 60) % 60 +//htime = (stime / 60) / 60 +//stime = stime % 60 +// +//print("시간", htime) +//print("분", mtime) +//print("초", stime) + +//MARK: - + +////노동시간 +//print("노동시간: ", terminator: " ") +//var times = Int(readLine()!)! +//var money : Double = 0 +//var overTime = (times - 8) +// +//if times > 8 { +// money = ((Double(overTime) * (5000*1.5)) + (8 * 5000.0)) +//}else{ +// money = Double(times) * 5000.0 +//} +//print("총 임금은", Int(money),"원 입니다.") + + +//MARK: - + +////짝수홀수 +//print("정수를 입력하세요: ", terminator: " ") +//let num = Int(readLine()!)! +// +//var num1 = num % 2 +//print(num1 >= 1 ? "홀수입니다." : "짝수입니다.") +//MARK: - + +// +////두 개의 정수 +//print("정수를 입력하세요: ", terminator: " ") +//let num1 = Int(readLine()!)! +//print("정수를 입력하세요: ", terminator: " ") +//let num2 = Int(readLine()!)! +// +//print("두 수의 차: ", num1 > num2 ? "\(num1 - num2)":"\(num2-num1)") + +//MARK: - + +//func inputLine(_ message: String) -> Int { +// print(message, terminator: " ") +// return Int(readLine()!)! +//} +//// +// +// +//print("초를 입력해주세요: ", terminator: " ") +//let total = Int(readLine()!)! +// +//let m = (total / 60) % 60 //분 구하기 초를 60으로 나누면 나머지가 분이다. +//let h = (total/60)/60 //시간 구하기 초를 60으로 나누고 한번더 60으로 나누면 초가 시간이 된다. +//let s = total % 60 //초는 전체초를 60으로 나누면 나온다. +//print(h , m, s) +//print("시간:",h ,"분:",m ,"초:" ,s) + +//MARK: - + +////농구공 상자 문제 +//print("공의 수를 입력해주세요: ", terminator: " ") +//let balls = Int(readLine()!)! +//var leftBall = 0 +//var boxs = 0 +// +//leftBall = balls % 5 +//boxs = balls / 5 +// +//print("공이 들어간 박스: ", boxs) +//print("남은 공: ", leftBall) +// +//if leftBall != 0 { +// boxs = boxs + 1 +// print("필요한 상자의 수: ", boxs) +//}else{ +// +// print("필요한 상자의 수: ", boxs) +//} +// +// +//print("필요한 상자의 수", leftBall != 0 ? "\(boxs = boxs + 1)": boxs) + + + +//MARK: - + +//경헌님 도움 +//print("예제 6") +//print("초 입력: ", terminator: "") +//var sec = Int(readLine()!)! +// +//var m = sec / 60 +//sec %= 60 +//let h = m / 60 +//m %= 60 +// +//print("\(h)시 \(m)분 \(sec)초") +//print("----------") + +//MARK: - + +////if문 예제 1 +//print("정수 입력: ", terminator: " ") +//let age = Int(readLine()!)! +// +//if age >= 20 { +// print("성인입니다.") +//}else{ +// print("어린이입니다.") +//} + +//MARK: - + +////조건문예제 2번 +//print("num 입력: ", terminator: " ") +//var num = Int(readLine()!)! +//var a = 0 ;var b = 0 +//a = num % 3 +//b = num % 5 +// +//if a == 0 && b == 0{ +// print("3과 5의 배수입니다.") +//}else{ +// print("3과 5의 배수가 아닙니다.") +//} + +//MARK: - + +////조건문예제 3번 +//print("grade 입력: ", terminator: " ") +//let grade = Int(readLine()!)! +// +//if grade >= 60{ +// print("합격입니다.") +//}else{ +// print("불합격입니다.") +//} + +//MARK: - + +////조건문예제 4번 +//print("정수 입력: ", terminator: " ") +//let num = Int(readLine()!)! +// +//if num > 0{ +// print(num, "양수입니다.") +//}else if num < 0{ +// print(num, "음수입니다.") +//}else { +// print(0,"입니다.") +//} + +//MARK: - + +//조건문예제 5번 +//print("정수 num1 입력: ", terminator: " ") +//let num1 = Int(readLine()!)! +//print("정수 num2 입력: ", terminator: " ") +//let num2 = Int(readLine()!)! +// +//if num1 > num2 { +// print(num1) +//}else if num1 < num2 { +// print(num2) +//}else{} + +//MARK: - +// # again + + +//////조건문예제 6번 +//print("1과목 소프트웨어 설계: ", terminator: " ") +//let num1 = Int(readLine()!)! +//print("2과목 소프트웨어 개발: ", terminator: " ") +//let num2 = Int(readLine()!)! +//print("3과목 데이터베이스 구축: ", terminator: " ") +//let num3 = Int(readLine()!)! +//print("4과목 프로그래밍 언어 활용: ", terminator: " ") +//let num4 = Int(readLine()!)! +//print("5과목 정보시스템 구축관리: ", terminator: " ") +//let num5 = Int(readLine()!)! +// +//var score = num1 + num2 + num3 + num4 + num5 +// +//if num1 < 8 { +// print("불합격입니다.") +//}else if num2 < 8 { +// print("불합격입니다.") +//}else if num3 < 8 { +// print("불합격입니다.") +//}else if num4 < 8 { +// print("불합격입니다.") +//}else if num5 < 8 { +// print("불합격입니다.") +//}else if score < 60 { +// print("불합격입니다.") +//}else{ +// print("합격입니다.") +//} + +//MARK: - + +/////디즈니랜드 입장료 +//print("나이를 입력해주세요: " , terminator: " ") +//let age = Int(readLine()!)! +//print("인원 수를 입력해주세요: " , terminator: " ") +//let num = Int(readLine()!)! +// +//var price : Int = 5000 +// +//if num > 1 { +// price = num * price +// print(price) +//}else if age < 18{ +// price = (price / 2) * num +// print(price) +//}else{} + +//MARK: - + +/////마트 계산대 +//print("구매하려는 상품 개수를 입력해주세요: ", terminator: " ") +//let num = Int(readLine()!)! +// +//var price = 10000 +// +//if num >= 11 { +// price = (num * price) - ((num * price)/10) //0.9를 곱해도 가능 +//// price = Int(Double(price)*0.9) * num +// print(price) +//}else { +// price = price * num +// print(price) +//} + +//MARK: - + +////input 함수 +//func inputLine(_ message: String) -> Int{ +// print(message, terminator: " ") +// return Int(readLine()!)! +//} +// + +//MARK: - + +////조건문 예제 9 학점출력 +// +//let grade = inputLine("grade를 입력해주세요 ") +// +//if grade > 90 { +// print("A학점입니다.") +//}else if grade > 80 && grade < 90{ +// print("B학점입니다.") +//}else{ +// print("C학점입니다.")} + + + + +//MARK: --- + +////지훈님 풀이 +//func inputLine(_ message: String) -> Int{ +// print(message,terminator: " ") +// return Int(readLine()!)! +//} +// var flag:Bool = true +// +// var A = inputLine("1과목 소프트웨어 설계") +// if A <= 8 && flag {flag=false} +// A = inputLine("2과목 소프트웨어 개발") +// if A <= 8 && flag {flag=false} +// A = inputLine("3과목 데이터베이스 구축") +// if A <= 8 && flag {flag=false} +// A = inputLine("4과목 프로그래밍 언어 활용") +// if A <= 8 && flag {flag=false} +// A = inputLine("5과목 정보시스템 구축관리") +// if A <= 8 && flag {flag=false} +// +// flag ? print("합격입니다."):print("불합격입니다.") + + diff --git a/lecture/23.09.22.swift b/lecture/23.09.22.swift new file mode 100644 index 0000000..aba43ee --- /dev/null +++ b/lecture/23.09.22.swift @@ -0,0 +1,341 @@ +// Created by 박선구 on 2023/09/23. +// 23.09.22 수업예제 + +import Foundation + +//MARK: - + +//// 조건문 예제 12번 +//// 월을 입력받아 봄, 여름, 가을, 겨울 중 맞는 계절을 알려주는 프로그램을 만드세요 +// +//print("월 입력: ", terminator: " ") +//let month = Int(readLine()!)! +// +//if month == 12 || month == 1 || month == 2{ +// print("\(month)월은 겨울입니다") +//}else if month == 3 || month == 4 || month == 5 { +// print("\(month)월은 봄입니다.") +//}else if month == 6 || month == 7 || month == 8 { +// print("\(month)월은 여름입니다.") +//}else if month == 9 || month == 10 || month == 11{ +// print("\(month)월은 가을입니다.") +//}else{ +// print("!!월을 적어주세요!!") +//} + +//MARK: - + +//// 조건문 예제 13번, 14번 +//// 금액을 입력하고 메뉴를 고른 뒤 잔돈을 출력 +//// 입력한 금액이 선택한 메뉴의 가격보다 부족하면 돈이 부족하다는 문장을 출력하세요. + +//print("금액을 입력해주세요: ", terminator: " ") +//let pay = Int(readLine()!)! +//var money = 0 +// +//if pay < 500 { +// print("구매가능한 메뉴가 없습니다.") +//}else{ +// print("메뉴를 입력해주세요.", "1. 콜라(800원)", "2. 생수(500원)", "3. 비타민워터(1500원)") +// let menu = Int(readLine()!)! +// +// switch menu { +// case 1: +// if pay > 800 { +// money = pay - 800 +// print("잔돈: \(money)원") +// }else{ +// print("구매하실 수 없습니다.") +// } +// case 2: +// print("잔돈: \(pay - 500)원") +// case 3: +// if pay > 1500 { +// money = pay - 1500 +// print("잔돈: \(money)원") +// }else{ +// print("구매하실 수 없습니다.") +// } +// default: +// print("오류") +// } +//} + +//MARK: - + +//// 조건문 예제 15 +//// 잔돈을 줄때 천원, 오백원, 백원을 몇 개 줘야 하는지 계산해보세요 + +//print("금액을 입력해주세요: ", terminator: " ") +//let pay = Int(readLine()!)! +//var money = 0 +// +//if pay < 500 { +// print("구매가능한 메뉴가 없습니다.") +//}else{ +// print("메뉴를 입력해주세요.", "1. 콜라(800원)", "2. 생수(500원)", "3. 비타민워터(1500원)") +// let menu = Int(readLine()!)! +// +// switch menu { +// case 1: +// if pay > 800 { +// money = pay - 800 +// var m1000 = money / 1000 +// var x = money % 1000 +// var m500 = x / 500 +// var y = x % 500 +// var m100 = y / 100 +// print("잔돈: \(money)") +// print("천원지폐: \(m1000)장, 500원: \(m500)개, 100원: \(m100)개") +// }else{ +// print("구매하실 수 없습니다.") +// } +// case 2: +// if pay > 500 { +// money = pay - 500 +// var m1000 = money / 1000 +// var x = money % 1000 +// var m500 = x / 500 +// var y = x % 500 +// var m100 = y / 100 +// print("잔돈: \(money)") +// print("천원지폐: \(m1000)장, 500원: \(m500)개, 100원: \(m100)개") +// }else{ +// print("구매하실 수 없습니다.") +// } +// case 3: +// if pay > 1500 { +// money = pay - 1500 +// var m1000 = money / 1000 +// var x = money % 1000 +// var m500 = x / 500 +// var y = x % 500 +// var m100 = y / 100 +// print("잔돈: \(money)") +// print("천원지폐: \(m1000)장, 500원: \(m500)개, 100원: \(m100)개") +// }else{ +// print("구매하실 수 없습니다.") +// } +// default: +// print("오류") +// } +//} + + +//MARK: - +// +//// 조건문 예제 15, 16 자판기 문제 +//// 추가본 + +//print("금액을 입력해주세요: ", terminator: " ") +//let pay = Int(readLine()!)! +// +//func getchange(_ money: Int) -> (Int, Int, Int){ +// var t = money / 1000 +// var fh = money % 1000 / 500 +// var h = money % 1000 % 500 / 100 +// print("천원: \(t)장, 오백원: \(fh)개, 백원: \(h)개") +// return (t, fh, h) +//} +// +// +//var money = 0 +// +//if pay < 500 { +// print("구매가능한 메뉴가 없습니다.") +//}else{ +// print("메뉴를 입력해주세요.", "1. 콜라(800원)", "2. 생수(500원)", "3. 비타민워터(1500원)") +// let menu = Int(readLine()!)! +// +// switch menu { +// case 1: +// if pay > 800 { +// money = pay - 800 +// getchange(money) +// print("잔돈: \(money)") +// }else{ +// print("구매하실 수 없습니다.") +// } +// case 2: +// if pay > 500 { +// money = pay - 500 +// getchange(money) +// print("잔돈: \(money)") +// }else{ +// print("구매하실 수 없습니다.") +// } +// case 3: +// if pay > 1500 { +// money = pay - 1500 +// getchange(money) +// print("잔돈: \(money)") +// }else{ +// print("구매하실 수 없습니다.") +// } +// default: +// print("오류") +// } +//} + +//MARK: - + +//// Sring 타입의 변수 data를 선언하고 키보드로 값을 입력 받으세요 +//// switch ~ case 문 사용 + +//(다시 해보기) +//대답하는 기계 (경헌님 코드) + +//func inputLineString(_ message: String) -> String{ +// print(message, terminator: " ") +// return String(readLine()!) +//} + +////let hi = inputLineString("user:") + +//print("입력: ",terminator: "") +//let greeting = (readLine()) +// +//switch greeting { +//case "hello": +// print("mac: 네, 안녕하세요!") +//case "nice meet you.": +// print("mac: 네, 반가워요!") +//case "bye": +// print("mac: 네, 수고하세요.") +//default: +// print("mac: ?") +//} + +//MARK: - + +//// while 예제 1 +//// while문을 사용하여 키보드로부터 입력 받은 수가 10보다 작을 때만 계속 정수를 입력 받으세요. + +//var numIn = 0 +// +//while numIn < 10 { +// print("정수입력: ", terminator: "") +// numIn = Int(readLine()!)! +//} +//print("종료되었습니다.") + +//MARK: - + +//// while 에졔 2 +//// 다이어트 관리 프로그램 +//// 현재 몸무게와 목표 몸무게를 입력 받고 주차 별 감량 몸무게를 입력 받으세요 +//// 목표 몸무게를 달성하면 축하한다는 문구를 출력 하고 입력을 멈추세요! + +//print("현재 몸무게: ", terminator: "") +//var pWeight = Int(readLine()!)! +// +//print("목표 몸무게: ", terminator: "") +//let fWeight = Int(readLine()!)! +// +//var weak = 0 +// +//while pWeight > fWeight { +// weak += 1; +// print("\(weak)주차 감량 몸무게: ", terminator: "") +// var mWeight = Int(readLine()!)! +// +// pWeight = pWeight - mWeight +// +// if pWeight <= fWeight { +// break +// } +// +//} +//print("\(pWeight)kg 달성! 축하합니다!") + +//MARK: - + +//// while문 예제 3, 4번 +//// 로그인이 실패했을 경우에 계속 입력, 성공하면 종료 +//// +// +//let userID : String = "Hello" +//let password : Int = 1234 +// +//while true{ +// print("userID: ", terminator: "") +// let inputUserID = (readLine()!) +// print("password: ", terminator: "") +// let inputPassword = Int(readLine()!)! +// +// if inputUserID == userID && inputPassword == password { +// print("로그인 성공!") +// break +// }else{ +// print("아이디 또는 비밀번호가 잘못되었습니다.") +// } +//} + +//MARK: - + +////while 예제5 LOGIN 프로그램 +//// (아이디와 비밀번호가 틀렸을 경우 "계속 하시겠습니까?" 라는 문장을 출력) +// +//let userID : String = "Hello" +//let password : Int = 1234 +// +//while true{ +// print("ID를 입력해 주세요: ", terminator: "") +// let inputUserID = (readLine()!) +// print("비밀번호를 입력해 주세요: ", terminator: "") +// let inputPassword = Int(readLine()!)! +// +// if inputUserID == userID && inputPassword == password { +// print("로그인 성공!") +// break +// }else{ +// print("아이디 또는 비밀번호가 잘못되었습니다.") +// print("계속 하시겠습니까? (Y/N) : ", terminator: "") +// let answer = (readLine()!) +// if answer == "Y" { +// continue +// }else if answer == "N"{ +// break +// } +// } +//} + +//MARK: - + +//// while문 예제 6번 계산기 프로그램 +////두 정수를 입력받고 연산하기, 결과 출력 후 "계속 하시겠습니까?"를 출력 +////Yes 와 No 중, Yes면 반복문 다시실행 +// +//while true { +// print("첫 번째 정수를 입력하세요: ", terminator: "") +// let num1 = Int(readLine()!)! +// print("두 번째 정수를 입력하세요: ", terminator: "") +// let num2 = Int(readLine()!)! +// +// print("1.더하기 2.빼기 : ", terminator: "") +// let sm = Int(readLine()!)! +// +// switch sm { +// case 1: +// var sum : Int = 0 +// sum = num1 + num2 +// print("더하기 연산 결과는 \(sum)입니다.") +// case 2: +// var minus : Int = 0 +// minus = num1 - num2 +// print("빼기 연산 결과는 \(minus)입니다.") +// default: +// print("종료되었습니다.") +// } +// print("다시 실행 하시겠습니까? (Y/N) : ", terminator: "") +// let answer = String(readLine()!) +// if answer == "Y" { +// print("\n"); continue +// }else if answer == "N"{ +// break +// }else{ +// break +// } +//} + + diff --git a/lecture/23.09.25.swift b/lecture/23.09.25.swift new file mode 100644 index 0000000..7b79837 --- /dev/null +++ b/lecture/23.09.25.swift @@ -0,0 +1,506 @@ +// Created by 박선구 on 2023/09/25. + +import Foundation + +//MARK: - + +//MARK: 랜덤숫자게임 + +//var fn = Int.random(in: 0...20) +//var sn = Int.random(in: 0...20) +//var sum = fn + sn +// +//print("== Plus Game ==") +// +//print("\(fn) + \(sn) = ", terminator: "") +//let num = Int(readLine()!)! +// +//if sum == num { +// print("Success!") +//}else{ +// print("Fail!") +//} + +//MARK: - + +//MARK: 랜덤숫자 게임 7-1 + + + +// var fn = Int.random(in: 0...20) +// var sn = Int.random(in: 0...20) +// var sum = fn + sn +// +// print("== Plus Game ==") +// +//while true{ +// print("\(fn) + \(sn) = ", terminator: "") +// let num = Int(readLine()!)! +// +// if sum == num { +// print("Success!") +// print("계속 하시겠습니까? (Y/N): ", terminator: "") +// let play = readLine() +// if play == "N" { +// break +// } +// }else{ +// print("Fail!") +// print("계속 하시겠습니까? (Y/N): ", terminator: "") +// let play = readLine() +// if play == "N" { +// break +// } +// } +//} +//MARK: - + +//MARK: 랜덤숫자게임 7-2 (다시하기) + +//while true { +// var fn = Int.random(in: 0...20) +// var sn = Int.random(in: 0...20) +// var sum = fn + sn +// +// print("== Plus Game ==") +// +// print("\(fn) + \(sn) = ", terminator: "") +// let num = Int(readLine()!)! +// +// switch sum == num { +// case true : print("Success!") +// print("계속 하시겠습니까? (Y/N): ", terminator: "") +// let play = readLine() +// if play == "Y" { +// break +// } +// case false : print("Fail!") +// print("계속 하시겠습니까? (Y/N): ", terminator: "") +// let play = readLine() +// if play == "Y" { +// print("\(fn) + \(sn) = ", terminator: "") +// let num = Int(readLine()!)! +// }else { +// break +// } +// } + +// if sum == num { +// print("Success!") +// }else{ +// print("Fail!") +// } +// print("계속 하시겠습니까? (Y/N): ", terminator: "") +// let play = readLine() +// +// if play == "Y" { +// print("\n") +// continue +// }else{ +// break +// } +//} + + +//MARK: - + +//MARK: 랜덤숫자게임 7-2 + +//while true { +// var fn = Int.random(in: 0...20) +// var sn = Int.random(in: 0...20) +// var sum = fn + sn +// +// print("== Plus Game ==") +// +// print("\(fn) + \(sn) = ", terminator: "") +// let num = Int(readLine()!)! +// +// if sum == num { +// print("Success!") +// }else{ +// print("Fail!") +// } +// print("계속 하시겠습니까? (Y/N): ", terminator: "") +// let play = readLine() +// +// if play == "Y" { +// print("\n") +// continue +// }else{ +// break +// } +//} + +//MARK: - + +//MARK: for 문 00 +// +//for i in 53...96 { +// print(i) +//} + +//for 문 00-1 + +//let j = 21...57 +// +//for a in j where a % 2 != 0{ //where를 이용하여 조건을 넣는다. +// print(a) +//} +// + +//for 문 00-2 + + +//1~100까지 3의 배수의 합을 출력하세요. (1683) +//var num = 0 +//for i in 1...100 { +// if i % 3 == 0 { +// num += i +// } +//} +//print(num) + + +//MARK: - + + +//MARK: for 문 3 + +//for i in 1...9 { +// print("2 * \(i) = \(2 * i)") +//} + +//MARK: - + +//MARK: for 문 한 개의 자연수를 입력 받아 그 수의 배수를 차례로 10개 출력하는 프로그램을 작성하시오. + +//print("정수 입력: ", terminator: "") +//let num = Int(readLine()!)! +// +//var a = 1...10 +// +//for i in 1...10 { +// print("\(num * i)") +//} + +//MARK: - + +//let j = 21...57 +// +//for a in j where a % 2 != 0{ //where를 이용하여 조건을 넣는다. +// print(a) +//} +// +//for i in 21...57 { +// if i % 2 != 0 { +// print(i) +// } +//} + +//MARK: - + +//print("정수입력: ", terminator: "") +//let num = Int(readLine()!)! +// +//for i in 1...num { +// print(i) +//} + +//MARK: - + +//MARK: for문 예제 4 + +//print("정수 입력: ", terminator: "") +//let number = Int(readLine()!)! +// +//for a in 1...9{ +// print("\(number) * \(a) = \(number * a)") +//} + + +//MARK: - + +//MARK: for문 예제 5 + +//for a in 2...9{ +// print("\n===\(a)단===") +// for i in 1...9 { +// print("\(a) * \(i) = \(a * i)") +// } +//} + +//MARK: - + +//MARK: for문 예제 6 +// +//for a in 2...9{ +// print("\n\(a)단: ", terminator: "") +// for i in 1...9 { +// print("\(a) * \(i) = \(a * i) ", terminator: " ") +// } +//} + +//MARK: - + +//MARK: for문 예제 7 + +//print("정수입력: ", terminator: "") +//let number = Int(readLine()!)! +// +//print("\(number)의 약수 : ", terminator: "") +//for q in 1...number { +// if number % q == 0 { +// print("\(q)", terminator: " ") +// if q == number { +// print("\n") +// } +// } +//} + +//MARK: - + +//MARK: for문 예제 8 + +//for i in 2...30 { +// print("\n\(i)의 약수: ", terminator: "") +// for a in 1...30 { +// if i % a == 0 { +// print(a ,terminator: " ") +// if a == 30 { +// print("\n") +// } +// } +// } +//} + +//MARK: - + +//MARK: for 예제 9-1 +// +//var p = 0 +// +//for _ in 1...5{ +// print("") +// p += 1 +// for i in 1...p { +// print("*", terminator: "") +// if i == 5 { +// print("\n") +// } +// } +//} + +//MARK: - + +//MARK: for문 예제 9-2 +// +//var p = 5 +// +//for some in 1...5{ +// print("") +// p -= 1 +// for _ in 0...p { +// print("*", terminator: "") +// if some == 5 { +// print("\n") +// } +// } +//} + +//MARK: - + +//MARK: for문 예제 9-3 +// +//var o = 5 +//var p = 0 +//var k = 1...6 +// +//for some in k{ +// print("") +// p += 1 +// o -= 1 +// for _ in 0...o { +// print(" ", terminator: "") +// } +// for _ in 1...p { +// print("*", terminator: "") +//// if some == 5 { +//// print("\n") +//// } +// } +//} + + +//MARK: - +//MARK: 별찍기 1 (수정) + +// +//for i in (1...5).reversed() { +// print("") +// for _ in 1...i{ +// print("*", terminator: "") +// } +// for _ in 1...i{ +// print(" ", terminator: "") +// } +//} +//MARK: - +//MARK: 별찍기 2 (수정) + +//for i in (1...5).reversed() { +// print("") +// for _ in 1...i{ +// print("*", terminator: "") +// } +// for _ in 1...i{ +// print(" ", terminator: "") +// } +//} + +//MARK: - +//MARK: 별찍기3 (수정) + +//for i in (1...5).reversed() { +// print("") +// for _ in 1...i{ +// print(" ", terminator: "") +// } +// for _ in i...5{ +// print("*", terminator: "") +// } +//} + +//MARK: - +//MARK: 별찍기 다이아 (수정) + +//for i in (1...5).reversed(){ +// print("") +// for _ in 1...i{ +// print(" ", terminator: "") +// } +// for _ in i...5{ +// print("*", terminator: "") +// } +// for _ in i...5{ +// print("*", terminator: "") +// } +//} +// +//for i in 1...5 { +// print("") +// for _ in 1...i{ +// print(" ", terminator: "") +// } +// for _ in (i...5).reversed() { +// print("*", terminator: "") +// } +// for _ in i...5 { +// print("*", terminator: "") +// } +// +//} +//print("\n") + + +//MARK: - + +//MARK: 369 게임 (다시하기) + +//for i in 0...99{ +// print(i) +// while i % 3 == 0 { +// print("*") +// }break +//} + +//MARK: - +// 창준님 코드 + +//func forExercise10() { +// for num in 0...99 { +// var strNum = String(format: "%02d", num) +// var tmp = "" +// for s in strNum { +// if let intS = Int(String(s)), intS != 0, intS % 3 == 0 { +// tmp += "*" +// } +// } +// strNum += tmp +// tmp = "" +// print(strNum) +// } +//} + +//MARK: - + +// 경헌님 코드 + +for i in 0...9 { + for j in 0...9 { + // 여기서 부터 + print("\(i)\(j)", terminator: "") + var cnt = 0 + if (i != 0 && i % 3 == 0) { + cnt += 1 + } + + if (j != 0 && j % 3 == 0) { + cnt += 1 + } + + for _ in 0.. Int { +// fm + sm +//} +// +// +//print("1번째 수: ", terminator: "") +//var a = Int(readLine()!)! +//print("2번째 수: ", terminator: "") +//var b = Int(readLine()!)! +// +//print("연산결과: \(addNumber(fm: a, sm: b))") + +//MARK: - +//MARK: 함수예제 2 + +//func largerNumbers(fm : Int, sm : Int) { +// if fm > sm { +// return print("결과확인: ",fm) +// }else if fm == sm{ +// return print("0") +// }else { +// return print("결과확인: ",sm) +// } +//} +// +//print("1번째 수: ", terminator: "") +//let a = Int(readLine()!)! +//print("2번째 수: ", terminator: "") +//let b = Int(readLine()!)! +// +//largerNumbers(fm: a, sm: b) + +//MARK: - +//MARK: 함수예제 2 (강사님ver) + +//func largerNumbers (a: Int , b: Int) -> Int{ +// if a == b { +// return 0 +// } +// return a > b ? a : b +//} +// +//print("1번째 수: ", terminator: "") +//let a = Int(readLine()!)! +//print("2번째 수: ", terminator: "") +//let b = Int(readLine()!)! +// +//let c = largerNumbers(a: a, b: b) +//print("큰 수 확인: \(c)") + +//MARK: - +//MARK: 함수예제 3 + +//func close10(num1 : Int, num2 : Int) { +// if abs(10 - num1) > abs(10 - num2) { +// return print("10에 가까운 수: \(num2)") +// }else if abs(10 - num1) == abs(10 - num2) { +// return print("10에 가까운 수: 0") +// }else{ +// return print("10에 가까운 수: \(num1)") +// } +//} +// +//print("1번째 수: ", terminator: "") +//let a = Int(readLine()!)! +//print("2번째 수: ", terminator: "") +//let b = Int(readLine()!)! +// +//close10(num1: a, num2: b) + +//MARK: - +//MARK: 함수예제 4 + +//func powerN(base: Int, n: Int) { +// var result = 0 +// +// result = Int(pow(Float(base), Float(n))) //pow = 제곱 +// return print("결과 확인: \(result)") +//} +// +//print("1번째 수: ", terminator: "") +//let a = Int(readLine()!)! +//print("2번째 수: ", terminator: "") +//let b = Int(readLine()!)! +// +//powerN(base: a, n: b) + +//MARK: - +//MARK: 함수예제 5 + +//func getAbsoluteValue(num1 : Int, num2 : Int) { +// var result = 0 +// result = num1 - num2 +// return print("결과 확인: \(abs(result))") +//} +// +//print("1번째 수: ", terminator: "") +//let a = Int(readLine()!)! +//print("2번째 수: ", terminator: "") +//let b = Int(readLine()!)! +// +//getAbsoluteValue(num1: a, num2: b) + +//MARK: - +//MARK: 함수예제: 6 +//두 개의 정수를 인자(매개변수)로 넘겨받아 앞의 정수가 뒤의 정수로 나누어지는지를 판별하는 isDivide( ) 를 작성하세요. + +//func isDivide(a : Int, b : Int) -> Bool{ +// if b == 0{ +// return false +// } +// return (a % b == 0) +//} +//print("1번째 수: ", terminator: "") +//let a = Int(readLine()!)! +//print("2번째 수: ", terminator: "") +//let b = Int(readLine()!)! +// +//let c : Bool = isDivide(a: a, b: b) + + +//MARK: - +//MARK: 함수예제 7 (보충필요) +//약수를 구하는 getDivisor() 를 구현하세요 + +//func getDivisor(num : Int) { +// print("\(num)의 약수: ", terminator: "") +// for q in 1...num { +// if num % q == 0 { +// print("\(q)", terminator: " ") +// if q == num { +// print("\n") +// } +// } +// } +//} +// print("정수입력: ", terminator: "") +// let a = Int(readLine()!)! +// +// getDivisor(num: a) +// +// +// +//MARK: - +//MARK: 함수예제 7 (강사님ver) + +//func getDivisor (a: Int) -> String { +// var str = "\(a)의 약수: " +// for i in 1...a { +// if isDivide(a: a, b: i) { +// str += "\(i) " +// } +// } +// return str +//} +// +//print("정수 입력: ", terminator: "") +//let a = Int(readLine()!)! +// +//let c: String = getDivisor(a: a) +//print(c) + +//MARK: - +//MARK: 함수예제 8 (강사님Ver) +//func getSumofDivisors(a: Int) -> Int { +// var sum = 0 +// for i in 1...a { +// if isDivide(a: a, b: i) { +// sum += i +// } +// } +// return sum +//} + +//let a: Int = 10 +// +//let c: Int = getSumofDivisors(a: a) +//print("\(a)의 약수의 합: \(c)") + +//MARK: - +//MARK: 함수예제 9 (보충필요) +//startValue...endValue까지의 숫자 중 완전수를 출력하는 getPerfectNumber() 를 구현하세요 +//완전수 = 자신을 제외한 약수들의 합이 자신인 것 +// +//let a: Int = 100 +//let b: Int = 41 +// +//var str = "" +//for i in 2...1000{ +// let c: Int = getSumofDivisors(a: i) +// if c - a == a{ +// str += "\(i) " +// } +//} +//print(str) + +//MARK: - +//MARK: 함수예제 10 + +//권지원님 코드 +//func getPrimeNumber(first: Int, last: Int) { +// print("\(first)~\(last)까지의 소수: " ,terminator: "") +// for i in first...last { +// var result = "F" +// if i == 2 { +// +// } else { +// for j in 2...(i-1) { +// if i % j == 0 { +// result = "T" +// break +// } +// } +// } +// if result == "F" { +// print(i, terminator: " ") +// } +// } +// print() +//} +// +//getPrimeNumber(first: 2, last: 30) + +//MARK: - +//MARK: 클래스 + +//class piggbank { +// var bank = 0 +// func inputMoney(money: Int) -> Int { //입금 +// showMoney() +// if money > 0 { +// bank += money +// return bank +// }else{ +// return bank +// } +// } +// func outputMoney(bMoney: Int) -> String { //출금 +// showMoney() +// if bMoney > 0 && bank > bMoney{ +// bank -= bMoney +// return String(bank) +// }else if bank < bMoney{ +// return "잔액이 부족합니다." +// }else{ +// return String(0) +// } +// } +// func showMoney(){ //현재 잔액 +// print("현재 잔액: \(bank)") +// } +//} +// +//let a : Int = 15000 +//let b : Int = 9000 +// +//let myBank = piggbank() +//print("입금:\(a), 현재잔액: \(myBank.inputMoney(money: a))\n") +//print("출금:\(b), 현재잔액: \(myBank.outputMoney(bMoney: b))\n") + +//MARK: - +//MARK: 객체를 이용하여 입력된 학생의 정보를 출력하기 + +//let student1 = Student(name: "홍길동", number: "20200677", age: 22, scoreSwift: 50, scoreiOS: 89, scoreWeb: 77) +//let student2 = Student(name: "김영희", number: "20190541", age: 26, scoreSwift: 90, scoreiOS: 85, scoreWeb: 70) +// +//class Student { +// var name: String +// var number: String +// var age: Int +// var scoreSwift: Int +// var scoreiOS: Int +// var scoreWeb: Int +// +// init(name: String, number: String, age: Int, scoreSwift: Int, scoreiOS: Int, scoreWeb: Int) { +// self.name = name +// self.number = number +// self.age = age +// self.scoreSwift = scoreSwift +// self.scoreiOS = scoreiOS +// self.scoreWeb = scoreWeb +// } +// func show() { +// print("\(name)님 안녕하세요") +// print("[ \(number), \(age)살 ]") +// print("\(name)님의 Swift 점수는 \(scoreSwift)점 입니다.") +// print("\(name)님의 iOS 점수는 \(scoreiOS)점 입니다.") +// print("\(name)님의 Web 점수는 \(scoreWeb)점 입니다.") +// print("=======================================\n") +// } +//} +// +//student1.show() +//student2.show() diff --git a/lecture/23.10.04.swift b/lecture/23.10.04.swift new file mode 100644 index 0000000..3e9d392 --- /dev/null +++ b/lecture/23.10.04.swift @@ -0,0 +1,538 @@ +// Created by 박선구 on 2023/09/27. + +import Foundation + + +//MARK: - +//MARK: 0927 +//MARK: 객체지향 class 예제 1 (강사님 ver) +// 예제 1번 + +class Student { + var name: String = "" + var number: String = "" + var age: Int = 0 + var scoreSwift: Int = 0 + var scoreiOS: Int = 0 + var scoreWeb: Int = 0 + + func show() -> String{ + return "\(name)" + } +} + +//예제 2번 +let student1: Student = Student() +student1.name = "홍길동" +student1.number = "20200677" +student1.age = 22 +student1.scoreSwift = 50 +student1.scoreiOS = 89 +student1.scoreWeb = 77 + +let student2: Student = Student() +student2.name = "김영희" +student2.number = "20190541" +student2.age = 26 +student2.scoreSwift = 90 +student2.scoreiOS = 85 +student2.scoreWeb = 70 + +//예제 3번 +//print(student1.show()) +//print("=============") +//print(student2.show()) + + +//MARK: - +//MARK: class 예제 4 (강사님 ver) + +class Person { + private var name : String //private 외부에서 변수에 접근하는것을 방지 (접근제한자) + private var age : Int + + init() { //default값을 만들어보기 (오버로딩) + name = "이름없음" + age = 0 + } + + init(name: String, age: Int) { + self.name = name + self.age = age + } + + func getName() -> String { + return name + } + + func setName(name: String) { + self.name = name + } + func getAge() -> Int{ + return age + } + func setAge(age: Int) { + self.age = age + } + func show() -> String{ + return "이름: \(name), 나이: \(age)" + } +} + +//예제 4-1 +let st0 = Person() //Default값 (오버로딩) +let st1 = Person(name: "홍길동", age: 25) //init을 사용했기 때문에 따로 초기화를 해줘야 한다. +let st2 = Person(name: "김영희", age: 27) + +//print("(st1 객체 학생) \(st1.show())") +//print("(st2 객체 학생) \(st2.show())") +//print("(st 객체 학생) \(st0.show())") + +//MARK: - +//예제 5 + + + +//MARK: class 예제 5-1 (강사님 ver) + +class Calculator { + var num1 : Int + var num2 : Int + init() { + num1 = 0 + num2 = 0 + } + init(num1: Int, num2: Int) { + self.num1 = num1 + self.num2 = num2 + } + func sum() -> Int { + return num1 + num2 + } + func sub() -> Int{ + return num1 - num2 + } + func div() -> Int{ + return num1 / num2 + } + func mul() -> Int{ + return num1 * num2 + } + func setNum1(num1: Int) { + self.num1 = num1 + } + func setNum2(num2: Int) { + self.num2 = num2 + } +} + +let cal = Calculator(num1: 2, num2: 7) +cal.setNum1(num1: 10) +cal.setNum2(num2: 20) +let sum : Int = cal.sum() +let c = cal.sub() +//print(sum, c, cal.mul(), cal.div()) + +//MARK: - +//MARK: class 예제 06 + +class TV { + var name: String + var year: Int + var size: Int + + init(name: String, year: Int, size: Int) { + self.name = name + self.year = year + self.size = size + } + + func show() -> String{ + return "\(name)에서 만든 \(year)년형 \(size)인치 TV" + } +} + +let myTv = TV(name: "LG", year: 2023, size: 48) +//print(myTv.show()) + +//MARK: - +//MARK: class 별찍기 + +class makeStar { + func reverStar() { + for i in (1...10).reversed(){ + print("") + for _ in 1...i{ + print(" ", terminator: "") + } + for _ in i...10{ + print("*", terminator: "") + } + for _ in i...10{ + print("*", terminator: "") + } + } + } + func Star() { + for i in 1...10 { + print("") + for _ in 1...i{ + print(" ", terminator: "") + } + for _ in i...10 { + print("*", terminator: "") + } + for _ in i...10 { + print("*", terminator: "") + } + + } + } +} + +let star = makeStar() +//star.reverStar() +//star.Star() +//print("\n") + +//MARK: - +//MARK: class 별찍기 (강사님 ver) +class Shape { + var size : Int = 1 + + init(size: Int) { + self.size = size + } + + func printShape(start: Int, end: Int, shape: String) -> String{ + var result: String = "" + for _ in start...end { + result += shape + } + return result + } + func drawShape() -> String{ + var str = "" + for i in 1...size { + str = printShape(start: 1, end: i, shape: "*") + "\n" + } + return str + } + + func invdrawShape() -> String { + var str = "" + for i in (1...size).reversed() { + str = printShape(start: 1, end: i, shape: "*") + "\n" + } + return str + } +} + +let shape = Shape(size: 10); +//print(shape.drawShape() + shape.invdrawShape()) + +//MARK: - +//MARK: 배열 + +var items = [8,9,10,11,12,15] //배열 생성 + +var sumItems = 0 +for i in items { //items의 전체 합 + sumItems += i +} + +print(sumItems) + +//배열 인덱스의 항목위치를 참조하여 접근 +items[0] = 10 //0번째 배열에 10넣기 +print("0번째 인덱스의 값은: ",items[0]) //0번째 + +//문자열을 갖는 배열 +var strArray: [String] = ["nice", "to", "meet", "you"] + + +//빈배열 생성 +//var 변수명: [타입] = [] +//var 변수명 = [타입]() + + +//기본값과 크기를 미리 설정하여 초기화 +var nameArray = [String](repeating: "no Name", count: 10 ) +print("nameArray 배열 항목 개수: ",nameArray.count) +print("nameArray 빈배열인가?: ",nameArray.isEmpty) + +// 배열을 결합하여 새로운 배열 생성 : 같은 타입이라고 가정 +print(strArray + nameArray) + +// 배열 항목 섞기 +let shuffledArray = strArray.shuffled() +print(strArray) //섞기 전 +print(shuffledArray) //섞은 후 + +//배열 항목 무작위 접근 +print(strArray.randomElement()!) + +//배열에 항목 추가하기 +strArray.append("PLEASE") +print(strArray) + +strArray += ["HEY", "What"] +print(strArray) + +// 배열 항목을 특정 위치에 추가 +strArray.insert("jkl", at: 0) +print("strArray의 0번째 위치에 jkl 추가:", strArray) + +// 배열 항목 삭제 +// 배열 인덱스 위치에서 삭제 +print( strArray.remove(at: 0) ) +print("strArray의 0번째 위치 항목 삭제:", strArray) + +// 배열 마지막 항목 삭제 +print( strArray.removeLast() ) + +// 배열 모두 삭제 +print( strArray.removeAll() ) +print( strArray ) +print("=====================\n") + + +//MARK: - +//MARK: 배열 예제 1 + +// 1.정수형 데이터를 담을 수 있는 배열 array를 선언하세요 +// 2.정수형 데이터 10개를 담을 수 있도록 array배열을 생성하세요 +// 3.각각의 인덱스에 1~20까지의 랜덤수를 초기화하세요 +// 4.배열array의 각각에 인덱스에 들어있는 모든 데이터를 출력하세요. +// 5.4번째 인덱스에 들어있는 값과 9번째 인덱스에 들어있는 값을 더하여 결과 값을 출력하세요 +// 6.각각의 인덱스에 들어있는 데이터를 모두 더하여 결과 값을 출력하세요 +// 7.배열 안에 있는 수의 평균을 구하여 출력하세요 + +var array : [Int] = [1,2,3,4,5,6,7,8,9,10] //1,2 + +for _ in 1...10 { //3 + let a = Int.random(in: 0...9) + let b = Int.random(in: 1...20) + array[a] = b +} +print(array) //4 +print(array[4] + array[9]) //4번째와 9번째의 합 //5 + +var sumArray = 0 +for i in array { //array의 전체 합 //6 + sumArray += i +} +print(sumArray) + +var avg: Float = Float(sumArray) / 10 //7 +print(avg) + +//MARK: - +//MARK: 배열 예제 2 +//배열의 값 중 짝수인 값이 몇 개인지 출력하는 프로그램을 작성하세요 + +//var p = array[0] % 2 +//var result = [Int]() +// +//for i in 0...9{ +// p = array[i] % 2 +// if p == 0 { +// result.append(array[i]) //append = 배열 항목 추가 +// } +//} +//print("array에 들어있는 짝수는 \(result)입니다.") + +//MARK: - +//MARK: 배열 예제 3 +//배열의 값 중 홀수인 값이 몇 개인지 출력하는 프로그램을 작성하세요 + +var p = array[0] % 2 +var result = [Int]() + +for i in 0...9{ + p = array[i] % 2 + if p != 0 { + result.append(array[i]) + } +} +print("array에 들어있는 홀수는 \(result)이며, 총 \(result.count)개 입니다.") + + +//MARK: - +//MARK: 배열 예제 4 +//배열의 값 중 가장 큰 값을 찾아 출력하는 프로그램을 작성하세요 + +let maxArray = array.max()! //max는 배열안에 있는 값중 최댓값을 찾는다. +print("가장 큰 값은 \(maxArray)입니다.") + +//MARK: - +//MARK: 배열 예제 5 +//배열의 값 중 가장 작은 값을 찾아 출력하는 프로그램을 작성하세요 + +let minArray = array.min()! //min은 배열안에 있는 값중 최솟값을 찾는다. +print("가장 작은 값은 \(minArray)입니다.") + +//MARK: - +//MARK: 배열 예제 6 (다시해보기) +//숫자를 입력받아 짝수인 4의 경우 “수박수박”, 홀수인 3의 경우 “수박수“ 를 출력하는 프로그램을 작성하세요 + +//var stArray : [String] = ["수","박"] +//print("=== 수박 게임 시작! ===") +//print("숫자를 입력해주세요: ", terminator: "") +//let number = Int(readLine()!)! +// +//var resArr = "" +// +//for i in 1...number { +// let indexArray = (i - 1) % 2 // 짝수면 0 홀수면 1 저장 +// resArr += stArray[indexArray] // +//} +//print(resArr) + +//MARK: - +//MARK: 배열 예제 7 +//1차원 정수형 배열을 선언한 후 10개의 공간으로 생성합니다 +//숫자를 입력 받아 3의 배수인 숫자를 출력하는 프로그램을 작성하세요 + +//var array7 = [Int](repeating: 0, count: 10) +//var result7 = [Int]() +// +// +//for i in 1...10{ +// print("\(i)번째 정수 입력: ", terminator: "") +// let inputNum = Int(readLine()!)! +// array7.remove(at: i-1) +// array7.insert(inputNum, at: i-1) +// +// var num7 = array7[i-1] % 3 +// if num7 == 0{ +// result7.append(array7[i-1]) +// } +//} +// +//print("3의 배수:", terminator:" ") +//for j in result7 { +// print(j, terminator:" ") +//} +////print("3의 배수: \(result7.map {String($0)}.joined(separator: " "))") //또 다른 방법 + +//MARK: - +//MARK: 배열 예제 8 +//다음과 같이 정답이 있을 때 사용자로부터 답을 입력받아 결과를 출력하고 총점을 출력하는 프로그램을 작성하세요 + +//var answer8 : [Int] = [1, 1, 4, 2, 3] +//var myAnswer = [Int]() +//var point = 0 +// +//for i in 1...5{ +// print("\(i)번답: ", terminator: "") +// myAnswer.insert(Int(readLine()!)!, at: i-1) +//} +// +//for j in 1...5{ +// if answer8[j-1] == myAnswer[j-1] { +// print("O", terminator: " ") +// point += 20 +// }else{ +// print("X", terminator: " ") +// } +// if j == 5{ +// print("총점: \(point)") +// } +//} + +//MARK: - +//MARK: 배열 예제 9 +//배열의 (인덱스) 값 만큼 별을 출력해보세요 + +//var array9 : [Int] = [1,2,3,2,1] +var array9 = [Int]() + +print("입력 횟수: ", terminator: "") +let inputNum = Int(readLine()!)! + +for _ in 1...inputNum{ + print("별의 갯수 입력: ", terminator: "") + let stars = Int(readLine()!)! + array9.append(stars) +} + +for i in 1...array9.count { + print("") + print("\(array9[i-1]): ", terminator: "") + if array9[i-1] != 0 { + for _ in 1...array9[i-1] { + print("*", terminator: "") + } + } + if i >= array9.count { + print("\n") + } +} + +//MARK: - +//MARK: 스택 예제 1 (강사님 ver) +//func checkParentheses(_ input: String) -> Bool { +// +// var stack: [Character] = [] +// for char in input { +// if char == "(" || char == "{" || char == "["{ +// stack.append(char) +// } else if char == ")" || char == "}" || char == "]"{ +// if stack.isEmpty { +// return false +// } +// +// let top = stack.popLast() +// if (char == ")" && top != "(") || (char == "}" && top != "{") || (char == "]" && top != "[") { +// return false +// } +// } +// } +// +// return stack.isEmpty +//} +// +//print( checkParentheses("()()") ) +//print( checkParentheses("({[}])") ) +//print( checkParentheses("())(") ) +//print( checkParentheses("({}[()]())") ) + +//MARK: - +//MARK: 스택 예제 2 (강사님 ver) + +//func postFix(expression: String) -> Int{ +// +// +// let tokens = expression.split(separator: " ") //문자열을 잘라서 나눠주기 +// +// var stack = [String]() +// +// for token in tokens { +// if "+-*/".contains(token) { +// let right = Int(stack.popLast()!)! //꺼낸 것중 숫자 하나를 오른쪽에 배정 +// let left = Int(stack.popLast()!)! //꺼낸 것중 숫자 하나를 왼쪽에 배정 +// +// switch token { +// case "+": +// stack.append(String(right + left)) +// case "*": +// stack.append(String(right * left)) +// case "-": +// stack.append(String(right - left)) +// case "/": +// stack.append(String(right / left)) +// default: +// break +// } +// +// } else { +// stack.append(String(token)) +// } +// +// } +// +// return (Int(stack.popLast()!)!) +//} +// +//print(postFix(expression: "2 3 + 4 *")) diff --git a/lecture/Mentoring.swift b/lecture/Mentoring.swift new file mode 100644 index 0000000..7b430e0 --- /dev/null +++ b/lecture/Mentoring.swift @@ -0,0 +1,348 @@ +// Created by 박선구 on 2023/09/27. + +import SwiftUI + +// 텍스트 필드 밖 화면 터치 시 키보드 내림 +extension UIApplication { + func hideKeyboard() { + guard let window = windows.first else { return } + let tapRecognizer = UITapGestureRecognizer(target: window, action: #selector(UIView.endEditing)) + tapRecognizer.cancelsTouchesInView = false + tapRecognizer.delegate = self + window.addGestureRecognizer(tapRecognizer) + } + } + +extension UIApplication: UIGestureRecognizerDelegate { + public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { + return false + } +} + +struct ContentView: View { + + @State private var email : String = "" + @State private var password : String = "" + @State private var showPassword : Bool = false + @State private var validEmail : Bool = false + @State private var checkButton : Bool = true + @State private var isDisabled : Bool = false + @State private var loginFail : Bool = false + + //필드 포커스 + @FocusState private var focusedField: FormField? + +// @State private var currectEmail : String = "s1111@apple.com" +// @State private var currectPassword : String = "happyswift1!" + + var body: some View { + ZStack{ + ColorManager.BackgroundColor + .cornerRadius(40) + .padding(.bottom, -100) + .padding(.top, 50) + .shadow(radius: /*@START_MENU_TOKEN@*/10/*@END_MENU_TOKEN@*/) + VStack { + Spacer() + HStack{ + Text("Hello\nWorld !") + Spacer() + Text("") + } + .font(.system(size: 50)) + .fontWeight(.heavy) + .padding(.horizontal) + + + VStack{ //이메일 + HStack{ + Text("이메일") + Spacer() + Text("") + } + ZStack(alignment: .trailing){ + TextField(" 이메일을 입력해주세요", text: $email) + .keyboardType(.emailAddress) + .textInputAutocapitalization(.never) + .padding() + .background(Color.white) + .cornerRadius(15) + .overlay( + RoundedRectangle(cornerRadius: 15) + .stroke(fieldcheck(checkButton, email), lineWidth: 2) + ) + //포커스 필드 + .submitLabel(.next) + .focused($focusedField, equals: .email) + + if !email.isEmpty { + Image(systemName: checkButton == true ? "xmark" : "exclamationmark.circle") + .resizable() + .frame(width: 15, height: 15) + .padding() + .foregroundColor(checkButton == true ? .black : .red) + .symbolEffect(.bounce, value: checkButton) + .onTapGesture { + email = "" + } + } + } + +// .onAppear { +// UITextField.appearance().clearButtonMode = .whileEditing +// } //텍스트 필드 클리어 버튼 + + HStack{ + if email.isEmpty { + Text("Helper text") + .foregroundColor(checkButton == true ? .black : .red) + }else{ + Text(validEmail == false ? "Helper text" : "이메일을 올바르게 입력해 주세요") + .foregroundColor(validEmail == false ? .black : .red) +// Text(checkEmail(str: email) == true ? "Helper text" : "이메일을 올바르게 입력해주세요") +// .foregroundColor(checkButton == true ? .black : .red) + } + Spacer() + Text("") + } + } + .padding() + + + VStack{ //비밀번호 + HStack{ + Text("비밀번호") + Spacer() + Text("") + } + + ZStack(alignment: .trailing){ + + if showPassword == false{ + + SecureField(" 비밀번호를 입력해주세요", text: $password) + .keyboardType(.asciiCapable) + .textInputAutocapitalization(.never) + .padding() + .background(Color.white) + .cornerRadius(15) + .overlay( + RoundedRectangle(cornerRadius: 15) + .stroke(fieldcheck2(checkButton, password), lineWidth: 2) + ) + //포커스 필드 + .submitLabel(.done) + .focused($focusedField, equals: .password) + + }else{ + TextField(" 비밀번호를 입력해 주세요", text: $password) + .keyboardType(.asciiCapable) + .textInputAutocapitalization(.never) + .padding() + .background(Color.white) + .cornerRadius(15) + .overlay( + RoundedRectangle(cornerRadius: 15) + .stroke(fieldcheck2(checkButton, password), lineWidth: 2) + ) + //포커스 필드 + .submitLabel(.done) + .focused($focusedField, equals: .password) + + } + Image(systemName: showPassword == false ? "eye.slash" : "eye") + .resizable() + .frame(width: 20, height: 17) + .padding() + .onTapGesture { + if showPassword == false{ + showPassword = true + }else{ + showPassword = false + } + } + } + + HStack{ + Text(" ") + .frame(minWidth: 82, maxHeight: 2.5) + .background(CheckPassword().pwcheck4(password)) + Text(" ") + .frame(minWidth: 82, maxHeight: 2.5) + .background(CheckPassword().pwcheck3(password)) + Text(" ") + .frame(minWidth: 82, maxHeight: 2.5) + .background(CheckPassword().pwcheck2(password)) + Text(" ") + .frame(minWidth: 82, maxHeight: 2.5) + .background(CheckPassword().pwcheck1(password)) + } + .shadow(radius: 1) + + HStack{ + Text("Helper text") + .foregroundColor(checkButton == true ? .black : .red) + Spacer() + Text("") + } + } + .padding() + + Button(action: onButton, label: { + Text("로그인") + .font(.title2) + .fontWeight(/*@START_MENU_TOKEN@*/.bold/*@END_MENU_TOKEN@*/) + .frame(maxWidth: 350, maxHeight: 50) + }) + + .foregroundColor(.white) + .background(!email.isEmpty && CheckPassword().pwcheck2(password) == .orange && checkEmail(str: email) == true ? Color.blue : Color.gray) + .cornerRadius(10) + .disabled(CheckPassword().pwcheck2(password) == .orange && checkEmail(str: email) == true ? false : true) + + // 경고 + .alert(isPresented: $loginFail){ + Alert(title: Text("로그인 실패"), + message: Text("아이디 혹은 비밀번호가 맞지 않습니다"), + dismissButton: .default(Text("확인"))) + } + + Spacer() + Spacer() + + } + .frame(maxWidth: .infinity, maxHeight: .infinity) + } + + //키보드 내림 + .onAppear (perform : UIApplication.shared.hideKeyboard) + + //텍스트 필드 옮기기 (포커스필드) + .onSubmit { + switch focusedField { + case .email: + if checkEmail(str: email) == true{ + validEmail = false + focusedField = .password + }else{ + validEmail = true + } + case .password: + focusedField = nil + default: + focusedField = nil + } + } + + } + + // 버튼 + func onButton() { + + let currectEmail : String = "s1111@apple.com" + let currectPassword : String = "happyswift1!" + + if email == currectEmail && password == currectPassword{ + loginFail = false + return checkButton = true + }else{ + loginFail = true + return checkButton = false + } + } + + // 텍스트필드 테두리 색 (이메일) + func fieldcheck(_ checkButton : Bool, _ email : String) -> Color{ + + if checkButton == false { + return Color.red + }else if focusedField == .email { + return Color.black + }else if focusedField != .email{ + return Color.gray + }else{ + return Color.gray + } + } + + // 텍스트필드 테두리 색 (비밀번호) + func fieldcheck2(_ checkButton : Bool, _ password : String) -> Color{ + + if checkButton == false { + return Color.red + }else if focusedField == .password { + return Color.black + }else if focusedField != .password{ + return Color.gray + }else{ + return Color.gray + } + } +} + +//이메일 확인 +func checkEmail(str: String) -> Bool { + let check = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}" + let test = NSPredicate(format: "SELF MATCHES %@", check) + return test.evaluate(with: str) +} + +//비밀번호 확인 및 규격 체크 +struct CheckPassword{ + let check = "^(?=.*[A-Za-z])(?=.*[0-9])(?=.*[!@#$%^&*()_+=-]).{8,64}" + let test : NSPredicate + + init(){ + test = NSPredicate(format: "SELF MATCHES %@", check) + } + + func pwcheck1(_ str: String) -> Color{ + let strcount = str.reduce(0) {$0 + ("!@#$%^&*()_+=-".contains($1) ? 1 : 0)} + if strcount >= 2 && test.evaluate(with: str){ + return .green + }else{ + return .gray + } + } + func pwcheck2(_ str: String) -> Color{ + if str.count >= 8 && str.rangeOfCharacter(from: .decimalDigits) != nil && str.rangeOfCharacter(from: CharacterSet(charactersIn: "!@#$%^&*()_+=-")) != nil { + return .orange + }else{ + return .gray + } + } + func pwcheck3(_ str: String) -> Color{ + if str.count >= 8 && str.rangeOfCharacter(from: .decimalDigits) != nil { + return .orange + }else{ + return .gray + } + } + func pwcheck4(_ str: String) -> Color{ + if !str.isEmpty { + return .red + }else if str.count >= 8{ + return .red + }else{ + return .gray + } + } +} + + + +//커스텀 컬러 +struct ColorManager { + static let BackgroundColor = Color("pickColor") +} + +//포커스 필드 +enum FormField { + case email, password +} + + + +#Preview { + ContentView() +} diff --git a/resume/cv/codelion.css b/resume/cv/codelion.css new file mode 100644 index 0000000..fb26e33 --- /dev/null +++ b/resume/cv/codelion.css @@ -0,0 +1,105 @@ +@import url("https://fonts.googleapis.com/css?family=Montserrat:100,200,300,400,500,600,700,800&display=swap"); + +* { + font-family: "Montserrat"; +} + +body, +h1, +h2 { + margin: 0px; + padding: 0px; +} + +body { + min-width: fit-content; +} + +h1 { + font-size: 36px; + font-weight: bold; + font-style: italic; +} + +h2 { + font-size: 20px; + color: #282828; + font-weight: lighter; + margin-bottom: 16px; + border-bottom: 1px solid #ebebeb; + padding-bottom: 5px; +} + +.name-text { + font-size: 16px; + color: #7c7c7c; + font-weight: bold; +} + +.about-me-text { + font-size: 10px; + line-height: 16px; +} + +.mainbox { + width: 610px; + padding: 30px; + margin: 30px; + margin-right: auto; + margin-left: auto; + border: 1px solid #ebebeb; + box-shadow: 0 1px 20px 0 rgba(0, 0, 0, 0.1); +} + +.title-box { + text-align: right; +} + +section { + margin-bottom: 24px; +} + +.float-wrap { + overflow: hidden; +} + +.title-text { + font-size: 11px; + font-weight: bold; + color: #282828; + float: left; +} + +.year-text { + font-size: 11px; + font-weight: bold; + color: #282828; + float: right; +} + +.desc-text { + font-size: 9px; +} + +.desc-subtext { + font-size: 9px; + color: #282828; + padding-left: 16px; +} + +.sns-img { + width: 12px; + height: 12px; +} + +.sns-wrap { + text-align: right; +} + +footer { + text-align: center; + background-color: #1e1e1e; + padding: 20px; + font-size: 12px; + color: #919191; +} diff --git a/resume/cv/index.html b/resume/cv/index.html new file mode 100644 index 0000000..b315714 --- /dev/null +++ b/resume/cv/index.html @@ -0,0 +1,56 @@ + + + + + 이창준의 이력서 + + + +
+
+

이창준 [ Phang ]

+

Mobile Developer

+
+
+

ABOUT ME

+

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do + eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad + minim veniam, quis nostrud exercitation ullamco laboris nisi ut + aliquip ex ea commodo consequat. Duis aute irure dolor in + reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla + pariatur. Excepteur sint occaecat cupidatat non proident, sunt in + culpa qui officia deserunt mollit anim id est laborum. +

+
+
+

EXPERIENCE

+
+

멋사 iOS 교육

+

2023.09 -

+
+

Mobile Developer

+

iOS, Swift, ...

+
+

XXXXXXXX 교육 수료

+

2023.07 - 2023.08

+
+

Mobile Designer

+

iOS, Swift

+
+

XXXXXXXX 교육 수료

+

2022.07 - 2023.06

+
+

Front-End Web Developer

+

HTML/CSS, JS, Vue.js, ...

+

Back-End Web Developer

+

Java, Spring, Python, Django, ...

+

Mobile Developer

+

Android, Kotlin, Jetpack Compose ...

+
+
+ + + diff --git a/ds/codelion.css b/resume/ds/codelion.css similarity index 100% rename from ds/codelion.css rename to resume/ds/codelion.css diff --git a/ds/index.html b/resume/ds/index.html similarity index 100% rename from ds/index.html rename to resume/ds/index.html diff --git a/studyReview/main.swift b/studyReview/main.swift new file mode 100644 index 0000000..3de9d37 --- /dev/null +++ b/studyReview/main.swift @@ -0,0 +1,1204 @@ +// +// main.swift +// studyReview +// +// Created by 박선구 on 2023/09/30. +// + +import Foundation + +//연산자 예제 1번 + +//let num1 = 7 +//let num2 = 3 +// +//print("더하기 결과: \(num1 + num2)") +//print("빼기 결과: \(num1 - num2)") +//print("곱하기 결과: \(num1 * num2)") +//print("나누기 결과: \(num1 / num2)") +//print("나머지 구하기: \(num1 % num2)") //+ + +//MARK: - +//MARK: 연산자 예제 2 +//변수 num 값 중에서 백의 자리 이하를 버리는 코드이다. 만일 변수 num의 값이 456이라며 400이 되고, 111이라면 100이 된다. + +//let num1: Int = 925 +// +//var result = (num1 / 100) * 100 +//print(result) + +//MARK: - +//MARK: 연산자 예제 3 +//제주도에 다녀온 김모 씨는 3,729개의 귤을 샀다. 김모 씨는 주위 사람들에게 귤을 나눠주려고 하는데 너무 많아서 문제가 생겼습니다. +//김모씨는 귤을 한 사람당 52개씩 박스에 담아서 나눠주려고 합니다. +//김모씨가 사람들에게 줄 수 있는 박스의 수와 남은 귤 갯수를 구해보세요. + +//let orange = 3729 +//let box = 52 +// +//var result = orange / box +//print("나누어 줄 수 있는 박스의 수: ",result) +//result = orange % box +//print("남은 귤 갯수: ",result) + +//MARK: - +//MARK: 연산자 예제 4 +//변수 num 값 중에서 일의 자리를 1로 바꾸는 코드이다. 만일 변수 num의 값이 456 이라면 451이 되고, 777이라면 771이 된다. + +//print("정수를 입력해주세요: ",terminator: "") +//let num = Int(readLine()!)! +// +//var result1 = ((num / 10) * 10) + 1 +//print("\(result1)") + +//MARK: - +//MARK: 연산자 예제 5 +//Swift, iOS, Web 점수를 키보드로 부터 입력 받아 합계와 평균을 출력하세요 + +//print("Swift 점수: ",terminator: "") +//let swiftScore = Int(readLine()!)! +//print("iOS 점수: ",terminator: "") +//let iOSScore = Int(readLine()!)! +//print("Web 점수: ",terminator: "") +//let WebScore = Int(readLine()!)! +// +//var sum = swiftScore + iOSScore + WebScore +//var avg = Float(sum) / 3 +//print("점수 합계: \(sum)\n평균: \(avg)") + +//MARK: - +//MARK: 연산자 예제 6 +//초를 입력 받아 [시, 분, 초] 형태로 출력하세요. + +//print("초 입력: ", terminator: "") +//let t = Int(readLine()!)! +// +//var m = (t/60) % 60 +//var h = (t/60)/60 +//var s = (t%60) +//print("\(h)시간 \(m)분 \(s)초") + +//MARK: - +//MARK: 연산자 예제 7 +//시급계산기 입니다. 기본시급은 5,000원이고, 8시간이 넘을 경우 초과된 시간은 시급의 1.5배를 책정해줍니다. (하루 13시간 이하 근무) + +//var num = 5000 +//var hour = 5000 * 1.5 +// +//print("노동시간 입력: ", terminator: "") +//let time = Int(readLine()!)! +// +// +//if time >= 8 { +// var overtime = (Double(time-8) * hour) +// var money = (Double(time) - Double(time - 8)) * Double(num) +// print("총 입금은 \(Int(overtime + money))원 입니다.") +//} + +//MARK: - +//MARK: 연산자 예제 8 +//정수를 입력받아 홀수인지 짝수인지 판별하세요.(삼항연산자 이용) + +//print("정수를 입력하세요: ", terminator: "") +//let num = Int(readLine()!)! +// +//print(num % 2 == 0 ? "\(num)은 짝수입니다." : "\(num)은 홀수입니다.") + +//MARK: - +//MARK: 연산자 예제 9 +//두 개의 정수를 입력 받아 큰 수에서 작은 수를 뺀 결과값을 출력하세요. .(삼항연산자 이용) +//func inputLine (_ message: String) -> Int { +// print(message, terminator: " ") +// return Int(readLine()!)! +// } +// +//let num1 = inputLine("첫 번째 정수 입력: ") +//let num2 = inputLine("두 번째 정수 입력: ") +// +//print(num1 > num2 ? "두 수의 차: \(num1 - num2)" : "두 수의 차: \(num2 - num1)") + +//MARK: - +//MARK: 연산자 예제 10 +//농구공을 담기 위해 필요한 상자의 개수를 구하세요. +//상자 하나에는 농구공이 5개 들어갈 수 있습니다. 만일 농구공이 ‘23’개라면 필요한 상자의 개수는 ‘5’개입니다. + +func inputLine (_ message : String) -> Int{ + print(message, terminator: "") + return Int(readLine()!)! +} + +//let balls = inputLine("농구공의 갯수를 입력하세요: ") +//var box = balls / 5 +//var left = balls % 5 +// +//print(left != 0 ? "필요한 상자의 수: \(box + 1)" : "필요한 상자의 수: \(box)") + +//MARK: - +//MARK: 조건문 예제 1 +//Int 타입의 변수 age를 선언하고 키보드로 값을 입력받으세요. +//만약 age가 20보다 크거나 같다면 “성인입니다.” 라고 +//출력하는 프로그램을 만들어 보세요. + +//let age = inputLine("정수를 입력하세요: ") +// +//if age >= 20 { +// print("성인입니다.") +//}else{ +// print("성인이 아닙니다.") +//} + +//MARK: - +//MARK: 조건문 예제 2 +//변수 num를 선언하고 키보드로 값을 입력받으세요. +//만약 num이 3의 배수이면서 5의 배수라면 “3과 5의 배수입니다”라고 출력하는 +//프로그램을 만들어보세요. + +//let num = inputLine("정수를 입력하세요: ") +// +//if num % 3 == 0 && num % 5 == 0 { +// print("3과 5의 배수입니다.") +//}else{ +// print("3과 5의 배수가 아닙니다.") +//} +//MARK: - +//MARK: 조건문 예제 3 +//Int 타입의 변수 grade 를 선언하고 키보드로 값을 입력받으세요. +//만약 grade 가 60점이상이면 “합격입니다.” grade 가 60점 미만이면 “불합격입니다.” 를 출력하는 프로그램을 작성해보세요. + +//let grade = inputLine("정수를 입력하세요: ") +// +//if grade >= 60 { +// print("합격입니다.") +//}else{ +// print("불합격입니다.") +//} +//MARK: - +//MARK: 조건문 예제 4 +//정수를 입력 받아 양수, 음수, 0을 판별하여 다음과 같이 출력하세요. + +//let num = inputLine("정수를 입력하세요: ") +// +//if num > 0 { +// print("양수입니다.") +//}else if num < 0 { +// print("음수입니다.") +//}else{ +// print("0 입니다.") +//} + +//MARK: - +//MARK: 조건문 예제 5 +//Int 타입의 변수 num1, num2를 선언하고 키보드로 값을 입력받으세요. +//입력받은 num1과 num2 중 큰 수를 출력하는 프로그램을 만들어보세요. + +//let num1 = inputLine("첫 번째 정수를 입력하세요: ") +//let num2 = inputLine("두 번째 정수를 입력하세요: ") +// +//switch num1 > num2{ +// +//case true: +// print("더 큰 수: \(num1)") +//case false: +// print("더 큰 수: \(num2)") +//} + +//MARK: - +//MARK: 조건문 예제 6 +//정보처리기사의 각 과목의 정답개수를 Int형 타입의 변수 5개를 선언하고 입력받으세요. +//한 과목이라도 8개 미만인 경우, “불합격입니다!”를 출력하고 총 개수가 60개 이상이면 “합격입니다!”를 출력하는 프로그램을 만들어보세요. + +//let num1 = inputLine("1과목 소프트웨어 설계: ") +//let num2 = inputLine("2과목 소프트웨어 개발: ") +//let num3 = inputLine("3과목 데이터베이스 구축: ") +//let num4 = inputLine("4과목 프로그래밍 언어 활용: ") +//let num5 = inputLine("5과목 정보시스템 구축관리: ") +// +//if num1 < 8 || num2 < 8 || num3 < 8 || num4 < 8 || num5 < 8 { +// print("불합격입니다.") +//}else if num1+num2+num3+num4+num5 < 60 { +// print("불합격입니다.") +//}else{ +// print("합격입니다!") +//} + +//MARK: - +//MARK: 조건문 예제 7 +//다음은 디즈니랜드 입장료 계산 프로그램입니다. +//기본료는 5000원이며 인원수에 따라 지불해야하는 프로그램을 만들어보세요. +//단, 미성년자인 경우 50%할인이 적용됩니다! + +//let money = 5000 +//let age = inputLine("나이를 말씀해주세요: ") +//let people = inputLine("인원수를 말씀해주세요: ") +// +//if age < 20 { +// print("총 \(people * (money/2))원 입니다.") +//}else{ +// print("총 \(people * money)원 입니다.") +//} +//MARK: - +//MARK: 조건문 예제 7 (더 해보기) + +//let money = 5000 +//var pay = 0 +// +//let people = inputLine("인원수를 말씀해주세요: ") +// +//for i in 1...people{ +// let age = inputLine("\(i)나이를 입력해주세요: ") +// +// if age <= 20{ +// pay += (money/2) +// }else{ +// pay += money +// } +//} +// +//print("총 \(pay)원 입니다.") + +//MARK: - +//MARK: 조건문 예제 8 +//마트 계산대 프로그램입니다. +//10000원짜리 추석선물셋트를 구입했을 때 지불해야하는 금액을 계산해 보세요. +//단, 11개 이상 구매시에는 10%할인이 됩니다! + +//let set = 10000 +//let num = inputLine("구매하려는 상품 갯수를 입력하세요: ") +// +//if num >= 11 { +// print("가격은 \(Int(Double(set)*0.9) * num)원 입니다.") +//}else{ +// print("가격은 \(set * num)원 입니다.") +//} + +//MARK: - +//MARK: 조건문 예제 9 +//Int 타입의 변수 grade 를 선언하고 키보드로 값을 입력받으세요. +//Grade가 +//90이상이면 “A학점입니다.”, +//80점 이상 90점 미만일 경우 “B학점입니다.” +//70점이상 80점 미만일 경우 “C학점입니다.” 를 출력하세요. + +//let grade = inputLine("점수를 입력하세요: ") +// +//if grade > 90 { +// print("A학점입니다.") +//}else if grade > 80 && grade < 90 { +// print("B학점입니다.") +//}else{ +// print("C학점입니다.") +//} + +//MARK: - +//MARK: 조건문 예제 10 +//switch ~ case 문을 사용하여, +//data가 "hello" 일 때, "네, 안녕하세요!" 출력, +//data 가 "nice to meet you" 일 때, "네, 반가워요!" 출력, +//data가 "take care" 일 때, "네, 수고하세요!" 출력, +//그 외 다른 문장일 때는 "잘못 입력하셨습니다." 라고 출력하는 프로그램을 작성하세요. + +func inputString(_ message: String) -> String{ + print(message, terminator: "") + return readLine()! +} + +//let data = inputString("") +// +//switch data { +//case "hello": +// print("네, 안녕하세요.") +//case "nice to meet you": +// print("네, 반가워요!") +//case "take care": +// print("네, 수고하세요") +//default: +// print("잘못 입력하셨습니다.") +//} + +//MARK: - +//MARK: 조건문 예제 12 +//월을 입력받아 봄, 여름, 가을, 겨울 중 맞는 계절을 알려주는 프로그램을 만드세요. +//12, 1, 2월 → 겨울 +//3, 4, 5월 → 봄 +//6, 7, 8월 → 여름 +//9, 10, 11월 →가을 + +//let month = inputLine("월을 입력하세요: ") +// +//switch month { +//case 12, 1 ,2 : +// print("겨울") +//case 3, 4, 5: +// print("봄") +//case 6, 7, 8: +// print("여름") +//case 9, 10, 11: +// print("가을") +//default: +// print("다시 입력해주세요.") +//} + +//MARK: - +//MARK: 조건문 예제 13 +//자판기 프로그램을 만들어 봅시다. +//금액을 입력하고 메뉴를 고른 뒤 잔돈을 출력해 보세요! + +//let money = inputLine("금액을 입력하세요: ") +//let menu = inputLine("메뉴를 고르세요\n1.콜라(800원) 2.생수(500원) 3.비타민워터(1500원): ") +// +//switch menu { +//case 1: +// print("잔돈: \(money - 800)") +//case 2: +// print("잔돈: \(money - 500)") +//case 3: +// print("잔돈: \(money - 1500)") +//default: break +//} + +//MARK: - +//MARK: 조건문 예제 14 +//입력한 금액이 선택한 메뉴의 가격보다 부족하면 +//돈이 부족하다는 문장을 출력하세요! + +//let money = inputLine("금액을 입력하세요: ") +//let menu = inputLine("메뉴를 고르세요\n1.콜라(800원) 2.생수(500원) 3.비타민워터(1500원): ") +// +//switch menu { +//case 1: +// if money < 800 { +// print("돈이 부족해요 ㅠㅠ") +// }else{ +// print("잔돈: \(money - 800)") +// } +//case 2: +// if money < 500 { +// print("돈이 부족해요 ㅠㅠ") +// }else{ +// print("잔돈: \(money - 500)") +// } +//case 3: +// if money < 1500 { +// print("돈이 부족해요 ㅠㅠ") +// }else{ +// print("잔돈: \(money - 1500)") +// } +//default: break +//} + +//MARK: - +//MARK: 조건문 예제 15 +//잔돈을 줄 때 천원을 몇 개 줘야 하는지 계산해 보세요! + +//let money = inputLine("금액을 입력하세요: ") +//let menu = inputLine("메뉴를 고르세요\n1.콜라(800원) 2.생수(500원) 3.비타민워터(1500원): ") +// +//switch menu { +//case 1: +// if money < 800 { +// print("돈이 부족해요 ㅠㅠ") +// }else{ +// print("잔돈: \(money - 800)") +// print("천원: \((money - 800)/1000)") +// } +//case 2: +// if money < 500 { +// print("돈이 부족해요 ㅠㅠ") +// }else{ +// print("잔돈: \(money - 500)") +// print("천원: \((money - 500)/1000)") +// } +//case 3: +// if money < 1500 { +// print("돈이 부족해요 ㅠㅠ") +// }else{ +// print("잔돈: \(money - 1500)") +// print("천원: \((money - 1500)/1000)") +// } +//default: break +//} + +//MARK: - +//MARK: 조건문 예제 16 +//잔돈을 줄 때 천원, 오백원, 백원짜리를 몇 개 줘야하는지 계산해 보세요! + +//let money = inputLine("금액을 입력하세요: ") +//let menu = inputLine("메뉴를 고르세요\n1.콜라(800원) 2.생수(500원) 3.비타민워터(1500원): ") +// +//switch menu { +//case 1: +// if money < 800 { +// print("돈이 부족해요 ㅠㅠ") +// }else{ +// print("잔돈: \(money - 800)") +// print("천원: \((money - 800)/1000)") +// print("오백원: \((money - 800)%1000/500)") +// print("백원: \((money - 800)%1000%500/100)") +// } +//case 2: +// if money < 500 { +// print("돈이 부족해요 ㅠㅠ") +// }else{ +// print("잔돈: \(money - 500)") +// print("천원: \((money - 500)/1000)") +// print("오백원: \((money - 500)%1000/500)") +// print("백원: \((money - 500)%1000%500/100)") +// } +//case 3: +// if money < 1500 { +// print("돈이 부족해요 ㅠㅠ") +// }else{ +// print("잔돈: \(money - 1500)") +// print("천원: \((money - 1500)/1000)") +// print("오백원: \((money - 1500)%1000/500)") +// print("백원: \((money - 1500)%1000%500/100)") +// } +//default: break +//} + +//MARK: - +//MARK: while문 예제 1 + +//var result = 0 +// +//while result < 10 { +// let num = inputLine("정수 입력: ") +// result = num +//} +//print("종료되었습니다.") + +//MARK: - +//MARK: while문 예제 2 +//다이어트 관리 프로그램 +//현재 몸무게와 목표몸무게를 입력 받고 주차 별 감량 몸무게를 입력 받으세요. +//목표 몸무게를 달성하면 축하한다는 문구를 출력 하고 입력을 멈추세요! + +//var nowWeight = inputLine("현재 몸무게: ") +//let target = inputLine("목표 몸무게: ") +//var i = 0 +// +//while nowWeight > target { +// i = i + 1 +// var weight = inputLine("\(i)주차 몸무게: ") +// nowWeight -= weight +//} +//if nowWeight < target { +// print("\(nowWeight)kg 달성! 축하합니다.") +//} + +//MARK: - +//MARK: while문 예제 3 +//로그인 프로그램을 만들어 보자. +//아이디와 비밀번호를 각각 입력 받고 일치할 경우 “로그인성공!” +//일치하지 않은 경우에는 “로그인 실패!” + +//let setId = "hello" +//let setPassword = 1234 +//let id = inputString("아이디를 입력해주세요: ") +//let password = inputLine("비밀번호를 입력해주세요: ") +// +//if id == setId && password == setPassword { +// print("로그인 성공!") +//}else{ +// print("id 또는 비밀번호가 틀렸습니다.") +//} + +//MARK: - +//MARK: while문 예제 4 +//로그인이 실패했을 경우에 계속 입력 +//로그인이 성공하면 프로그램 종료 + +//let setId = "hello" +//let setPassword = 1234 +// +//while true { +// let id = inputString("아이디를 입력해주세요: ") +// let password = inputLine("비밀번호를 입력해주세요: ") +// +// if id == setId && password == setPassword { +// print("로그인 성공!") +// break +// }else{ +// print("id 또는 비밀번호가 틀렸습니다.\n") +// continue +// } +//} + +//MARK: - +//MARK: while문 예제 5 +//Login프로그램 +//아이디와 비밀번호가 틀렸을 경우 "계속 하시겠습니까?" 라는 문장을 출력하세요. +//Y를 입력하면 아이디 비밀번호 입력 계속, +//N을 입력하면 종료 +//로그인 성공 시 종료 + + +//let setId = "hello" +//let setPassword = 1234 +// +//while true { +// let id = inputString("아이디를 입력해주세요: ") +// let password = inputLine("비밀번호를 입력해주세요: ") +// +// if id == setId && password == setPassword { +// print("로그인 성공!") +// break +// }else{ +// print("id 또는 비밀번호가 틀렸습니다.\n") +// let again = inputString("다시 하시겠습니까? (Y/N): ") +// if again == "Y"{ +// continue +// }else if again == "N"{ +// break +// } +// } +//} + +//MARK: - +//MARK: while문 예제 6 +//아이디와 비밀번호가 틀렸을 경우 "계속 하시겠습니까?" 라는 문장을 출력하세요. +//첫 번째 정수를 입력 받는다. +//두 번째 정수를 입력 받는다. +//연산자를 선택한다. +//선택한 연산자에 따라 연산결과를 출력한다. +//다시 실행할 것인가를 물어본다. +//“Y” 를 입력하면 다시 실행. +//“N”을 입력하면 반복문 종료. + + +//var a = true +//while a { +//let num1 = inputLine("첫 번째 정수 입력: ") +//let num2 = inputLine("두 번째 정수 입력: ") +//var result = 0 +// +//let sellect1 = inputLine("1.더하기 2.빼기: ") +// switch sellect1 { +// case 1: +// result = num1 + num2 +// print(result) +// let sellect2 = inputString("다시(Y/N): ") +// if sellect2 == "Y"{ +// continue +// }else if sellect2 == "N"{ +// a = false +// } +// case 2: +// result = num1 - num2 +// print(result) +// let sellect2 = inputString("다시(Y/N): ") +// if sellect2 == "Y"{ +// continue +// }else if sellect2 == "N"{ +// a = false +// } +// default: +// print("다시 입력해주세요.") +// continue +// } +//} + +//MARK: - +//MARK: while문 예제 7 + +//let num1 = Int.random(in: 0...100) +//let num2 = Int.random(in: 0...100) +//var result = num1 + num2 +// +//let answer = inputLine("\(num1) + \(num2) = ? ") +// +//if answer == result { +// print("SUCCESS") +//}else{ +// print("FAIL") +//} + +//MARK: - +//MARK: while문 예제 7 - 1 +//사용자가 원할 때까지 반복 +//Fail 후 계속하기를 선택할 시 기존 숫자를 출력 + +//var again = true +//let num1 = Int.random(in: 0...100) +//let num2 = Int.random(in: 0...100) +//var result = num1 + num2 +// +//while again { +// let answer = inputLine("\(num1) + \(num2) = ? ") +// +// if answer == result { +// print("SUCCESS") +// again = false +// }else{ +// print("FAIL") +// let failAgain = inputString("다시 하시겠습니까? (Y/N): ") +// if failAgain == "Y"{ +// again = true +// }else{ +// again = false +// } +// } +//} + +//MARK: - +//MARK: while문 예제 7-2 * +//Success 후 계속하기를 선택할 시 새로운 숫자를 뽑아서 출력 + +//var again = true +//var again2 = true +// +//while again2 { +// let num1 = Int.random(in: 0...100) +// let num2 = Int.random(in: 0...100) +// let result = num1 + num2 +// +// while again { +// let answer = inputLine("\(num1) + \(num2) = ? ") +// +// if answer == result { +// print("SUCCESS") +// let successAgain = inputString("다시 하시겠습니까? (Y/N): ") +// if successAgain == "Y"{ +// break +// }else{ +// again2 = false +// again = false +// } +// }else{ +// print("FAIL") +// let failAgain = inputString("재도전 하시겠습니까? (Y/N): ") +// if failAgain == "Y"{ +// again = true +// again2 = true +// }else{ +// again2 = false +// again = false +// } +// } +// } +//} + +//MARK: - +//MARK: for문 예제 00 +//for문을 사용하여 96에서 53까지 출력하시오. + +//for i in (53...96).reversed(){ +// print(i) +//} + +//for문을 사용하여 21에서 57까지의 수 중 홀수만 출력하시오. + +//for i in 21...57 { +// if i % 2 == 1{ +// print(i) +// } +//} + +//정수를 입력 받아 1부터 입력 받은 정수까지 차례대로 출력하는 프로그램을 작성하시오. + +//let num1 = inputLine("정수 입력: ") +//for i in 1...num1{ +// print(i) +//} + +//한 개의 자연수를 입력 받아 그 수의 배수를 차례로 10개 출력하는 프로그램을 작성하시오. + +//let num1 = inputLine("자연수 입력: ") +//for i in 1...10{ +// print("\(num1 * i)") +//} + +//1~100까지 3의 배수의 합을 출력하세요. (1683) + +//var sum = 0 +// +//for i in 1...33 { +// var result = 3 * i +// sum += result +//} +//print(sum) + +//MARK: - +//MARK: for문 예제 3 +//2단 출력 + +//for i in 1...9{ +// print("2 * \(i) = \(i * 2)") +//} + +//MARK: - +//MARK: for문 예제 4 +//원하는 단을 입력받아 구구단을 출력하세요. + +//let num = inputLine("단 입력: ") +//for i in 1...9 { +// print("\(num) * \(i) = \(num * i)") +//} + +//MARK: - +//MARK: for문 예제 5 +//구구단 1단~9단까지 출력 + +//for i in 2...9{ +// print("=== \(i)단 ===") +// for j in 1...9{ +// print("\(i) * \(j) = \(i * j)") +// if j == 9{ +// print("\n") +// } +// } +//} + +//MARK: - +//MARK: for문 예제 6 + +//for i in 2...9{ +// print("\(i)단: ", terminator: "") +// for j in 1...9{ +// if (i * j) < 10{ +// print("\(i) * \(j) = \(i * j)", terminator: " ") +// }else{ +// print("\(i) * \(j) = \(i * j)", terminator: " ") +// } +// if j == 9{ +// print("\n") +// } +// } +//} + +//MARK: - +//MARK: for문 예제 7 +//입력 받은 정수의 약수를 구하세요 + +//print("정수 입력: ",terminator: "") +//let num = Int(readLine()!)! +// +//print("\(num)의 약수: ",terminator: "") +//for i in 1...num{ +// if num % i == 0{ +// print(i, terminator: " ") +// } +//} + +//MARK: - +//MARK: for문 예제 8 +//2~30까지의 약수를 구하세요 + +//for i in 2...30{ +// print("\(i)의 약수: ", terminator: "") +// for j in 1...i{ +// if i % j == 0{ +// print("\(j)", terminator: " ") +// if j == i { +// print("\n") +// } +// } +// } +//} + +//MARK: - +//MARK: for문 에제 9 +//별찍기 + +//for i in 1...5{ +// print(" ") +// for j in 1...i{ +// print("*",terminator: "") +// } +//} + +//MARK: - +//MARK: 별찍기 거꾸로 + +//for i in (1...5).reversed(){ +// print(" ") +// for j in 1...i{ +// print("*",terminator: "") +// } +//} + +//MARK: - +//MARK: 별찍기 반대로 + +//for i in 1...5{ +// print("") +// for k in i...5{ +// print(" ",terminator: "") +// } +// for j in 1...i{ +// print("*",terminator: "") +// } +//} + +//MARK: - +//MARK: 별찍기 다이아 + +//for i in 1...5{ +// print("") +// for _ in i...5{ +// print(" ",terminator: "") +// } +// for _ in 1...i{ +// print("*",terminator: "") +// } +// for _ in 1...i{ +// print("*", terminator: "") +// } +//} +//for p in (1...5).reversed(){ +// print("") +// for _ in p...5{ +// print(" ",terminator: "") +// } +// for _ in 1...p{ +// print("*",terminator: "") +// } +// for _ in 1...p{ +// print("*", terminator: "") +// } +//} + +//MARK: - +//MARK: 함수 예제 1 +//두 수의 합을 받아 아래와 같은 결과가 나올 수 있도록 addNumber() 를 작성하시오 + +//func addNumber(_ num1: Int,_ num2: Int) -> Int { +// return num1 + num2 +//} +// +//let firstnum = inputLine("첫번째 수: ") +//let seccondnum = inputLine("두번째 수: ") +// +//let result = addNumber(firstnum, seccondnum) +//print("연산결과: \(result)") + +//MARK: - +//MARK: 함수 예제 2 +//2개의 정수를 받아 2개의 숫자 중 더 큰 수를 반환하는 largerNumbers() 을 만들어보세요 + +//func largerNumbers(_ num1: Int,_ num2: Int) -> Int{ +// if num1 > num2{ +// return num1 +// }else if num2 > num1{ +// return num2 +// }else{ +// return 0 +// } +//} +// +//let inputNum1 = inputLine("첫번째 수: ") +//let inputNum2 = inputLine("두번째 수: ") +// +//let result = largerNumbers(inputNum1, inputNum2) +//print("큰 수 확인: \(result)") + +//MARK: - +//MARK: 함수 예제 3 * +//2개의 정수를 받아 2개의 숫자 중 10에 더 가까운 수를 반환하는 close10() 을 만들어보세요 + +//func close10(num1: Int, num2: Int) -> Int{ +// if 10 - abs(num1) < 10 - abs(num2) { +// return num1 +// }else if 10 - abs(num2) < 10 - abs(num1) { +// return num2 +// }else{ +// return 0 +// } +// +//} +// +//let inputNum1 = inputLine("첫번째 수: ") +//let inputNum2 = inputLine("두번째 수: ") +// +//let result = close10(num1: inputNum1, num2: inputNum2) +//print("10에 가까운 수: \(result)") + +//MARK: - +//MARK: 함수 예제 4 +//2개의 정수 base, n을 받아 base의 n제곱 만큼 값을 반환하는 powerN() 를 작성하세요 + +//func powerN(base : Float, n : Float) -> Float{ +// return pow(base, n) +//} +// +//let inputNum1 = inputLine("첫번째 수: ") +//let inputNum2 = inputLine("두번째 수: ") +// +//let result = powerN(base: Float(inputNum1), n: Float(inputNum2)) +//print("결과 확인: \(Int(result))") + +//MARK: - +//MARK: 함수 예제 5 +//키보드로부터 입력받은 두 개의 정수를 인자(매개변수)로 넘겨받아 num1에서 num2를 뺀 결과값을 절대값으로 바꾸어 출력하는 getAbsoluteValue( ) 를 구현하세요 + + +//func getAbsoluteValue(num1 : Int, num2 : Int) -> Int{ +// return abs(num1 - num2) +//} +// +//let inputNum1 = inputLine("첫번째 수: ") +//let inputNum2 = inputLine("두번째 수: ") +// +//let result = getAbsoluteValue(num1: inputNum1, num2: inputNum2) +//print("결과 확인: \(result)") + +//MARK: - +//MARK: 함수 예제 6 +//두 개의 정수를 인자(매개변수)로 넘겨받아 앞의 정수가 뒤의 정수로 나누어지는지를 판별하는 isDivide( ) 를 작성하세요. +//(이때 나누어지면 true, 나누어지지 않으면 false을 반환) + +//func isDivide(num1: Int, num2: Int) -> Bool{ +// if num1 % num2 == 0 { +// return true +// }else if num1 % num2 != 0{ +// return false +// }else{ +// return false +// } +//} +// +//let inputNum1 = inputLine("첫번째 수: ") +//let inputNum2 = inputLine("두번째 수: ") +// +//let result = isDivide(num1: inputNum1, num2: inputNum2) +//print("결과 확인: \(result)") + +//MARK: - +//MARK: 함수 예제 7 +//약수를 구하는 getDivisor() 를 구현하세요 + +//func getDivisior(num1: Int) { +// for i in 1...num1{ +// if num1 % i == 0{ +// print(i, terminator: " ") +// } +// } +//} +//let inputNum = inputLine("약수: ") +//let divi = getDivisior(num1: inputNum) +//print(divi) + +//MARK: - +//MARK: 함수 예제 8 +//약수의 합을 구하여 반환하는 getSumOfDivisors() 를 구현하세요 + +//func getSumOfDivisiors(num1: Int) -> Int{ +// var result = 0 +// for i in 1...num1{ +// if num1 % i == 0{ +// result += i +// } +// } +// return result +//} +// +//let inputNum = inputLine("약수: ") +//let result = getSumOfDivisiors(num1: inputNum) +//print("\(inputNum)의 약수의 합: \(result)") + +//MARK: - +//MARK: 함수 예제 9 * +//startValue...endValue까지의 숫자 중 완전수를 출력하는 getPerfectNumber() 를 구현하세요 + + +//MARK: - +//MARK: 함수 예제 10 * +//startValue~endValue까지의 숫자 중 소수를 출력하는 getPrimeNumber() 를 구현하세요 +//func getPrimeNumber(num1: Int, num2: Int) { +// for i in num1...num2{ +// for j in 1...i { +// if i % j == 0{ +// print(i, terminator: " ") +// } +// } +// } +//} +// +//let inputNum1 = inputLine("첫번째 수: ") +//let inputNum2 = inputLine("두번째 수: ") +// +//getPrimeNumber(num1: inputNum1, num2: inputNum2) +//print("결과 확인: \(result)") + +//MARK: - +//MARK: 클래스 예제 0 + +//class Pigbank { +// var mybank = 0 +// +// func moneyIn (num: Int) { +// mybank += num +// show() +// } +// func moneyOut (num: Int){ +// if mybank == 0 || mybank < 0{ +// print("잔액이 부족합니다.") +// }else{ +// mybank -= num +// } +// show() +// } +// func show() { +// print("현재 잔액: \(mybank)") +// } +//} +// +//let bank = Pigbank() +//bank.show() +//bank.moneyIn(num: inputLine("입금: ")) +//bank.moneyOut(num: inputLine("출금: ")) + +//MARK: - +//MARK: 클래스 예제 1 ~ 3 + +//class Student { +// var name : String +// var number : String +// var age : Int +// var scoreSwift : Int +// var scoreiOS : Int +// var scoreWeb : Int +// +// init(name: String, number: String, age: Int, scoreSwift: Int, scoreiOS: Int, scoreWeb: Int) { +// self.name = name +// self.number = number +// self.age = age +// self.scoreSwift = scoreSwift +// self.scoreiOS = scoreiOS +// self.scoreWeb = scoreWeb +// } +// func show(){ +// print("\(name)님 안녕하세요.\n[ \(number), \(age)살 ]\n\(name)님의 Swift 점수는 \(scoreSwift)점 입니다.\n\(name)님의 iOS 점수는 \(scoreiOS)점 입니다.\n\(name)님의 Web 점수는 \(scoreWeb)점 입니다.") +// } +//} +// +//var student1 = Student.init(name: "홍길동", number: "20200677", age: 22, scoreSwift: 50, scoreiOS: 89, scoreWeb: 77) +//var student2 = Student.init(name: "김영희", number: "20190541", age: 26, scoreSwift: 90, scoreiOS: 85, scoreWeb: 70) +// +//student1.show() +//print("===============") +//student2.show() + +//MARK: - +//MARK: 클래스 예제 4 + +//class Person { +// var name: String +// var age: Int +// +// init(name: String, age: Int) { +// self.name = name +// self.age = age +// } +// func getName () -> String { +// return name +// } +// func setName (change: String) -> String{ +// name = change +// return name +// } +// func getAge() -> Int { +// return age +// } +// func setAge(changeAge: Int) -> Int { +// age = changeAge +// return age +// } +//} +// +//var st1 = Person(name: "홍길동", age: 25) +//var st2 = Person(name: "김영희", age: 27) +//print("이름: \(st1.name), 나이: \(st2.age)") +//print("이름: \(st2.name), 나이: \(st2.age)") + +//MARK: - +//MARK: 클래스 예제 5 + +//class Caculator { +// var num1: Int +// var num2: Int +// +// init(num1: Int, num2: Int) { +// self.num1 = num1 +// self.num2 = num2 +// } +// func setNum1 (num: Int) -> Int { +// num1 = num +// return num1 +// } +// func setNum2 (num: Int) -> Int { +// num2 = num +// return num2 +// } +// func sum () -> Int{ +// return num1 + num2 +// } +// func sub () -> Int{ +// return num1 - num2 +// } +// func mul () -> Int{ +// return num1 * num2 +// } +// func div () -> Int{ +// return num1 / num2 +// } +//} +// +//var cal = Caculator(num1: inputLine("1번째 수: "), num2: inputLine("2번째 수: ")) +// +//print(cal.sum(), cal.setNum1(num: 75), cal.setNum2(num: 5), cal.sub(), cal.mul(), cal.div()) + +//MARK: - +//MARK: 클래스 예제 6 + +//class TV { +// var name: String +// var year: Int +// var size: Int +// +// init(name: String, year: Int, size: Int) { +// self.name = name +// self.year = year +// self.size = size +// } +// func show() { +// print("\(name)에서 만든 \(year)년형 \(size)인치 TV") +// } +//} +// +//let myTV = TV(name: "LG", year: 2023, size: 48) +//myTV.show() + +//MARK: - +//MARK: 별그리기 클래스 + +//MARK: - +//MARK: 배열 예제 1 + +//var array : [Int] = [] +//for i in 1...10{ +// array.insert(Int.random(in: 1...20), at: i-1) +//} +//print(array) +//print(array[4] + array[9]) +//var sum = 0 +//for j in 1...10{ +// sum += array[j-1] +//} +//print(sum) +//print(Float(sum) / 10.0) + +//MARK: - +//MARK: 배열 예제 2 + +var array : [Int] = [] +for i in 1...10{ + array.insert(Int.random(in: 1...20), at: i-1) +} +var result : [Int] = [] +for j in 1...10{ + if array[j-1] % 2 == 0{ + result.append(array[j-1]) + } +} +print(result)