feat: 🚧 Create two screens

This commit is contained in:
Louis Gallet 2023-11-04 14:24:10 +01:00
parent 9358bfe709
commit 78f2aedcd8
Signed by: lgallet
SSH Key Fingerprint: SHA256:qnW7pk4EoMRR0UftZLZQKSMUImbEFsiruLC7jbCHJAY
5 changed files with 83 additions and 7 deletions

View File

@ -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 = "<group>"; };
2CCE3EA22AF678B300BB0ED3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
2CCE3EA52AF678B300BB0ED3 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
2CCE3EAC2AF67A9000BB0ED3 /* UtilsFunctions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UtilsFunctions.swift; sourceTree = "<group>"; };
2CCE3EAE2AF67BA900BB0ED3 /* BinaryConverter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinaryConverter.swift; sourceTree = "<group>"; };
2CCE3EB02AF67CFD00BB0ED3 /* HexaConverter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HexaConverter.swift; sourceTree = "<group>"; };
/* 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;

View File

@ -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()
}

View File

@ -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)
})
}
}

View File

@ -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()
}

View File

@ -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
}
}