🎉 Initial Commit
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
D40CCAE22C2DC5A9007C4A9F /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D40CCAE12C2DC5A9007C4A9F /* ContentView.swift */; };
|
||||
D40CCAE42C2DC5AA007C4A9F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D40CCAE32C2DC5AA007C4A9F /* Assets.xcassets */; };
|
||||
D40CCAE82C2DC5AA007C4A9F /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = D40CCAE72C2DC5AA007C4A9F /* Preview Assets.xcassets */; };
|
||||
D40CCAEF2C2DC5D8007C4A9F /* Subscription.swift in Sources */ = {isa = PBXBuildFile; fileRef = D40CCAEE2C2DC5D8007C4A9F /* Subscription.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
@@ -20,6 +21,7 @@
|
||||
D40CCAE32C2DC5AA007C4A9F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
D40CCAE52C2DC5AA007C4A9F /* AboTracker.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = AboTracker.entitlements; sourceTree = "<group>"; };
|
||||
D40CCAE72C2DC5AA007C4A9F /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
|
||||
D40CCAEE2C2DC5D8007C4A9F /* Subscription.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Subscription.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -57,6 +59,7 @@
|
||||
D40CCAE32C2DC5AA007C4A9F /* Assets.xcassets */,
|
||||
D40CCAE52C2DC5AA007C4A9F /* AboTracker.entitlements */,
|
||||
D40CCAE62C2DC5AA007C4A9F /* Preview Content */,
|
||||
D40CCAEE2C2DC5D8007C4A9F /* Subscription.swift */,
|
||||
);
|
||||
path = AboTracker;
|
||||
sourceTree = "<group>";
|
||||
@@ -139,6 +142,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
D40CCAEF2C2DC5D8007C4A9F /* Subscription.swift in Sources */,
|
||||
D40CCAE22C2DC5A9007C4A9F /* ContentView.swift in Sources */,
|
||||
D40CCAE02C2DC5A9007C4A9F /* AboTrackerApp.swift in Sources */,
|
||||
);
|
||||
|
||||
@@ -1,21 +1,59 @@
|
||||
//
|
||||
// ContentView.swift
|
||||
// AboTracker
|
||||
//
|
||||
// Created by Keyvan Atashfaraz on 27.06.24.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ContentView: View {
|
||||
var subs: [Subscription] = [
|
||||
Subscription(name: "Test", amount: 9.99, intervall: .monthly),
|
||||
Subscription(name: "Fitness First", amount: 8, intervall: .weekly)
|
||||
]
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Image(systemName: "globe")
|
||||
.imageScale(.large)
|
||||
.foregroundStyle(.tint)
|
||||
Text("Hello, world!")
|
||||
NavigationView {
|
||||
List {
|
||||
ForEach(subs) { sub in
|
||||
HStack {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
HStack {
|
||||
Image(systemName: "arrow.left")
|
||||
Text(sub.name)
|
||||
Spacer()
|
||||
Text("\(sub.amount, specifier: "%.2f")€/\(sub.intervall.description)")
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(7)
|
||||
.background(Color.gray.opacity(0.15))
|
||||
.cornerRadius(10)
|
||||
.padding(5)
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.padding(.vertical, 4)
|
||||
}
|
||||
.listRowInsets(EdgeInsets())
|
||||
.listRowSeparator(.hidden)
|
||||
|
||||
HStack {
|
||||
Text("Monthly Total: ")
|
||||
Spacer()
|
||||
Text("\(getMonthlyTotal(subs: subs), specifier: "%.2f€")")
|
||||
}
|
||||
.padding(.vertical, 4)
|
||||
Button("Add a Subscription", action: addSub)
|
||||
}
|
||||
.listStyle(PlainListStyle())
|
||||
.navigationTitle("Subscriptions")
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
|
||||
func getMonthlyTotal(subs: [Subscription]) -> Float {
|
||||
var monthlyTotal: Float = 0.0
|
||||
for sub in subs {
|
||||
monthlyTotal += sub.getMonthlyAmount()
|
||||
}
|
||||
return monthlyTotal
|
||||
}
|
||||
|
||||
func addSub() -> Void {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
21
AboTracker/SubView.swift
Normal file
21
AboTracker/SubView.swift
Normal file
@@ -0,0 +1,21 @@
|
||||
import SwiftUI
|
||||
|
||||
struct SubView: View {
|
||||
var subs: [Subscription] = [
|
||||
Subscription(name: "Test", amount: 9.99),
|
||||
Subscription(name: "Test 2", amount: 9.99)
|
||||
]
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
ForEach(subs) {sub in
|
||||
Text(sub.name)
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
SubView()
|
||||
}
|
||||
50
AboTracker/Subscription.swift
Normal file
50
AboTracker/Subscription.swift
Normal file
@@ -0,0 +1,50 @@
|
||||
//
|
||||
// Subscription.swift
|
||||
// AboTracker
|
||||
//
|
||||
// Created by Keyvan Atashfaraz on 27.06.24.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
final class Subscription: Identifiable {
|
||||
public let id = UUID()
|
||||
var name: String
|
||||
var amount: Float
|
||||
var intervall: PaymentIntervall
|
||||
|
||||
init(name: String, amount: Float, intervall: PaymentIntervall) {
|
||||
self.name = name
|
||||
self.amount = amount
|
||||
self.intervall = intervall
|
||||
}
|
||||
|
||||
func getMonthlyAmount() -> Float {
|
||||
switch intervall {
|
||||
case .weekly:
|
||||
return amount/7*30;
|
||||
case .monthly:
|
||||
return amount;
|
||||
case .yearly:
|
||||
return amount/12;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum PaymentIntervall: CustomStringConvertible {
|
||||
case weekly
|
||||
case monthly
|
||||
case yearly
|
||||
|
||||
var description: String {
|
||||
switch self {
|
||||
case .weekly:
|
||||
return "week"
|
||||
case .monthly:
|
||||
return "month"
|
||||
case .yearly:
|
||||
return "year"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user