MVVM #6

Merged
emre.kartal merged 6 commits from MVVM into master 1 year ago

@ -2,9 +2,21 @@
<Workspace
version = "1.0">
<FileRef
location = "group:Model">
location = "group:Api">
</FileRef>
<FileRef
location = "group:AllInApp/AllInApp.xcodeproj">
</FileRef>
<FileRef
location = "group:StubLib">
</FileRef>
<FileRef
location = "group:ViewModel">
</FileRef>
<FileRef
location = "group:DependencyInjection/DependencyInjection.xcodeproj">
</FileRef>
<FileRef
location = "group:Model">
</FileRef>
</Workspace>

@ -6,6 +6,11 @@
//
import SwiftUI
import DependencyInjection
import Model
import ViewModel
import StubLib
import Api
@main
struct AllInApp: App {
@ -15,6 +20,7 @@ struct AllInApp: App {
init() {
DI.addSingleton(IAuthService.self, AuthService())
DI.addSingleton(ManagerVM.self, ManagerVM(withModel: Manager(withBetDataManager: BetStubManager(), withUserDataManager: UserApiManager())))
}
var body: some Scene {

@ -6,11 +6,13 @@
//
import SwiftUI
import Model
class AppStateContainer: ObservableObject {
static let shared = AppStateContainer()
let loggedState: LoggedState = LoggedState()
var onlineStatus: OnlineStatus = OnlineStatus()
var user: User?
@AppStorage("authenticationRefresh") var authenticationRefresh: String?
}

@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "Trophy.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

@ -13,7 +13,7 @@ struct AllcoinsCounter: View {
Image("allcoinIcon")
.resizable()
.frame(width: 17, height: 17, alignment: .leading)
Text("541")
Text(String(AppStateContainer.shared.user?.nbCoins ?? 0))
.fontWeight(.black)
.foregroundColor(AllInColors.primaryColor)
}

@ -19,7 +19,7 @@ struct Menu: View {
.scaledToFit()
.frame(width: 100, height: 100)
.cornerRadius(180)
Text("Pseudo")
Text(AppStateContainer.shared.user?.username.capitalized ?? "")
.fontWeight(.medium)
.font(.system(size: 17))
.foregroundColor(.white)
@ -87,6 +87,11 @@ struct Menu: View {
ParameterMenu(image: "moneyImage", title: "BET EN COURS", description: "Gérez vos bets et récompensez les gagnants.")
.padding([.leading,.trailing], 13)
}
NavigationLink(destination: MainView(page: "Ranking").navigationBarBackButtonHidden(true))
{
ParameterMenu(image: "rankingImage", title: "CLASSEMENT", description: "Consultez votre classement parmis vos amis.")
.padding([.leading,.trailing], 13)
}
Spacer()
Image("gearIcon")

@ -16,6 +16,8 @@ struct ParameterMenu: View {
var body: some View {
HStack {
Image(image)
.resizable()
.frame(width: 28, height: 28)
VStack(alignment: .leading){
Text(title)
.textStyle(weight: .bold, color: .white, size: 14)

@ -6,6 +6,7 @@
//
import SwiftUI
import DependencyInjection
struct ContentView: View {
@ -14,17 +15,20 @@ struct ContentView: View {
var body: some View {
VStack {
NavigationView {
if loggedState.connectedUser {
if loggedState.connectedUser {
NavigationView {
MainView(page: "Bet")
} else {
}
.navigationViewStyle(StackNavigationViewStyle())
} else {
NavigationView {
WelcomeView()
}
.navigationViewStyle(StackNavigationViewStyle())
}
.navigationViewStyle(StackNavigationViewStyle())
}
.onAppear {
//authService.refreshAuthentication() { status in }
authService.refreshAuthentication()
}
}
}

@ -1,22 +0,0 @@
//
// User.swift
// AllIn
//
// Created by Emre on 11/10/2023.
//
import Foundation
class User {
public var username: String
public var email: String
public var nbCoins: Int
public init(username: String, email: String, nbCoins: Int)
{
self.username = username
self.email = email
self.nbCoins = nbCoins
}
}

@ -6,6 +6,7 @@
//
import Foundation
import Model
class AuthService: IAuthService {
@ -30,9 +31,14 @@ class AuthService: IAuthService {
let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
let token = json["token"] as? String {
AppStateContainer.shared.authenticationRefresh = token;
self.initializeUser(withToken: token) { status in
if status != 200 {
completion(status)
AppStateContainer.shared.authenticationRefresh = nil;
}
}
}
}
completion(httpResponse.statusCode)
}
}.resume()
@ -56,19 +62,33 @@ class AuthService: IAuthService {
URLSession.shared.uploadTask(with: request, from: jsonData) { data, response, error in
print ("ALLIN : Process REGISTER")
if let httpResponse = response as? HTTPURLResponse {
if httpResponse.statusCode == 201 {
if let data = data,
let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
let token = json["token"] as? String {
AppStateContainer.shared.authenticationRefresh = token;
self.initializeUser(withToken: token) { status in
if status != 200 {
completion(status)
AppStateContainer.shared.authenticationRefresh = nil;
}
}
}
}
completion(httpResponse.statusCode)
}
}.resume()
}
}
func refreshAuthentication(completion: @escaping (Int) -> ()) {
func refreshAuthentication() {
guard let token = AppStateContainer.shared.authenticationRefresh else {
completion(401)
return
}
print(token)
let url = URL(string: Config.allInApi + "users/token")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
@ -76,13 +96,45 @@ class AuthService: IAuthService {
request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
URLSession.shared.dataTask(with: request) { data, response, error in
if let httpResponse = response as? HTTPURLResponse {
completion(httpResponse.statusCode)
if let data = data,
let httpResponse = response as? HTTPURLResponse {
if httpResponse.statusCode == 200 {
AppStateContainer.shared.loggedState.connectedUser = true
if let userJson = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
let user = User.mapUser(from: userJson) {
AppStateContainer.shared.user = user
AppStateContainer.shared.loggedState.connectedUser = true
}
} else {
AppStateContainer.shared.authenticationRefresh = nil
}
}
}.resume()
}
private func initializeUser(withToken token: String, completion: @escaping (Int) -> ()) {
let url = URL(string: Config.allInApi + "users/token")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
URLSession.shared.dataTask(with: request) { data, response, error in
if let data = data,
let httpResponse = response as? HTTPURLResponse {
if httpResponse.statusCode == 200 {
if let userJson = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any],
let user = User.mapUser(from: userJson) {
completion(httpResponse.statusCode)
AppStateContainer.shared.user = user
}
} else {
completion(httpResponse.statusCode)
}
} else {
completion(500)
}
}.resume()
}
}

@ -10,5 +10,5 @@ import Foundation
protocol IAuthService {
func login(login: String, password: String, completion : @escaping (Int)-> ())
func register(username: String, email: String, password: String, completion : @escaping (Int)-> ())
func refreshAuthentication(completion: @escaping (Int) -> ())
func refreshAuthentication()
}

@ -0,0 +1,35 @@
//
// BetViewModel.swift
// AllIn
//
// Created by Emre on 30/12/2023.
//
import Foundation
import DependencyInjection
import ViewModel
class BetViewModel: ObservableObject {
@Inject var manager: ManagerVM
init() {
getItems()
}
func getItems() {
}
func deleteItem(indexSet: IndexSet) {
}
func moveltem(from: IndexSet, to: Int) {
}
func addItem(title: String) {
}
}

@ -0,0 +1,95 @@
//
// CreationBetViewModel.swift
// AllIn
//
// Created by Emre on 30/12/2023.
//
import Foundation
import SwiftUI
import DependencyInjection
import ViewModel
class CreationBetViewModel: ObservableObject {
@Inject var manager: ManagerVM
@Published var theme: String = ""
@Published var description: String = ""
@Published var isPublic = true
@Published var endRegisterDate = Date()
@Published var endBetDate = Date()
@Published var themeFieldError: String?
@Published var descriptionFieldError: String?
@Published var endRegisterDateFieldError: String?
@Published var endBetDateFieldError: String?
func create() {
guard checkAndSetError(forTheme: true, forDescription: true, forEndRegisterDate: true, forEndBetDate: true) else {
return
}
resetAllFieldErrors()
if let user = AppStateContainer.shared.user {
manager.addBet(theme: theme, description: description, endRegister: endRegisterDate, endBet: endBetDate, isPublic: isPublic, creator: user)
}
}
func checkAndSetError(forTheme checkTheme: Bool, forDescription checkDescription: Bool, forEndRegisterDate checkEndRegisterDate: Bool, forEndBetDate checkEndBetDate: Bool) -> Bool {
var newThemeFieldError: String?
var newDescriptionFieldError: String?
var newEndRegisterDateFieldError: String?
var newEndBetDateFieldError: String?
var hasError = false
// Theme
if checkTheme, theme.isEmpty {
newThemeFieldError = "Veuillez saisir le thème."
hasError = true
}
// Description
if checkDescription, description.isEmpty {
newDescriptionFieldError = "Veuillez saisir la description."
hasError = true
}
// End Register Date
if checkEndRegisterDate, endRegisterDate < Date() {
newEndRegisterDateFieldError = "La date de fin des inscriptions doit être ultérieure à la date actuelle."
hasError = true
}
// End Bet Date
if checkEndBetDate, endBetDate < endRegisterDate {
newEndBetDateFieldError = "La date de fin des paris doit être ultérieure à la date de fin des inscriptions."
hasError = true
}
if !hasError {
// No error
return true
}
withAnimation {
themeFieldError = newThemeFieldError
descriptionFieldError = newDescriptionFieldError
endRegisterDateFieldError = newEndRegisterDateFieldError
endBetDateFieldError = newEndBetDateFieldError
}
return false
}
func resetAllFieldErrors() {
withAnimation {
themeFieldError = nil
descriptionFieldError = nil
endRegisterDateFieldError = nil
endBetDateFieldError = nil
}
}
}

@ -0,0 +1,35 @@
//
// FriendsViewModel.swift
// AllIn
//
// Created by Emre on 30/12/2023.
//
import Foundation
import DependencyInjection
import ViewModel
class FriendsViewModel: ObservableObject {
@Inject var manager: ManagerVM
init() {
getItems()
}
func getItems ( ) {
}
func deleteItem(indexSet: IndexSet) {
}
func moveltem(from: IndexSet, to: Int) {
}
func addItem(title: String) {
}
}

@ -7,6 +7,7 @@
import Foundation
import SwiftUI
import DependencyInjection
class LoginViewModel: ObservableObject {

@ -0,0 +1,35 @@
//
// RankingViewModel.swift
// AllIn
//
// Created by Emre on 30/12/2023.
//
import Foundation
import DependencyInjection
import ViewModel
class RankingViewModel: ObservableObject {
@Inject var manager: ManagerVM
init() {
getItems()
}
func getItems ( ) {
}
func deleteItem(indexSet: IndexSet) {
}
func moveltem(from: IndexSet, to: Int) {
}
func addItem(title: String) {
}
}

@ -7,6 +7,7 @@
import Foundation
import SwiftUI
import DependencyInjection
class RegisterViewModel: ObservableObject {

@ -9,6 +9,7 @@ import SwiftUI
struct BetView: View {
@StateObject private var viewModel = BetViewModel()
@Binding var showMenu: Bool
@State private var showingSheet = false

@ -9,26 +9,25 @@ import SwiftUI
struct CreationBetView: View {
@StateObject private var viewModel = CreationBetViewModel()
@Binding var showMenu: Bool
@State private var selectedTab = 0
// Popovers
@State private var showTitlePopover: Bool = false
@State private var showDescriptionPopover: Bool = false
@State private var showRegistrationEndDatePopover: Bool = false
@State private var showBetEndDatePopover: Bool = false
@State private var showConfidentialityPopover: Bool = false
@State private var selectedTab = 0
@Binding var showMenu: Bool
@State var selectedConfidentiality = true
@State private var theme: String = ""
@State private var description: String = ""
@State var present = false
@State private var endRegisterDate = Date()
@State private var endBetDate = Date()
let dateRange: ClosedRange<Date> = {
let calendar = Calendar.current
let startDate = Date()
let endDate = calendar.date(byAdding: .year, value: 10, to: startDate)!
return startDate ... endDate
}()
let screenWidth = UIScreen.main.bounds.width
@State private var response = ""
@State private var values: [String] = []
@ -40,7 +39,6 @@ struct CreationBetView: View {
]
@State var groupedItems: [[String]] = [[String]] ()
let screenWidth = UIScreen.main.bounds.width
private func updateGroupedItems() {
@ -99,23 +97,29 @@ struct CreationBetView: View {
.frame(width: 340)
.padding(.leading, 10)
TextField("", text: $theme, prompt: Text("Études, sport, soirée...")
.foregroundColor(AllInColors.lightGrey300Color)
.font(.system(size: 14))
.fontWeight(.light))
.padding()
.background(
RoundedRectangle(cornerRadius: 9)
.fill(AllInColors.componentBackgroundColor)
.frame(height: 40)
)
.frame(width: 350, height: 40)
.foregroundColor(.black)
.overlay(
RoundedRectangle(cornerRadius: 10, style: .continuous)
.stroke(AllInColors.delimiterGrey, lineWidth: 1)
)
.padding(.bottom, 5)
VStack {
if let themeError = $viewModel.themeFieldError.wrappedValue {
Text(themeError)
.textStyle(weight: .bold, color: .red, size: 10)
}
TextField("", text: $viewModel.theme, prompt: Text("Études, sport, soirée...")
.foregroundColor(AllInColors.lightGrey300Color)
.font(.system(size: 14))
.fontWeight(.light))
.padding()
.background(
RoundedRectangle(cornerRadius: 9)
.fill(AllInColors.componentBackgroundColor)
.frame(height: 40)
)
.frame(width: 350, height: 40)
.foregroundColor(.black)
.overlay(
RoundedRectangle(cornerRadius: 10, style: .continuous)
.stroke(AllInColors.delimiterGrey, lineWidth: 1)
)
.padding(.bottom, 5)
}
}
HStack(spacing: 5) {
@ -134,24 +138,30 @@ struct CreationBetView: View {
.frame(width: 340)
.padding(.leading, 10)
TextField("", text: $description, prompt: Text("David sera absent Lundi matin en cours ?")
.foregroundColor(AllInColors.lightGrey300Color)
.font(.system(size: 14))
.fontWeight(.light), axis: .vertical)
.lineLimit(4, reservesSpace: true)
.padding()
.background(
RoundedRectangle(cornerRadius: 9)
.fill(AllInColors.componentBackgroundColor)
.frame(height: 110)
)
.frame(width: 350, height: 110)
.foregroundColor(.black)
.overlay(
RoundedRectangle(cornerRadius: 10, style: .continuous)
.stroke(AllInColors.delimiterGrey, lineWidth: 1)
)
.padding(.bottom, 30)
VStack {
if let descriptionError = $viewModel.descriptionFieldError.wrappedValue {
Text(descriptionError)
.textStyle(weight: .bold, color: .red, size: 10)
}
TextField("", text: $viewModel.description, prompt: Text("David sera absent Lundi matin en cours ?")
.foregroundColor(AllInColors.lightGrey300Color)
.font(.system(size: 14))
.fontWeight(.light), axis: .vertical)
.lineLimit(4, reservesSpace: true)
.padding()
.background(
RoundedRectangle(cornerRadius: 9)
.fill(AllInColors.componentBackgroundColor)
.frame(height: 110)
)
.frame(width: 350, height: 110)
.foregroundColor(.black)
.overlay(
RoundedRectangle(cornerRadius: 10, style: .continuous)
.stroke(AllInColors.delimiterGrey, lineWidth: 1)
)
.padding(.bottom, 30)
}
HStack(spacing: 5) {
Text("Date de fin des inscriptions")
@ -168,19 +178,25 @@ struct CreationBetView: View {
.frame(width: 340)
.padding(.leading, 10)
HStack(spacing: 5) {
DatePicker(
"",
selection: $endRegisterDate,
in: dateRange,
displayedComponents: [.date, .hourAndMinute]
)
.accentColor(AllInColors.lightPurpleColor)
.labelsHidden()
.padding(.bottom, 10)
Spacer()
VStack {
if let endRegisterError = $viewModel.endRegisterDateFieldError.wrappedValue {
Text(endRegisterError)
.textStyle(weight: .bold, color: .red, size: 10)
}
HStack(spacing: 5) {
DatePicker(
"",
selection: $viewModel.endRegisterDate,
in: dateRange,
displayedComponents: [.date, .hourAndMinute]
)
.accentColor(AllInColors.lightPurpleColor)
.labelsHidden()
.padding(.bottom, 10)
Spacer()
}
.frame(width: 340)
}
.frame(width: 340)
VStack(alignment: .leading, spacing: 5) {
VStack() {
@ -199,15 +215,25 @@ struct CreationBetView: View {
}
.padding(.leading, 10)
}
DatePicker(
"",
selection: $endBetDate,
in: dateRange,
displayedComponents: [.date, .hourAndMinute]
)
.accentColor(AllInColors.lightPurpleColor)
.labelsHidden()
.padding(.bottom, 40)
VStack {
if let endBetError = $viewModel.endBetDateFieldError.wrappedValue {
Text(endBetError)
.textStyle(weight: .bold, color: .red, size: 10)
}
HStack(spacing: 5) {
DatePicker(
"",
selection: $viewModel.endBetDate,
in: dateRange,
displayedComponents: [.date, .hourAndMinute]
)
.accentColor(AllInColors.lightPurpleColor)
.labelsHidden()
.padding(.bottom, 40)
Spacer()
}
}
}
.frame(width: 340)
@ -227,15 +253,15 @@ struct CreationBetView: View {
.padding(.leading, 10)
HStack(spacing: 5) {
ConfidentialityButton(image: "globe", text: "Public", selected: !selectedConfidentiality)
ConfidentialityButton(image: "globe", text: "Public", selected: viewModel.isPublic)
.onTapGesture {
selectedConfidentiality = false
viewModel.isPublic = true
}
.padding(.trailing, 5)
ConfidentialityButton(image: "lock", text: "Privé", selected: selectedConfidentiality)
ConfidentialityButton(image: "lock", text: "Privé", selected: !viewModel.isPublic)
.onTapGesture {
selectedConfidentiality = true
viewModel.isPublic = false
}
Spacer()
}
@ -246,7 +272,7 @@ struct CreationBetView: View {
VStack(spacing: 10) {
if self.selectedConfidentiality {
if !self.viewModel.isPublic {
DropDownFriends()
.padding(.bottom, 30)
}
@ -277,7 +303,9 @@ struct CreationBetView: View {
Spacer()
HStack() {
Spacer()
Button(action: {}) {
Button(action: {
viewModel.create()
}) {
Text("Publier le bet")
.font(.system(size: 24))
.fontWeight(.bold)

@ -7,6 +7,10 @@
objects = {
/* Begin PBXBuildFile section */
122278B82B4BDE1100E632AA /* DependencyInjection.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 122278B72B4BDE1100E632AA /* DependencyInjection.framework */; };
1257EB1F2B4BE008005509B0 /* Model in Frameworks */ = {isa = PBXBuildFile; productRef = 1257EB1E2B4BE008005509B0 /* Model */; };
1257EB212B4BE008005509B0 /* StubLib in Frameworks */ = {isa = PBXBuildFile; productRef = 1257EB202B4BE008005509B0 /* StubLib */; };
1257EB232B4BE008005509B0 /* ViewModel in Frameworks */ = {isa = PBXBuildFile; productRef = 1257EB222B4BE008005509B0 /* ViewModel */; };
EC0193782B25BF16005D81E6 /* AllcoinsCapsule.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC0193772B25BF16005D81E6 /* AllcoinsCapsule.swift */; };
EC01937A2B25C12B005D81E6 /* BetCard.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC0193792B25C12B005D81E6 /* BetCard.swift */; };
EC01937C2B25C2A8005D81E6 /* AllcoinsCounter.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC01937B2B25C2A8005D81E6 /* AllcoinsCounter.swift */; };
@ -36,8 +40,6 @@
EC6B96AD2B24B4CC00FC1C58 /* AllInTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96AC2B24B4CC00FC1C58 /* AllInTests.swift */; };
EC6B96B72B24B4CC00FC1C58 /* AllInUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96B62B24B4CC00FC1C58 /* AllInUITests.swift */; };
EC6B96B92B24B4CC00FC1C58 /* AllInUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96B82B24B4CC00FC1C58 /* AllInUITestsLaunchTests.swift */; };
EC6B96C72B24B5A100FC1C58 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96C62B24B5A100FC1C58 /* User.swift */; };
EC6B96C92B24B69B00FC1C58 /* DependancyInjection.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96C82B24B69B00FC1C58 /* DependancyInjection.swift */; };
EC6B96CC2B24B7E500FC1C58 /* IAuthService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96CB2B24B7E500FC1C58 /* IAuthService.swift */; };
EC6B96CF2B24B8D900FC1C58 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96CE2B24B8D900FC1C58 /* Config.swift */; };
EC6B96D12B24BAE800FC1C58 /* AuthService.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC6B96D02B24BAE800FC1C58 /* AuthService.swift */; };
@ -49,10 +51,16 @@
EC89F7BD2B250D66003821CE /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EC89F7BC2B250D66003821CE /* LoginView.swift */; };
ECA9D1C92B2D9ADA0076E0EC /* UserInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECA9D1C82B2D9ADA0076E0EC /* UserInfo.swift */; };
ECA9D1CB2B2DA2320076E0EC /* DropDownFriends.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECA9D1CA2B2DA2320076E0EC /* DropDownFriends.swift */; };
ECB26A132B406A9400FE06B3 /* BetViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB26A122B406A9400FE06B3 /* BetViewModel.swift */; };
ECB26A172B4073F100FE06B3 /* CreationBetViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB26A162B4073F100FE06B3 /* CreationBetViewModel.swift */; };
ECB26A192B40744F00FE06B3 /* RankingViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB26A182B40744F00FE06B3 /* RankingViewModel.swift */; };
ECB26A1B2B40746C00FE06B3 /* FriendsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB26A1A2B40746C00FE06B3 /* FriendsViewModel.swift */; };
ECB357322B3CA69300045D41 /* DependencyInjection.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = ECB357302B3CA69300045D41 /* DependencyInjection.framework */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
ECB7BC682B2F1ADF002A6654 /* LoginViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB7BC672B2F1ADF002A6654 /* LoginViewModel.swift */; };
ECB7BC6A2B2F410A002A6654 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB7BC692B2F410A002A6654 /* AppDelegate.swift */; };
ECB7BC6C2B2F43EE002A6654 /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB7BC6B2B2F43EE002A6654 /* AppState.swift */; };
ECB7BC702B336E28002A6654 /* RegisterViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB7BC6F2B336E28002A6654 /* RegisterViewModel.swift */; };
ECCD244A2B4DE8010071FA9E /* Api in Frameworks */ = {isa = PBXBuildFile; productRef = ECCD24492B4DE8010071FA9E /* Api */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -72,7 +80,24 @@
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
ECB357332B3CA69300045D41 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
ECB357322B3CA69300045D41 /* DependencyInjection.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
122278B72B4BDE1100E632AA /* DependencyInjection.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DependencyInjection.framework; sourceTree = BUILT_PRODUCTS_DIR; };
122278B92B4BDE9500E632AA /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = Package.swift; path = ../Model/Package.swift; sourceTree = "<group>"; };
122278BB2B4BDEC300E632AA /* Sources */ = {isa = PBXFileReference; lastKnownFileType = folder; name = Sources; path = ../StubLib/Sources; sourceTree = "<group>"; };
EC0193772B25BF16005D81E6 /* AllcoinsCapsule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllcoinsCapsule.swift; sourceTree = "<group>"; };
EC0193792B25C12B005D81E6 /* BetCard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BetCard.swift; sourceTree = "<group>"; };
EC01937B2B25C2A8005D81E6 /* AllcoinsCounter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllcoinsCounter.swift; sourceTree = "<group>"; };
@ -105,8 +130,6 @@
EC6B96B22B24B4CC00FC1C58 /* AllInUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AllInUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
EC6B96B62B24B4CC00FC1C58 /* AllInUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllInUITests.swift; sourceTree = "<group>"; };
EC6B96B82B24B4CC00FC1C58 /* AllInUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllInUITestsLaunchTests.swift; sourceTree = "<group>"; };
EC6B96C62B24B5A100FC1C58 /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
EC6B96C82B24B69B00FC1C58 /* DependancyInjection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DependancyInjection.swift; sourceTree = "<group>"; };
EC6B96CB2B24B7E500FC1C58 /* IAuthService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IAuthService.swift; sourceTree = "<group>"; };
EC6B96CE2B24B8D900FC1C58 /* Config.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = "<group>"; };
EC6B96D02B24BAE800FC1C58 /* AuthService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthService.swift; sourceTree = "<group>"; };
@ -118,6 +141,12 @@
EC89F7BC2B250D66003821CE /* LoginView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = "<group>"; };
ECA9D1C82B2D9ADA0076E0EC /* UserInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserInfo.swift; sourceTree = "<group>"; };
ECA9D1CA2B2DA2320076E0EC /* DropDownFriends.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropDownFriends.swift; sourceTree = "<group>"; };
ECB26A122B406A9400FE06B3 /* BetViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BetViewModel.swift; sourceTree = "<group>"; };
ECB26A162B4073F100FE06B3 /* CreationBetViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreationBetViewModel.swift; sourceTree = "<group>"; };
ECB26A182B40744F00FE06B3 /* RankingViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RankingViewModel.swift; sourceTree = "<group>"; };
ECB26A1A2B40746C00FE06B3 /* FriendsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FriendsViewModel.swift; sourceTree = "<group>"; };
ECB3572E2B3CA3C300045D41 /* DependencyInjection.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DependencyInjection.framework; sourceTree = BUILT_PRODUCTS_DIR; };
ECB357302B3CA69300045D41 /* DependencyInjection.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = DependencyInjection.framework; sourceTree = BUILT_PRODUCTS_DIR; };
ECB7BC672B2F1ADF002A6654 /* LoginViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewModel.swift; sourceTree = "<group>"; };
ECB7BC692B2F410A002A6654 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
ECB7BC6B2B2F43EE002A6654 /* AppState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppState.swift; sourceTree = "<group>"; };
@ -129,6 +158,11 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
EC8B9CCE2B42C9D3002806F3 /* StubLib in Frameworks */,
ECB357352B3E13A400045D41 /* Model in Frameworks */,
ECCD244A2B4DE8010071FA9E /* Api in Frameworks */,
ECB357312B3CA69300045D41 /* DependencyInjection.framework in Frameworks */,
ECB26A152B406B4800FE06B3 /* ViewModel in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -156,6 +190,7 @@
EC6B96AB2B24B4CC00FC1C58 /* AllInTests */,
EC6B96B52B24B4CC00FC1C58 /* AllInUITests */,
EC6B96992B24B4CC00FC1C58 /* Products */,
ECB3572D2B3CA3BD00045D41 /* Frameworks */,
);
sourceTree = "<group>";
};
@ -178,14 +213,13 @@
EC6B96D22B24BC4F00FC1C58 /* Extensions */,
EC6B96CD2B24B8A300FC1C58 /* Ressources */,
EC6B96CA2B24B7B300FC1C58 /* Services */,
EC6B96C52B24B58700FC1C58 /* Models */,
EC6B969B2B24B4CC00FC1C58 /* AllInApp.swift */,
EC6B969D2B24B4CC00FC1C58 /* ContentView.swift */,
EC6B969F2B24B4CC00FC1C58 /* Assets.xcassets */,
EC6B96A12B24B4CC00FC1C58 /* Preview Content */,
EC650A612B28CB72003AFCAD /* Launch Screen.storyboard */,
ECB7BC692B2F410A002A6654 /* AppDelegate.swift */,
ECB7BC6B2B2F43EE002A6654 /* AppState.swift */,
EC6B96A12B24B4CC00FC1C58 /* Preview Content */,
);
path = AllIn;
sourceTree = "<group>";
@ -215,15 +249,6 @@
path = AllInUITests;
sourceTree = "<group>";
};
EC6B96C52B24B58700FC1C58 /* Models */ = {
isa = PBXGroup;
children = (
EC6B96C62B24B5A100FC1C58 /* User.swift */,
EC6B96C82B24B69B00FC1C58 /* DependancyInjection.swift */,
);
path = Models;
sourceTree = "<group>";
};
EC6B96CA2B24B7B300FC1C58 /* Services */ = {
isa = PBXGroup;
children = (
@ -291,11 +316,27 @@
path = Components;
sourceTree = "<group>";
};
ECB3572D2B3CA3BD00045D41 /* Frameworks */ = {
isa = PBXGroup;
children = (
122278BB2B4BDEC300E632AA /* Sources */,
122278B92B4BDE9500E632AA /* Package.swift */,
122278B72B4BDE1100E632AA /* DependencyInjection.framework */,
ECB357302B3CA69300045D41 /* DependencyInjection.framework */,
ECB3572E2B3CA3C300045D41 /* DependencyInjection.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
ECB7BC662B2F1AAD002A6654 /* ViewModels */ = {
isa = PBXGroup;
children = (
ECB7BC672B2F1ADF002A6654 /* LoginViewModel.swift */,
ECB7BC6F2B336E28002A6654 /* RegisterViewModel.swift */,
ECB26A122B406A9400FE06B3 /* BetViewModel.swift */,
ECB26A162B4073F100FE06B3 /* CreationBetViewModel.swift */,
ECB26A182B40744F00FE06B3 /* RankingViewModel.swift */,
ECB26A1A2B40746C00FE06B3 /* FriendsViewModel.swift */,
);
path = ViewModels;
sourceTree = "<group>";
@ -310,6 +351,7 @@
EC6B96942B24B4CC00FC1C58 /* Sources */,
EC6B96952B24B4CC00FC1C58 /* Frameworks */,
EC6B96962B24B4CC00FC1C58 /* Resources */,
ECB357332B3CA69300045D41 /* Embed Frameworks */,
);
buildRules = (
);
@ -317,6 +359,10 @@
);
name = AllIn;
packageProductDependencies = (
ECB357342B3E13A400045D41 /* Model */,
ECB26A142B406B4800FE06B3 /* ViewModel */,
EC8B9CCD2B42C9D3002806F3 /* StubLib */,
ECCD24492B4DE8010071FA9E /* Api */,
);
productName = AllIn;
productReference = EC6B96982B24B4CC00FC1C58 /* AllIn.app */;
@ -436,25 +482,26 @@
buildActionMask = 2147483647;
files = (
EC6B96CC2B24B7E500FC1C58 /* IAuthService.swift in Sources */,
ECB26A172B4073F100FE06B3 /* CreationBetViewModel.swift in Sources */,
EC3077092B24CF7F0060E34D /* Colors.swift in Sources */,
ECB7BC6A2B2F410A002A6654 /* AppDelegate.swift in Sources */,
EC6B969E2B24B4CC00FC1C58 /* ContentView.swift in Sources */,
EC89F7BD2B250D66003821CE /* LoginView.swift in Sources */,
EC650A442B25CDF3003AFCAD /* ParameterMenu.swift in Sources */,
ECB26A132B406A9400FE06B3 /* BetViewModel.swift in Sources */,
EC30770F2B24FCB00060E34D /* RegisterView.swift in Sources */,
EC650A522B2794DD003AFCAD /* BetView.swift in Sources */,
EC6B969C2B24B4CC00FC1C58 /* AllInApp.swift in Sources */,
ECB26A192B40744F00FE06B3 /* RankingViewModel.swift in Sources */,
EC650A502B2793D5003AFCAD /* TextCapsule.swift in Sources */,
EC650A482B25DCFF003AFCAD /* UsersPreview.swift in Sources */,
EC650A462B25D686003AFCAD /* RankingRow.swift in Sources */,
EC01937A2B25C12B005D81E6 /* BetCard.swift in Sources */,
EC650A422B25C817003AFCAD /* Friend.swift in Sources */,
EC6B96C92B24B69B00FC1C58 /* DependancyInjection.swift in Sources */,
EC7A882F2B28E6BE004F226A /* ConfidentialityButton.swift in Sources */,
ECB7BC702B336E28002A6654 /* RegisterViewModel.swift in Sources */,
EC650A4C2B25E9C7003AFCAD /* RankingView.swift in Sources */,
EC7A882B2B28D1E0004F226A /* DropDownMenu.swift in Sources */,
EC6B96C72B24B5A100FC1C58 /* User.swift in Sources */,
EC7A882D2B28D8A1004F226A /* CreationBetView.swift in Sources */,
EC6B96CF2B24B8D900FC1C58 /* Config.swift in Sources */,
EC30770B2B24D9160060E34D /* WelcomeView.swift in Sources */,
@ -466,6 +513,7 @@
EC3077072B24CB840060E34D /* SplashView.swift in Sources */,
EC01937E2B25C52E005D81E6 /* TopBar.swift in Sources */,
ECA9D1CB2B2DA2320076E0EC /* DropDownFriends.swift in Sources */,
ECB26A1B2B40746C00FE06B3 /* FriendsViewModel.swift in Sources */,
ECB7BC682B2F1ADF002A6654 /* LoginViewModel.swift in Sources */,
EC6B96D52B24BE0E00FC1C58 /* MainView.swift in Sources */,
EC650A562B279D68003AFCAD /* WinModal.swift in Sources */,
@ -633,6 +681,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"AllIn/Preview Content\"";
DEVELOPMENT_TEAM = 35KQ5BDC64;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = "All In";
@ -664,6 +713,7 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"AllIn/Preview Content\"";
DEVELOPMENT_TEAM = 35KQ5BDC64;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = "All In";
@ -799,6 +849,29 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
/* Begin XCSwiftPackageProductDependency section */
1257EB1E2B4BE008005509B0 /* Model */ = {
isa = XCSwiftPackageProductDependency;
productName = Model;
};
1257EB202B4BE008005509B0 /* StubLib */ = {
isa = XCSwiftPackageProductDependency;
productName = StubLib;
};
1257EB222B4BE008005509B0 /* ViewModel */ = {
isa = XCSwiftPackageProductDependency;
productName = ViewModel;
};
ECB357342B3E13A400045D41 /* Model */ = {
isa = XCSwiftPackageProductDependency;
productName = Model;
};
ECCD24492B4DE8010071FA9E /* Api */ = {
isa = XCSwiftPackageProductDependency;
productName = Api;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = EC6B96902B24B4CC00FC1C58 /* Project object */;
}

@ -10,43 +10,26 @@ import XCTest
final class AllInTests: XCTestCase {
func testInstance() {
DependencyInjection.shared.addSingleton(UserTest.self, UserTest(age: 10))
let view1 = View1()
let view2 = View2()
XCTAssertEqual(view1.getAge(), view2.getAge())
view1.setAge()
XCTAssertEqual(view1.getAge(), view2.getAge())
view2.setAge()
XCTAssertEqual(view1.getAge(), view2.getAge())
override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}
class UserTest {
public var age:Int
init(age:Int) {
self.age = age
}
override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
class View1 {
@Inject private var user:UserTest
func getAge() -> Int {
return user.age
}
func setAge() {
user.age = 20
}
func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}
class View2 {
@Inject private var user:UserTest
func getAge() -> Int {
return user.age
}
func setAge() {
user.age = 40
func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}

@ -0,0 +1,25 @@
// swift-tools-version: 5.8
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "Api",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "Api",
targets: ["Api"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "Api",
dependencies: []),
]
)

@ -0,0 +1,3 @@
# Api
A description of this package.

@ -0,0 +1,52 @@
//
// UserApiManager.swift
//
//
// Created by Emre on 31/12/2023.
//
import Foundation
import Model
let allInApi = "https://codefirst.iut.uca.fr/containers/AllDev-api"
public struct UserApiManager: UserDataManager {
public init() {
}
public func getBets(withIndex index: Int, withCount count: Int) -> [Bet] {
fatalError("Not implemented yet")
}
public func addBet(bet: Bet) {
let url = URL(string: allInApi + "bets/add")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let json = [
"theme": bet.theme,
"sentenceBet": bet.phrase,
"endRegistration": dateFormatter.string(from: bet.endRegisterDate),
"endBet": dateFormatter.string(from: bet.endBetDate),
"isPrivate": String(bet.isPublic),
"response": "",
"createdBy": ""
]
if let jsonData = try? JSONSerialization.data(withJSONObject: json, options: []){
URLSession.shared.uploadTask(with: request, from: jsonData) { data, response, error in
}.resume()
}
}
public func getFriends() -> [User] {
fatalError("Not implemented yet")
}
}

@ -0,0 +1,486 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 56;
objects = {
/* Begin PBXBuildFile section */
ECB3572C2B3CA37800045D41 /* DependencyInjection.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECB3572B2B3CA37800045D41 /* DependencyInjection.swift */; };
ECEE18B82B3C9CF400C95E8A /* DependencyInjection.docc in Sources */ = {isa = PBXBuildFile; fileRef = ECEE18B72B3C9CF400C95E8A /* DependencyInjection.docc */; };
ECEE18BE2B3C9CF400C95E8A /* DependencyInjection.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ECEE18B32B3C9CF400C95E8A /* DependencyInjection.framework */; };
ECEE18C32B3C9CF400C95E8A /* DependencyInjectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECEE18C22B3C9CF400C95E8A /* DependencyInjectionTests.swift */; };
ECEE18C42B3C9CF400C95E8A /* DependencyInjection.h in Headers */ = {isa = PBXBuildFile; fileRef = ECEE18B62B3C9CF400C95E8A /* DependencyInjection.h */; settings = {ATTRIBUTES = (Public, ); }; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
ECEE18BF2B3C9CF400C95E8A /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = ECEE18AA2B3C9CF400C95E8A /* Project object */;
proxyType = 1;
remoteGlobalIDString = ECEE18B22B3C9CF400C95E8A;
remoteInfo = DependencyInjection;
};
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
ECB3572B2B3CA37800045D41 /* DependencyInjection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DependencyInjection.swift; sourceTree = "<group>"; };
ECEE18B32B3C9CF400C95E8A /* DependencyInjection.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DependencyInjection.framework; sourceTree = BUILT_PRODUCTS_DIR; };
ECEE18B62B3C9CF400C95E8A /* DependencyInjection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DependencyInjection.h; sourceTree = "<group>"; };
ECEE18B72B3C9CF400C95E8A /* DependencyInjection.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = DependencyInjection.docc; sourceTree = "<group>"; };
ECEE18BD2B3C9CF400C95E8A /* DependencyInjectionTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DependencyInjectionTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
ECEE18C22B3C9CF400C95E8A /* DependencyInjectionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DependencyInjectionTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
ECEE18B02B3C9CF400C95E8A /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
ECEE18BA2B3C9CF400C95E8A /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
ECEE18BE2B3C9CF400C95E8A /* DependencyInjection.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
ECEE18A92B3C9CF400C95E8A = {
isa = PBXGroup;
children = (
ECEE18B52B3C9CF400C95E8A /* DependencyInjection */,
ECEE18C12B3C9CF400C95E8A /* DependencyInjectionTests */,
ECEE18B42B3C9CF400C95E8A /* Products */,
);
sourceTree = "<group>";
};
ECEE18B42B3C9CF400C95E8A /* Products */ = {
isa = PBXGroup;
children = (
ECEE18B32B3C9CF400C95E8A /* DependencyInjection.framework */,
ECEE18BD2B3C9CF400C95E8A /* DependencyInjectionTests.xctest */,
);
name = Products;
sourceTree = "<group>";
};
ECEE18B52B3C9CF400C95E8A /* DependencyInjection */ = {
isa = PBXGroup;
children = (
ECEE18B62B3C9CF400C95E8A /* DependencyInjection.h */,
ECEE18B72B3C9CF400C95E8A /* DependencyInjection.docc */,
ECB3572B2B3CA37800045D41 /* DependencyInjection.swift */,
);
path = DependencyInjection;
sourceTree = "<group>";
};
ECEE18C12B3C9CF400C95E8A /* DependencyInjectionTests */ = {
isa = PBXGroup;
children = (
ECEE18C22B3C9CF400C95E8A /* DependencyInjectionTests.swift */,
);
path = DependencyInjectionTests;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
ECEE18AE2B3C9CF400C95E8A /* Headers */ = {
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
ECEE18C42B3C9CF400C95E8A /* DependencyInjection.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXHeadersBuildPhase section */
/* Begin PBXNativeTarget section */
ECEE18B22B3C9CF400C95E8A /* DependencyInjection */ = {
isa = PBXNativeTarget;
buildConfigurationList = ECEE18C72B3C9CF400C95E8A /* Build configuration list for PBXNativeTarget "DependencyInjection" */;
buildPhases = (
ECEE18AE2B3C9CF400C95E8A /* Headers */,
ECEE18AF2B3C9CF400C95E8A /* Sources */,
ECEE18B02B3C9CF400C95E8A /* Frameworks */,
ECEE18B12B3C9CF400C95E8A /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = DependencyInjection;
productName = DependencyInjection;
productReference = ECEE18B32B3C9CF400C95E8A /* DependencyInjection.framework */;
productType = "com.apple.product-type.framework";
};
ECEE18BC2B3C9CF400C95E8A /* DependencyInjectionTests */ = {
isa = PBXNativeTarget;
buildConfigurationList = ECEE18CA2B3C9CF400C95E8A /* Build configuration list for PBXNativeTarget "DependencyInjectionTests" */;
buildPhases = (
ECEE18B92B3C9CF400C95E8A /* Sources */,
ECEE18BA2B3C9CF400C95E8A /* Frameworks */,
ECEE18BB2B3C9CF400C95E8A /* Resources */,
);
buildRules = (
);
dependencies = (
ECEE18C02B3C9CF400C95E8A /* PBXTargetDependency */,
);
name = DependencyInjectionTests;
productName = DependencyInjectionTests;
productReference = ECEE18BD2B3C9CF400C95E8A /* DependencyInjectionTests.xctest */;
productType = "com.apple.product-type.bundle.unit-test";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
ECEE18AA2B3C9CF400C95E8A /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1430;
LastUpgradeCheck = 1430;
TargetAttributes = {
ECEE18B22B3C9CF400C95E8A = {
CreatedOnToolsVersion = 14.3.1;
};
ECEE18BC2B3C9CF400C95E8A = {
CreatedOnToolsVersion = 14.3.1;
};
};
};
buildConfigurationList = ECEE18AD2B3C9CF400C95E8A /* Build configuration list for PBXProject "DependencyInjection" */;
compatibilityVersion = "Xcode 14.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = ECEE18A92B3C9CF400C95E8A;
productRefGroup = ECEE18B42B3C9CF400C95E8A /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
ECEE18B22B3C9CF400C95E8A /* DependencyInjection */,
ECEE18BC2B3C9CF400C95E8A /* DependencyInjectionTests */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
ECEE18B12B3C9CF400C95E8A /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
ECEE18BB2B3C9CF400C95E8A /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
ECEE18AF2B3C9CF400C95E8A /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
ECB3572C2B3CA37800045D41 /* DependencyInjection.swift in Sources */,
ECEE18B82B3C9CF400C95E8A /* DependencyInjection.docc in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
ECEE18B92B3C9CF400C95E8A /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
ECEE18C32B3C9CF400C95E8A /* DependencyInjectionTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
ECEE18C02B3C9CF400C95E8A /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = ECEE18B22B3C9CF400C95E8A /* DependencyInjection */;
targetProxy = ECEE18BF2B3C9CF400C95E8A /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin XCBuildConfiguration section */
ECEE18C52B3C9CF400C95E8A /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
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;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
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;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
name = Debug;
};
ECEE18C62B3C9CF400C95E8A /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
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;
CURRENT_PROJECT_VERSION = 1;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu11;
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;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
name = Release;
};
ECEE18C82B3C9CF400C95E8A /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_MODULE_VERIFIER = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
LD_RUNPATH_SEARCH_PATHS = (
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = (
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.3;
MARKETING_VERSION = 1.0;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20";
PRODUCT_BUNDLE_IDENTIFIER = com.alldev.DependencyInjection;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SDKROOT = auto;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
ECEE18C92B3C9CF400C95E8A /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_MODULE_VERIFIER = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_NSHumanReadableCopyright = "";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
LD_RUNPATH_SEARCH_PATHS = (
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = (
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.3;
MARKETING_VERSION = 1.0;
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu11 gnu++20";
PRODUCT_BUNDLE_IDENTIFIER = com.alldev.DependencyInjection;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SDKROOT = auto;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
ECEE18CB2B3C9CF400C95E8A /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
MACOSX_DEPLOYMENT_TARGET = 13.3;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.alldev.DependencyInjectionTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
ECEE18CC2B3C9CF400C95E8A /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
MACOSX_DEPLOYMENT_TARGET = 13.3;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.alldev.DependencyInjectionTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx";
SWIFT_EMIT_LOC_STRINGS = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
ECEE18AD2B3C9CF400C95E8A /* Build configuration list for PBXProject "DependencyInjection" */ = {
isa = XCConfigurationList;
buildConfigurations = (
ECEE18C52B3C9CF400C95E8A /* Debug */,
ECEE18C62B3C9CF400C95E8A /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
ECEE18C72B3C9CF400C95E8A /* Build configuration list for PBXNativeTarget "DependencyInjection" */ = {
isa = XCConfigurationList;
buildConfigurations = (
ECEE18C82B3C9CF400C95E8A /* Debug */,
ECEE18C92B3C9CF400C95E8A /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
ECEE18CA2B3C9CF400C95E8A /* Build configuration list for PBXNativeTarget "DependencyInjectionTests" */ = {
isa = XCConfigurationList;
buildConfigurations = (
ECEE18CB2B3C9CF400C95E8A /* Debug */,
ECEE18CC2B3C9CF400C95E8A /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = ECEE18AA2B3C9CF400C95E8A /* Project object */;
}

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

@ -0,0 +1,13 @@
# ``DependencyInjection``
<!--@START_MENU_TOKEN@-->Summary<!--@END_MENU_TOKEN@-->
## Overview
<!--@START_MENU_TOKEN@-->Text<!--@END_MENU_TOKEN@-->
## Topics
### <!--@START_MENU_TOKEN@-->Group<!--@END_MENU_TOKEN@-->
- <!--@START_MENU_TOKEN@-->``Symbol``<!--@END_MENU_TOKEN@-->

@ -0,0 +1,18 @@
//
// DependencyInjection.h
// DependencyInjection
//
// Created by Emre on 27/12/2023.
//
#import <Foundation/Foundation.h>
//! Project version number for DependencyInjection.
FOUNDATION_EXPORT double DependencyInjectionVersionNumber;
//! Project version string for DependencyInjection.
FOUNDATION_EXPORT const unsigned char DependencyInjectionVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <DependencyInjection/PublicHeader.h>

@ -1,38 +1,38 @@
//
// DependancyInjection.swift
// AllIn
// DependencyInjection.swift
// DependencyInjection
//
// Created by Emre on 20/10/2023.
// Created by Emre on 27/12/2023.
//
import Foundation
class DependencyInjection {
static var shared = DependencyInjection()
public class DependencyInjection {
public static var shared = DependencyInjection()
private var singletons = [String: Any]()
@discardableResult
func addSingleton<T>(_ type: T.Type, _ instance: T) -> DependencyInjection {
public func addSingleton<T>(_ type: T.Type, _ instance: T) -> DependencyInjection {
let key = String(describing: T.self)
singletons[key] = instance
return self
}
func resolve<T>(_ type: T.Type) -> T? {
public func resolve<T>(_ type: T.Type) -> T? {
let key = String(describing: T.self)
return singletons[key] as? T
}
}
@propertyWrapper
struct Inject<T> {
public struct Inject<T> {
private var value: T?
init() {
public init() {
self.value = DependencyInjection.shared.resolve(T.self)
}
var wrappedValue: T {
public var wrappedValue: T {
get {
if let value = value {
return value

@ -0,0 +1,76 @@
//
// DependencyInjectionTests.swift
// DependencyInjectionTests
//
// Created by Emre on 27/12/2023.
//
import XCTest
@testable import DependencyInjection
class DependencyInjectionTests: XCTestCase {
override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}
func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}
func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}
func testInstance() {
DependencyInjection.shared.addSingleton(UserTest.self, UserTest(age: 10))
let view1 = View1()
let view2 = View2()
XCTAssertEqual(view1.getAge(), view2.getAge())
view1.setAge()
XCTAssertEqual(view1.getAge(), view2.getAge())
view2.setAge()
XCTAssertEqual(view1.getAge(), view2.getAge())
}
class UserTest {
public var age:Int
init(age:Int) {
self.age = age
}
}
class View1 {
@Inject private var user:UserTest
func getAge() -> Int {
return user.age
}
func setAge() {
user.age = 20
}
}
class View2 {
@Inject private var user:UserTest
func getAge() -> Int {
return user.age
}
func setAge() {
user.age = 40
}
}
}

@ -21,8 +21,5 @@ let package = Package(
.target(
name: "Model",
dependencies: []),
.testTarget(
name: "ModelTests",
dependencies: ["Model"]),
]
)

@ -0,0 +1,22 @@
//
// Bet.swift
//
//
// Created by Emre on 28/12/2023.
//
import Foundation
public protocol Bet {
//public private(set) var id: String
var theme: String { get set }
var phrase: String { get set }
var endRegisterDate: Date { get set }
var endBetDate: Date { get set }
var totalStakes: Int { get set }
var isPublic: Bool { get set }
var invited: [User] { get set }
var author: User { get set }
var registered: [User] { get set }
}

@ -0,0 +1,13 @@
//
// BetDataManager.swift
//
//
// Created by Emre on 29/12/2023.
//
import Foundation
public protocol BetDataManager {
func getBets(withIndex index: Int, withCount count: Int) -> [Bet]
func getUsers(username: String) -> [User]
}

@ -0,0 +1,43 @@
//
// BinaryBet.swift
//
//
// Created by Emre on 28/12/2023.
//
import Foundation
public struct BinaryBet: Bet {
public var theme: String
public var phrase: String
public var endRegisterDate: Date
public var endBetDate: Date
public var totalStakes: Int
public var isPublic: Bool
public var invited: [User]
public var author: User
public var registered: [User]
public init(
theme: String,
phrase: String,
endRegisterDate: Date,
endBetDate: Date,
totalStakes: Int,
isPublic: Bool,
invited: [User],
author: User,
registered: [User]
) {
self.theme = theme
self.phrase = phrase
self.endRegisterDate = endRegisterDate
self.endBetDate = endBetDate
self.totalStakes = totalStakes
self.isPublic = isPublic
self.invited = invited
self.author = author
self.registered = registered
}
}

@ -0,0 +1,22 @@
//
// BinaryParticipation.swift
//
//
// Created by Emre on 28/12/2023.
//
import Foundation
public enum YesNo {
case yes
case no
}
public struct BinaryParticipation: Participation {
public var coinAmount: Int
public var date: Date
public var user: User
public var bet: Bet
public var answer: YesNo
}

@ -0,0 +1,22 @@
//
// CustomBet.swift
//
//
// Created by Emre on 28/12/2023.
//
import Foundation
public struct CustomBet: Bet {
public var theme: String
public var phrase: String
public var endRegisterDate: Date
public var endBetDate: Date
public var totalStakes: Int
public var isPublic: Bool
public var invited: [User]
public var author: User
public var registered: [User]
public var possibleAnswers: [CustomBetResponse]
}

@ -0,0 +1,13 @@
//
// CustomBetResponse.swift
//
//
// Created by Emre on 28/12/2023.
//
import Foundation
public struct CustomBetResponse {
public var name: String
}

@ -0,0 +1,17 @@
//
// CustomParticipation.swift
//
//
// Created by Emre on 28/12/2023.
//
import Foundation
public struct CustomParticipation: Participation {
public var coinAmount: Int
public var date: Date
public var user: User
public var bet: Bet
public var answer: CustomBetResponse
}

@ -0,0 +1,14 @@
//
// FactoryBet.swift
//
//
// Created by Emre on 09/01/2024.
//
import Foundation
public protocol FactoryBet {
func toResponse()
func toModel() -> Bet
func toModel(theme: String, description: String, endRegister: Date, endBet: Date, isPublic: Bool, creator: User, type: Int) -> Bet
}

@ -0,0 +1,23 @@
//
// Manager.swift
//
//
// Created by Emre on 29/12/2023.
//
import Foundation
public struct Manager {
let betDataManager: BetDataManager
let userDataManager: UserDataManager
public init(withBetDataManager betDataManager: BetDataManager, withUserDataManager userDataManager: UserDataManager){
self.betDataManager = betDataManager
self.userDataManager = userDataManager
}
public func addBet(bet: Bet) {
userDataManager.addBet(bet: bet)
}
}

@ -0,0 +1,23 @@
//
// MatchBet.swift
//
//
// Created by Emre on 28/12/2023.
//
import Foundation
public struct MatchBet: Bet {
public var theme: String
public var phrase: String
public var endRegisterDate: Date
public var endBetDate: Date
public var totalStakes: Int
public var isPublic: Bool
public var invited: [User]
public var author: User
public var registered: [User]
public var nameTeam1: String
public var nameTeam2: String
}

@ -0,0 +1,18 @@
//
// MatchParticipation.swift
//
//
// Created by Emre on 28/12/2023.
//
import Foundation
public struct MatchParticipation: Participation {
public var coinAmount: Int
public var date: Date
public var user: User
public var bet: Bet
public var PointsTeam1: Int
public var PointsTeam2: Int
}

@ -1,6 +0,0 @@
public struct Model {
public private(set) var text = "Hello, World!"
public init() {
}
}

@ -0,0 +1,16 @@
//
// Participation.swift
//
//
// Created by Emre on 28/12/2023.
//
import Foundation
public protocol Participation {
var coinAmount: Int { get set }
var date: Date { get set }
var user: User { get set }
var bet: Bet { get set }
}

@ -0,0 +1,36 @@
//
// User.swift
//
//
// Created by Emre on 11/10/2023.
//
import Foundation
public struct User {
public var username: String
public var email: String
public var nbCoins: Int
public var friends: [User]
public init(username: String, email: String, nbCoins: Int, friends: [User]) {
self.username = username
self.email = email
self.nbCoins = nbCoins
self.friends = friends
}
public mutating func addFriend(user: User) {
self.friends.append(user)
}
public static func mapUser(from json: [String: Any]) -> User? {
guard let username = json["username"] as? String,
let email = json["email"] as? String,
let nbCoins = json["nbCoins"] as? Int else {
return nil
}
return User(username: username, email: email, nbCoins: nbCoins, friends: [])
}
}

@ -0,0 +1,14 @@
//
// UserDataManager.swift
//
//
// Created by Emre on 29/12/2023.
//
import Foundation
public protocol UserDataManager {
func getBets(withIndex index: Int, withCount count: Int) -> [Bet]
func addBet(bet: Bet)
func getFriends() -> [User]
}

@ -1,11 +0,0 @@
import XCTest
@testable import Model
final class ModelTests: XCTestCase {
func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.
XCTAssertEqual(Model().text, "Hello, World!")
}
}

@ -0,0 +1,26 @@
// swift-tools-version: 5.8
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "StubLib",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "StubLib",
targets: ["StubLib"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(name: "Model", path: "../Model")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "StubLib",
dependencies: ["Model"]),
]
)

@ -0,0 +1,3 @@
# StubLib
A description of this package.

@ -0,0 +1,26 @@
//
// BetStubManager.swift
//
//
// Created by Emre on 31/12/2023.
//
import Foundation
import Model
public struct BetStubManager: BetDataManager {
public init() {}
public func getBets(withIndex index: Int, withCount count: Int) -> [Bet] {
return Stub.shared.bets
}
public func getUsers(username: String) -> [User] {
return Stub.shared.users
.filter { user in
user.username.contains(username)
}
}
}

@ -0,0 +1,91 @@
//
// Stub.swift
//
//
// Created by Emre on 01/01/2024.
//
import Foundation
import Model
struct Stub {
static var shared = Stub()
public var bets: [Bet] = []
public var users: [User] = []
public init() {
loadBets()
}
public mutating func loadBets() {
var user1 = User(username: "Lucas", email: "lucas.delanier@etu.uca.fr", nbCoins: 100, friends: [])
users.append(user1)
var user2 = User(username: "Imri", email: "emre.kartal@etu.uca.fr", nbCoins: 75, friends: [user1])
users.append(user2)
user1.addFriend(user: user2)
let user3 = User(username: "Arthur", email: "arthur.valin@etu.uca.fr", nbCoins: 30, friends: [user2])
users.append(user3)
user2.addFriend(user: user3)
let bet1 = BinaryBet(
theme: "Football - Finale de la Ligue des Champions",
phrase: "Le gagnant de la finale sera l'équipe avec le plus de tirs au but.",
endRegisterDate: Date().addingTimeInterval(86400),
endBetDate: Date().addingTimeInterval(172800),
totalStakes: 100,
isPublic: true,
invited: [],
author: user1,
registered: [user2]
)
self.bets.append(bet1)
let bet2 = BinaryBet(
theme: "Cuisine - Concours de cuisine en direct",
phrase: "Le plat préféré du jury sera une recette végétarienne.",
endRegisterDate: Date().addingTimeInterval(172800),
endBetDate: Date().addingTimeInterval(259200),
totalStakes: 150,
isPublic: false,
invited: [user3],
author: user1,
registered: [user2]
)
self.bets.append(bet2)
let bet3 = BinaryBet(
theme: "Technologie - Lancement d'un nouveau smartphone",
phrase: "Le nombre total de précommandes dépassera-t-il 1 million dans la première semaine ?",
endRegisterDate: Date().addingTimeInterval(259200),
endBetDate: Date().addingTimeInterval(345600),
totalStakes: 75,
isPublic: true,
invited: [],
author: user1,
registered: [user2, user1, user3]
)
self.bets.append(bet3)
let bet4 = BinaryBet(
theme: "Cinéma - Oscars 2024",
phrase: "Le film favori des critiques remportera-t-il le prix du meilleur film ?",
endRegisterDate: Date().addingTimeInterval(345600),
endBetDate: Date().addingTimeInterval(432000),
totalStakes: 120,
isPublic: false,
invited: [user1],
author: user2,
registered: [user3]
)
self.bets.append(bet4)
}
public mutating func add(bet: Bet) {
self.bets.append(bet)
}
}

@ -0,0 +1,38 @@
//
// UserStubManager.swift
//
//
// Created by Emre on 31/12/2023.
//
import Foundation
import Model
public struct UserStubManager: UserDataManager {
private var username: String
public init(username: String) {
self.username = username
}
public func getBets(withIndex index: Int, withCount count: Int) -> [Bet] {
return Stub.shared.bets.filter { bet in
bet.registered.contains { user in
user.username == self.username
}
}
}
public func addBet(bet: Bet) {
Stub.shared.add(bet: bet)
}
public func getFriends() -> [User] {
return Stub.shared.users.filter { user in
user.friends.contains { friend in
friend.username == self.username
}
}
}
}

@ -0,0 +1,9 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/config/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc

@ -0,0 +1,29 @@
// swift-tools-version: 5.8
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "ViewModel",
platforms: [
.iOS(.v13)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "ViewModel",
targets: ["ViewModel"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(name: "Model", path: "../Model")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "ViewModel",
dependencies: ["Model"]),
]
)

@ -0,0 +1,3 @@
# ViewModel
A description of this package.

@ -0,0 +1,25 @@
//
// ManagerVM.swift
//
//
// Created by Emre on 30/12/2023.
//
import Foundation
import Model
public class ManagerVM: ObservableObject {
@Published var model: Manager
public init(withModel model: Manager) {
self.model = model
}
public func getPublicBets() {
}
public func addBet(theme: String, description: String, endRegister: Date, endBet: Date, isPublic: Bool, creator: User) {
model.addBet(bet: BinaryBet(theme: theme, phrase: description, endRegisterDate: endRegister, endBetDate: endBet, totalStakes: 0, isPublic: isPublic, invited: [], author: creator, registered: []))
}
}
Loading…
Cancel
Save