add nounours project (almost working)

master
etudiant 1 year ago
parent 0464fa0d66
commit cbcba07083

@ -0,0 +1,398 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 56;
objects = {
/* Begin PBXBuildFile section */
ECC5577E2A1CFDE000367962 /* NounoursAppApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECC5577D2A1CFDE000367962 /* NounoursAppApp.swift */; };
ECC557822A1CFDE100367962 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = ECC557812A1CFDE100367962 /* Assets.xcassets */; };
ECC557852A1CFDE100367962 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = ECC557842A1CFDE100367962 /* Preview Assets.xcassets */; };
ECC5578D2A1CFE4C00367962 /* Nounours.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECC5578C2A1CFE4C00367962 /* Nounours.swift */; };
ECC5578F2A1CFEB200367962 /* Bed.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECC5578E2A1CFEB200367962 /* Bed.swift */; };
ECC557922A1D01A000367962 /* BedsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECC557912A1D01A000367962 /* BedsView.swift */; };
ECC557942A1D023700367962 /* BedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECC557932A1D023700367962 /* BedView.swift */; };
ECC557962A1D02E600367962 /* NounoursView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECC557952A1D02E600367962 /* NounoursView.swift */; };
ECC557992A1D079400367962 /* NounoursVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECC557982A1D079400367962 /* NounoursVM.swift */; };
ECC5579B2A1D0BF900367962 /* BedVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECC5579A2A1D0BF900367962 /* BedVM.swift */; };
ECC5579D2A1D0E0100367962 /* BedsVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECC5579C2A1D0E0100367962 /* BedsVM.swift */; };
ECC5579F2A1D131500367962 /* EditableBedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = ECC5579E2A1D131500367962 /* EditableBedView.swift */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
ECC5577A2A1CFDE000367962 /* NounoursApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NounoursApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
ECC5577D2A1CFDE000367962 /* NounoursAppApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NounoursAppApp.swift; sourceTree = "<group>"; };
ECC557812A1CFDE100367962 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
ECC557842A1CFDE100367962 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
ECC5578C2A1CFE4C00367962 /* Nounours.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Nounours.swift; sourceTree = "<group>"; };
ECC5578E2A1CFEB200367962 /* Bed.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bed.swift; sourceTree = "<group>"; };
ECC557912A1D01A000367962 /* BedsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BedsView.swift; sourceTree = "<group>"; };
ECC557932A1D023700367962 /* BedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BedView.swift; sourceTree = "<group>"; };
ECC557952A1D02E600367962 /* NounoursView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NounoursView.swift; sourceTree = "<group>"; };
ECC557982A1D079400367962 /* NounoursVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NounoursVM.swift; sourceTree = "<group>"; };
ECC5579A2A1D0BF900367962 /* BedVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BedVM.swift; sourceTree = "<group>"; };
ECC5579C2A1D0E0100367962 /* BedsVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BedsVM.swift; sourceTree = "<group>"; };
ECC5579E2A1D131500367962 /* EditableBedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditableBedView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
ECC557772A1CFDE000367962 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
ECC557712A1CFDE000367962 = {
isa = PBXGroup;
children = (
ECC5577C2A1CFDE000367962 /* NounoursApp */,
ECC5577B2A1CFDE000367962 /* Products */,
);
sourceTree = "<group>";
};
ECC5577B2A1CFDE000367962 /* Products */ = {
isa = PBXGroup;
children = (
ECC5577A2A1CFDE000367962 /* NounoursApp.app */,
);
name = Products;
sourceTree = "<group>";
};
ECC5577C2A1CFDE000367962 /* NounoursApp */ = {
isa = PBXGroup;
children = (
ECC557972A1D077300367962 /* ViewModel */,
ECC557902A1D018F00367962 /* Views */,
ECC5578B2A1CFE3000367962 /* Model */,
ECC5577D2A1CFDE000367962 /* NounoursAppApp.swift */,
ECC557812A1CFDE100367962 /* Assets.xcassets */,
ECC557832A1CFDE100367962 /* Preview Content */,
);
path = NounoursApp;
sourceTree = "<group>";
};
ECC557832A1CFDE100367962 /* Preview Content */ = {
isa = PBXGroup;
children = (
ECC557842A1CFDE100367962 /* Preview Assets.xcassets */,
);
path = "Preview Content";
sourceTree = "<group>";
};
ECC5578B2A1CFE3000367962 /* Model */ = {
isa = PBXGroup;
children = (
ECC5578C2A1CFE4C00367962 /* Nounours.swift */,
ECC5578E2A1CFEB200367962 /* Bed.swift */,
);
path = Model;
sourceTree = "<group>";
};
ECC557902A1D018F00367962 /* Views */ = {
isa = PBXGroup;
children = (
ECC557912A1D01A000367962 /* BedsView.swift */,
ECC557932A1D023700367962 /* BedView.swift */,
ECC557952A1D02E600367962 /* NounoursView.swift */,
ECC5579E2A1D131500367962 /* EditableBedView.swift */,
);
path = Views;
sourceTree = "<group>";
};
ECC557972A1D077300367962 /* ViewModel */ = {
isa = PBXGroup;
children = (
ECC557982A1D079400367962 /* NounoursVM.swift */,
ECC5579A2A1D0BF900367962 /* BedVM.swift */,
ECC5579C2A1D0E0100367962 /* BedsVM.swift */,
);
path = ViewModel;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
ECC557792A1CFDE000367962 /* NounoursApp */ = {
isa = PBXNativeTarget;
buildConfigurationList = ECC557882A1CFDE100367962 /* Build configuration list for PBXNativeTarget "NounoursApp" */;
buildPhases = (
ECC557762A1CFDE000367962 /* Sources */,
ECC557772A1CFDE000367962 /* Frameworks */,
ECC557782A1CFDE000367962 /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = NounoursApp;
productName = NounoursApp;
productReference = ECC5577A2A1CFDE000367962 /* NounoursApp.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
ECC557722A1CFDE000367962 /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1430;
LastUpgradeCheck = 1430;
TargetAttributes = {
ECC557792A1CFDE000367962 = {
CreatedOnToolsVersion = 14.3;
};
};
};
buildConfigurationList = ECC557752A1CFDE000367962 /* Build configuration list for PBXProject "NounoursApp" */;
compatibilityVersion = "Xcode 14.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = ECC557712A1CFDE000367962;
productRefGroup = ECC5577B2A1CFDE000367962 /* Products */;
projectDirPath = "";
projectRoot = "";
targets = (
ECC557792A1CFDE000367962 /* NounoursApp */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
ECC557782A1CFDE000367962 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
ECC557852A1CFDE100367962 /* Preview Assets.xcassets in Resources */,
ECC557822A1CFDE100367962 /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
ECC557762A1CFDE000367962 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
ECC5579F2A1D131500367962 /* EditableBedView.swift in Sources */,
ECC557922A1D01A000367962 /* BedsView.swift in Sources */,
ECC557962A1D02E600367962 /* NounoursView.swift in Sources */,
ECC5579D2A1D0E0100367962 /* BedsVM.swift in Sources */,
ECC5578D2A1CFE4C00367962 /* Nounours.swift in Sources */,
ECC557942A1D023700367962 /* BedView.swift in Sources */,
ECC5579B2A1D0BF900367962 /* BedVM.swift in Sources */,
ECC5577E2A1CFDE000367962 /* NounoursAppApp.swift in Sources */,
ECC5578F2A1CFEB200367962 /* Bed.swift in Sources */,
ECC557992A1D079400367962 /* NounoursVM.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
ECC557862A1CFDE100367962 /* 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;
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;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
};
ECC557872A1CFDE100367962 /* 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;
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;
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
VALIDATE_PRODUCT = YES;
};
name = Release;
};
ECC557892A1CFDE100367962 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"NounoursApp/Preview Content\"";
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
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";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = fr.uca.iut.NounoursApp;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
ECC5578A2A1CFDE100367962 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"NounoursApp/Preview Content\"";
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
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";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = fr.uca.iut.NounoursApp;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
ECC557752A1CFDE000367962 /* Build configuration list for PBXProject "NounoursApp" */ = {
isa = XCConfigurationList;
buildConfigurations = (
ECC557862A1CFDE100367962 /* Debug */,
ECC557872A1CFDE100367962 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
ECC557882A1CFDE100367962 /* Build configuration list for PBXNativeTarget "NounoursApp" */ = {
isa = XCConfigurationList;
buildConfigurations = (
ECC557892A1CFDE100367962 /* Debug */,
ECC5578A2A1CFDE100367962 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = ECC557722A1CFDE000367962 /* 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,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,13 @@
{
"images" : [
{
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,38 @@
import Foundation
public struct Bed: Identifiable {
public let id: UUID
public var name: String
public var nounours: [Nounours]
init(id: UUID, name: String) {
self.id = id
self.name = name
self.nounours = []
}
init(name: String) {
self.init(id: UUID(), name: name)
}
}
public func loadBeds() -> [Bed] {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy MM dd"
var beds: [Bed] = []
var bed1 = Bed(name: "Star Wars")
bed1.nounours.append(Nounours(name: "Nounours1", hairCount: 27732, date: formatter.date(from: "2002 01 23")!))
bed1.nounours.append(Nounours(name: "Nounours2", hairCount: 262, date: formatter.date(from: "2003 04 16")!))
var bed2 = Bed(name: "Indiana Jones")
bed2.nounours.append(Nounours(name: "Nounours3", hairCount: 232, date: formatter.date(from: "2006 09 02")!))
bed2.nounours.append(Nounours(name: "Nounours4", hairCount: 24262, date: formatter.date(from: "2007 08 30")!))
bed2.nounours.append(Nounours(name: "Nounours5", hairCount: 2232362, date: formatter.date(from: "2009 11 13")!))
beds.append(bed1)
beds.append(bed2)
return beds
}

@ -0,0 +1,19 @@
import Foundation
public struct Nounours: Identifiable {
public let id: UUID
public var name: String
public var hairCount: Int32
public var date: Date
init(id: UUID, name: String, hairCount: Int32, date: Date) {
self.id = id
self.name = name
self.hairCount = hairCount
self.date = date
}
init(name: String, hairCount: Int32, date: Date) {
self.init(id: UUID(), name: name, hairCount: hairCount, date: date)
}
}

@ -0,0 +1,13 @@
import SwiftUI
@main
struct NounoursAppApp: App {
@StateObject
var beds: BedsVM = BedsVM(beds: loadBeds())
var body: some Scene {
WindowGroup {
BedsView(bedsVM: beds)
}
}
}

@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

@ -0,0 +1,41 @@
import Foundation
extension Bed {
struct Data: Identifiable {
public let id: UUID
public var name: String
public var nounours: [Nounours.Data] = []
}
var data : Data { Data(id: self.id, name: self.name, nounours: self.nounours.map{ $0.data }) }
mutating func update(from: Data) {
guard self.id == data.id else { return }
self.name = data.name
self.nounours = data.nounours.map{ Nounours(id: $0.id, name: $0.name, hairCount: $0.hairCount, date: $0.date)}
}
}
public class BedVM : ObservableObject {
var original: Bed = Bed(name: "")
@Published var model: Bed.Data
@Published var isEdited = false
init(original: Bed) {
self.original = original
model = original.data
}
func onEditing() {
model = original.data
isEdited = true
}
func onEdited(isCancel: Bool = false) {
if (!isCancel) {
original.update(from: model)
}
isEdited = false
model = original.data
}
}

@ -0,0 +1,15 @@
import Foundation
public class BedsVM : ObservableObject {
@Published var beds: [Bed]
init(beds: [Bed]) {
self.beds = beds
}
func update(vm: BedVM) {
if let i = beds.firstIndex(where: { $0.id == vm.original.id }) {
beds[i] = vm.original
}
}
}

@ -0,0 +1,44 @@
import Foundation
extension Nounours {
struct Data: Identifiable {
public let id: UUID
public var name: String
public var hairCount: Int32
public var date: Date
}
var data: Data {
Data(id: self.id, name: self.name, hairCount: self.hairCount, date: self.date)
}
mutating func update(from data: Data) {
guard data.id == self.id else { return }
self.name = data.name
self.hairCount = data.hairCount
self.date = data.date
}
}
public class NounoursVM : ObservableObject {
var original: Nounours = Nounours(id: UUID(), name: "", hairCount: 0, date: Date())
@Published var model: Nounours.Data
@Published var isEdited = false
init(original: Nounours) {
self.original = original
model = original.data
}
func onEditing() {
model = original.data
isEdited = true
}
func onEdited(isCancel: Bool = false) {
if (!isCancel) {
original.update(from: model)
}
isEdited = false
}
}

@ -0,0 +1,50 @@
import SwiftUI
struct BedView: View {
//@Binding public var bed: Bed
//@State public var isEdited = false
@ObservedObject var bedVM: BedVM
@ObservedObject var bedsVM : BedsVM
var body: some View {
VStack {
Text(bedVM.model.name)
List(bedVM.original.nounours) { n in
NounoursView(nounoursVM: NounoursVM(original: n))
}
}
.navigationBarTitle(bedVM.model.name)
.toolbar {
Button(action: {
bedVM.isEdited.toggle()
}) {
Text("Edit")
}
}
.sheet(isPresented: $bedVM.isEdited) {
NavigationStack {
EditableBedView(bedData: $bedVM.model)
.toolbar {
ToolbarItem(placement: .confirmationAction) {
Button("Done") {
bedVM.onEdited()
bedsVM.update(vm: bedVM)
}
}
ToolbarItem(placement: .cancellationAction) {
Button("Cancel") {
bedVM.onEdited(isCancel: true)
}
}
}
}
}
}
}
struct BedView_Previews: PreviewProvider {
static var previews: some View {
BedView(bedVM: BedVM(original: loadBeds()[0]), bedsVM: BedsVM(beds: loadBeds()))
}
}

@ -0,0 +1,27 @@
import SwiftUI
struct BedsView: View {
//@State public var beds: [Bed]
@ObservedObject var bedsVM: BedsVM
var body: some View {
NavigationStack {
List(bedsVM.beds) { b in
NavigationLink(destination: BedView(bedVM: BedVM(original: b), bedsVM: bedsVM)) {
HStack {
Text(b.name)
Spacer()
Text(String(b.nounours.count))
}
}
}
}
}
}
struct BedsView_Previews: PreviewProvider {
static var previews: some View {
BedsView(bedsVM: BedsVM(beds: loadBeds()))
}
}

@ -0,0 +1,16 @@
import SwiftUI
struct EditableBedView: View {
@Binding var bedData: Bed.Data
var body: some View {
TextField("Enter the name here", text: $bedData.name)
}
}
struct EditableBedView_Previews: PreviewProvider {
static var previews: some View {
EditableBedView(bedData: .constant(loadBeds()[0].data))
}
}

@ -0,0 +1,20 @@
import SwiftUI
struct NounoursView: View {
//@Binding public var nounours: Nounours
@ObservedObject var nounoursVM: NounoursVM
var body: some View {
VStack(alignment: .leading) {
Label(nounoursVM.model.name, systemImage: "person")
TextField("name: ", text: $nounoursVM.model.name)
}
}
}
struct NounoursView_Previews: PreviewProvider {
static var previews: some View {
NounoursView(nounoursVM: NounoursVM(original: loadBeds()[0].nounours[0]))
}
}
Loading…
Cancel
Save