From 78f2aedcd8cbe4d0db651ff1d324333db440a331 Mon Sep 17 00:00:00 2001 From: Louis Date: Sat, 4 Nov 2023 14:24:10 +0100 Subject: [PATCH] feat: :construction: Create two screens --- BinaryConverter.xcodeproj/project.pbxproj | 12 ++++++++++ BinaryConverter/BinaryConverter.swift | 18 +++++++++++++++ BinaryConverter/ContentView.swift | 14 ++++++------ BinaryConverter/HexaConverter.swift | 18 +++++++++++++++ BinaryConverter/UtilsFunctions.swift | 28 +++++++++++++++++++++++ 5 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 BinaryConverter/BinaryConverter.swift create mode 100644 BinaryConverter/HexaConverter.swift create mode 100644 BinaryConverter/UtilsFunctions.swift diff --git a/BinaryConverter.xcodeproj/project.pbxproj b/BinaryConverter.xcodeproj/project.pbxproj index c9530d0..e5744dd 100644 --- a/BinaryConverter.xcodeproj/project.pbxproj +++ b/BinaryConverter.xcodeproj/project.pbxproj @@ -11,6 +11,9 @@ 2CCE3EA12AF678B200BB0ED3 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CCE3EA02AF678B200BB0ED3 /* ContentView.swift */; }; 2CCE3EA32AF678B300BB0ED3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2CCE3EA22AF678B300BB0ED3 /* Assets.xcassets */; }; 2CCE3EA62AF678B300BB0ED3 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2CCE3EA52AF678B300BB0ED3 /* Preview Assets.xcassets */; }; + 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 */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -19,6 +22,9 @@ 2CCE3EA02AF678B200BB0ED3 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 2CCE3EA22AF678B300BB0ED3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 2CCE3EA52AF678B300BB0ED3 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; + 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 = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -53,6 +59,9 @@ children = ( 2CCE3E9E2AF678B200BB0ED3 /* BinaryConverterApp.swift */, 2CCE3EA02AF678B200BB0ED3 /* ContentView.swift */, + 2CCE3EB02AF67CFD00BB0ED3 /* HexaConverter.swift */, + 2CCE3EAE2AF67BA900BB0ED3 /* BinaryConverter.swift */, + 2CCE3EAC2AF67A9000BB0ED3 /* UtilsFunctions.swift */, 2CCE3EA22AF678B300BB0ED3 /* Assets.xcassets */, 2CCE3EA42AF678B300BB0ED3 /* Preview Content */, ); @@ -138,6 +147,9 @@ buildActionMask = 2147483647; files = ( 2CCE3EA12AF678B200BB0ED3 /* ContentView.swift in Sources */, + 2CCE3EAF2AF67BA900BB0ED3 /* BinaryConverter.swift in Sources */, + 2CCE3EAD2AF67A9000BB0ED3 /* UtilsFunctions.swift in Sources */, + 2CCE3EB12AF67CFD00BB0ED3 /* HexaConverter.swift in Sources */, 2CCE3E9F2AF678B200BB0ED3 /* BinaryConverterApp.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/BinaryConverter/BinaryConverter.swift b/BinaryConverter/BinaryConverter.swift new file mode 100644 index 0000000..be29e97 --- /dev/null +++ b/BinaryConverter/BinaryConverter.swift @@ -0,0 +1,18 @@ +// +// BinaryConverter.swift +// BinaryConverter +// +// Created by Louis Gallet on 04/11/2023. +// + +import SwiftUI + +struct BinaryConverter: View { + var body: some View { + Text("Hello, Binary!") + } +} + +#Preview { + BinaryConverter() +} diff --git a/BinaryConverter/ContentView.swift b/BinaryConverter/ContentView.swift index b458812..9838d85 100644 --- a/BinaryConverter/ContentView.swift +++ b/BinaryConverter/ContentView.swift @@ -8,14 +8,14 @@ import SwiftUI struct ContentView: View { + @State private var selectedTab = 0 var body: some View { - VStack { - Image(systemName: "globe") - .imageScale(.large) - .foregroundStyle(.tint) - Text("Hello, world!") - } - .padding() + 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) + + }) } } diff --git a/BinaryConverter/HexaConverter.swift b/BinaryConverter/HexaConverter.swift new file mode 100644 index 0000000..6e49257 --- /dev/null +++ b/BinaryConverter/HexaConverter.swift @@ -0,0 +1,18 @@ +// +// HexaConverter.swift +// BinaryConverter +// +// Created by Louis Gallet on 04/11/2023. +// + +import SwiftUI + +struct HexaConverter: View { + var body: some View { + Text("Hello, Hexa!") + } +} + +#Preview { + HexaConverter() +} diff --git a/BinaryConverter/UtilsFunctions.swift b/BinaryConverter/UtilsFunctions.swift new file mode 100644 index 0000000..2a6df49 --- /dev/null +++ b/BinaryConverter/UtilsFunctions.swift @@ -0,0 +1,28 @@ +// +// UtilsFunctions.swift +// BinaryConverter +// +// Created by Louis Gallet on 04/11/2023. +// + +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 + } +}