diff --git a/BinaryConverter.xcodeproj/project.pbxproj b/BinaryConverter.xcodeproj/project.pbxproj index e5744dd..7807a68 100644 --- a/BinaryConverter.xcodeproj/project.pbxproj +++ b/BinaryConverter.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ 2CCE3EAD2AF67A9000BB0ED3 /* UtilsFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CCE3EAC2AF67A9000BB0ED3 /* UtilsFunctions.swift */; }; 2CCE3EAF2AF67BA900BB0ED3 /* BinaryConverter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CCE3EAE2AF67BA900BB0ED3 /* BinaryConverter.swift */; }; 2CCE3EB12AF67CFD00BB0ED3 /* HexaConverter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CCE3EB02AF67CFD00BB0ED3 /* HexaConverter.swift */; }; + 2CCE3EB52AF6879200BB0ED3 /* OctalConverter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CCE3EB42AF6879200BB0ED3 /* OctalConverter.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -25,6 +26,7 @@ 2CCE3EAC2AF67A9000BB0ED3 /* UtilsFunctions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UtilsFunctions.swift; sourceTree = ""; }; 2CCE3EAE2AF67BA900BB0ED3 /* BinaryConverter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinaryConverter.swift; sourceTree = ""; }; 2CCE3EB02AF67CFD00BB0ED3 /* HexaConverter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HexaConverter.swift; sourceTree = ""; }; + 2CCE3EB42AF6879200BB0ED3 /* OctalConverter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OctalConverter.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -59,6 +61,7 @@ children = ( 2CCE3E9E2AF678B200BB0ED3 /* BinaryConverterApp.swift */, 2CCE3EA02AF678B200BB0ED3 /* ContentView.swift */, + 2CCE3EB42AF6879200BB0ED3 /* OctalConverter.swift */, 2CCE3EB02AF67CFD00BB0ED3 /* HexaConverter.swift */, 2CCE3EAE2AF67BA900BB0ED3 /* BinaryConverter.swift */, 2CCE3EAC2AF67A9000BB0ED3 /* UtilsFunctions.swift */, @@ -150,6 +153,7 @@ 2CCE3EAF2AF67BA900BB0ED3 /* BinaryConverter.swift in Sources */, 2CCE3EAD2AF67A9000BB0ED3 /* UtilsFunctions.swift in Sources */, 2CCE3EB12AF67CFD00BB0ED3 /* HexaConverter.swift in Sources */, + 2CCE3EB52AF6879200BB0ED3 /* OctalConverter.swift in Sources */, 2CCE3E9F2AF678B200BB0ED3 /* BinaryConverterApp.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -287,11 +291,13 @@ DEVELOPMENT_TEAM = KK24298HY5; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_CFBundleDisplayName = "Binary Converter"; + INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.education"; 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"; + INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait; + IPHONEOS_DEPLOYMENT_TARGET = 15.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -299,9 +305,12 @@ MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = fr.louisgallet.BinaryConverter; PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; + TARGETED_DEVICE_FAMILY = 1; }; name = Debug; }; @@ -316,11 +325,13 @@ DEVELOPMENT_TEAM = KK24298HY5; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_CFBundleDisplayName = "Binary Converter"; + INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.education"; 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"; + INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait; + IPHONEOS_DEPLOYMENT_TARGET = 15.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -328,9 +339,12 @@ MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = fr.louisgallet.BinaryConverter; PRODUCT_NAME = "$(TARGET_NAME)"; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; + TARGETED_DEVICE_FAMILY = 1; }; name = Release; }; diff --git a/BinaryConverter/Assets.xcassets/AppIcon.appiconset/1024.png b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/1024.png new file mode 100644 index 0000000..4f29e5e Binary files /dev/null and b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/1024.png differ diff --git a/BinaryConverter/Assets.xcassets/AppIcon.appiconset/114.png b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/114.png new file mode 100644 index 0000000..91f05bd Binary files /dev/null and b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/114.png differ diff --git a/BinaryConverter/Assets.xcassets/AppIcon.appiconset/120.png b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/120.png new file mode 100644 index 0000000..7774155 Binary files /dev/null and b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/120.png differ diff --git a/BinaryConverter/Assets.xcassets/AppIcon.appiconset/180.png b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/180.png new file mode 100644 index 0000000..aa05f6d Binary files /dev/null and b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/180.png differ diff --git a/BinaryConverter/Assets.xcassets/AppIcon.appiconset/29.png b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/29.png new file mode 100644 index 0000000..21022f0 Binary files /dev/null and b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/29.png differ diff --git a/BinaryConverter/Assets.xcassets/AppIcon.appiconset/40.png b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/40.png new file mode 100644 index 0000000..64eae8c Binary files /dev/null and b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/40.png differ diff --git a/BinaryConverter/Assets.xcassets/AppIcon.appiconset/57.png b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/57.png new file mode 100644 index 0000000..d3ca06e Binary files /dev/null and b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/57.png differ diff --git a/BinaryConverter/Assets.xcassets/AppIcon.appiconset/58.png b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/58.png new file mode 100644 index 0000000..3e076f3 Binary files /dev/null and b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/58.png differ diff --git a/BinaryConverter/Assets.xcassets/AppIcon.appiconset/60.png b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/60.png new file mode 100644 index 0000000..2fb3d7b Binary files /dev/null and b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/60.png differ diff --git a/BinaryConverter/Assets.xcassets/AppIcon.appiconset/80.png b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/80.png new file mode 100644 index 0000000..9bbebe8 Binary files /dev/null and b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/80.png differ diff --git a/BinaryConverter/Assets.xcassets/AppIcon.appiconset/87.png b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/87.png new file mode 100644 index 0000000..a785a8a Binary files /dev/null and b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/87.png differ diff --git a/BinaryConverter/Assets.xcassets/AppIcon.appiconset/Contents.json b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/Contents.json index 13613e3..af727e0 100644 --- a/BinaryConverter/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/BinaryConverter/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -1,8 +1,75 @@ { "images" : [ { - "idiom" : "universal", - "platform" : "ios", + "filename" : "40.png", + "idiom" : "iphone", + "scale" : "2x", + "size" : "20x20" + }, + { + "filename" : "60.png", + "idiom" : "iphone", + "scale" : "3x", + "size" : "20x20" + }, + { + "filename" : "29.png", + "idiom" : "iphone", + "scale" : "1x", + "size" : "29x29" + }, + { + "filename" : "58.png", + "idiom" : "iphone", + "scale" : "2x", + "size" : "29x29" + }, + { + "filename" : "87.png", + "idiom" : "iphone", + "scale" : "3x", + "size" : "29x29" + }, + { + "filename" : "80.png", + "idiom" : "iphone", + "scale" : "2x", + "size" : "40x40" + }, + { + "filename" : "120.png", + "idiom" : "iphone", + "scale" : "3x", + "size" : "40x40" + }, + { + "filename" : "57.png", + "idiom" : "iphone", + "scale" : "1x", + "size" : "57x57" + }, + { + "filename" : "114.png", + "idiom" : "iphone", + "scale" : "2x", + "size" : "57x57" + }, + { + "filename" : "120.png", + "idiom" : "iphone", + "scale" : "2x", + "size" : "60x60" + }, + { + "filename" : "180.png", + "idiom" : "iphone", + "scale" : "3x", + "size" : "60x60" + }, + { + "filename" : "1024.png", + "idiom" : "ios-marketing", + "scale" : "1x", "size" : "1024x1024" } ], diff --git a/BinaryConverter/BinaryConverter.swift b/BinaryConverter/BinaryConverter.swift index 48ce2c7..e1340c0 100644 --- a/BinaryConverter/BinaryConverter.swift +++ b/BinaryConverter/BinaryConverter.swift @@ -20,25 +20,8 @@ struct BinaryConverter: View { Text("Your number in base 2: \(binaryNumber)") } } -// .onChange(of: decimalNumber) { -// [decimalNumber] newValue in -// if newValue != decimalNumber { -// binaryNumber = convertToBinary(newValue) -// } -// } - .onChange(of: decimalNumber, initial: true, { - oldDecimalNumber, NewDecimalNumber in - if (oldDecimalNumber != NewDecimalNumber) { - binaryNumber = convertToBinary(NewDecimalNumber) - } - }) - } - func convertToBinary(_ decimalString: String) -> String { - if let decimal = Int(decimalString) { - // Perform your base conversion logic here - return String(decimal, radix: 2) - } else { - return "Invalid Input" + .onChange(of: decimalNumber) { newValue in + binaryNumber = convertToBinary(newValue) } } } diff --git a/BinaryConverter/ContentView.swift b/BinaryConverter/ContentView.swift index 9838d85..5c8080b 100644 --- a/BinaryConverter/ContentView.swift +++ b/BinaryConverter/ContentView.swift @@ -12,8 +12,8 @@ struct ContentView: View { var body: some View { TabView(selection: $selectedTab, content: { - BinaryConverter().tabItem { Image(systemName: "1.square.fill") ; Text("Binary") }.tag(0) - HexaConverter().tabItem { Image(systemName: "2.square.fill") ; Text("Hexa") }.tag(1) + BinaryConverter().tabItem { Image(systemName: "2.square.fill") ; Text("Binary") }.tag(0) + HexaConverter().tabItem { Image(systemName: "16.square.fill") ; Text("Hexa") }.tag(1) }) } diff --git a/BinaryConverter/HexaConverter.swift b/BinaryConverter/HexaConverter.swift index 6e49257..7e5eef4 100644 --- a/BinaryConverter/HexaConverter.swift +++ b/BinaryConverter/HexaConverter.swift @@ -8,8 +8,21 @@ import SwiftUI struct HexaConverter: View { + @State private var decimalNumber: String = "" + @State private var HexadecimalNumber: String = "" var body: some View { - Text("Hello, Hexa!") + Form { + Section(header: Text("Base 10")) { + TextField("Enter the base 10 number here", text: $decimalNumber) + .keyboardType(.numberPad) + } + Section(header: Text("Base 2")) { + Text("Your number in base 16: \(HexadecimalNumber)") + } + } + .onChange(of: decimalNumber) { newValue in + HexadecimalNumber = convertToBinary(newValue) + } } } diff --git a/BinaryConverter/OctalConverter.swift b/BinaryConverter/OctalConverter.swift new file mode 100644 index 0000000..589d006 --- /dev/null +++ b/BinaryConverter/OctalConverter.swift @@ -0,0 +1,18 @@ +// +// OctalConverter.swift +// BinaryConverter +// +// Created by Louis Gallet on 04/11/2023. +// + +import SwiftUI + +struct OctalConverter: View { + var body: some View { + Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + } +} + +#Preview { + OctalConverter() +} diff --git a/BinaryConverter/UtilsFunctions.swift b/BinaryConverter/UtilsFunctions.swift index 2a6df49..3ecc3f8 100644 --- a/BinaryConverter/UtilsFunctions.swift +++ b/BinaryConverter/UtilsFunctions.swift @@ -7,22 +7,25 @@ import Foundation -extension BinaryInteger { - var binaryDescription: String { - /// Convert a given number to it's binary representation - /// source: https://stackoverflow.com/questions/26181221/how-to-convert-a-decimal-number-to-binary-in-swift - var binaryString = "" - var internalNumber = self - var counter = 0 - - for _ in (1...self.bitWidth) { - binaryString.insert(contentsOf: "\(internalNumber & 1)", at: binaryString.startIndex) - internalNumber >>= 1 - counter += 1 - if counter % 4 == 0 { - binaryString.insert(contentsOf: " ", at: binaryString.startIndex) - } - } - return binaryString +/// Convert a given number to its binary form +/// - Parameter decimalString: Your number in base10 in String format +/// - Returns: Return the number in base2 in String format or return "Invalid Input" if the input is not valid +func convertToBinary(_ decimalString: String) -> String { + if let decimal = Int(decimalString) { + return String(decimal, radix: 2) + } else { + return "Invalid Input" + } +} + +/// Convert a given number to its hexadeciam form +/// - Parameter decimalString: Your number in base10 in String format +/// - Returns: Return the number in base16 in String format or return "Invalid Input" if the input is not valid +func convertToHex(_ decimalString: String) -> String { + if let number = Int(decimalString) { + let hexString = String(number, radix: 16) + return hexString.uppercased() + } else { + return "Invalid Input" } }