diff --git a/0307-sharing-pt3/README.md b/0307-sharing-pt3/README.md new file mode 100644 index 00000000..023841b6 --- /dev/null +++ b/0307-sharing-pt3/README.md @@ -0,0 +1,5 @@ +## [Point-Free](https://www.pointfree.co) + +> #### This directory contains code from Point-Free Episode: [Tour of Sharing: File Storage, Part 1](https://www.pointfree.co/episodes/ep306-tour-of-sharing-file-storage-part-1) +> +> `@Shared` is far more than a glorified version of `@AppStorage`: it can be customized with additional persistence strategies, including the file storage strategy that comes with the library, which persists far more complex data than user defaults. We will create a complex, new feature that is powered by the file system. diff --git a/0307-sharing-pt3/TourOfSharing/TourOfSharing.xcodeproj/project.pbxproj b/0307-sharing-pt3/TourOfSharing/TourOfSharing.xcodeproj/project.pbxproj new file mode 100644 index 00000000..d24976e6 --- /dev/null +++ b/0307-sharing-pt3/TourOfSharing/TourOfSharing.xcodeproj/project.pbxproj @@ -0,0 +1,594 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 77; + objects = { + +/* Begin PBXBuildFile section */ + 2A6E8B342CE7E25E00319151 /* Sharing in Frameworks */ = {isa = PBXBuildFile; productRef = 2A6E8B332CE7E25E00319151 /* Sharing */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 2A5622DB2CE7D2E600FC29DB /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 2A5622C22CE7D2E400FC29DB /* Project object */; + proxyType = 1; + remoteGlobalIDString = 2A5622C92CE7D2E500FC29DB; + remoteInfo = TourOfSharing; + }; + 2A5622E52CE7D2E600FC29DB /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 2A5622C22CE7D2E400FC29DB /* Project object */; + proxyType = 1; + remoteGlobalIDString = 2A5622C92CE7D2E500FC29DB; + remoteInfo = TourOfSharing; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 2A5622CA2CE7D2E500FC29DB /* TourOfSharing.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TourOfSharing.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 2A5622DA2CE7D2E600FC29DB /* TourOfSharingTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TourOfSharingTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 2A5622E42CE7D2E600FC29DB /* TourOfSharingUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TourOfSharingUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */ + 2AC40EFC2CEBECBD001DE136 /* Exceptions for "TourOfSharing" folder in "TourOfSharing" target */ = { + isa = PBXFileSystemSynchronizedBuildFileExceptionSet; + membershipExceptions = ( + Info.plist, + ); + target = 2A5622C92CE7D2E500FC29DB /* TourOfSharing */; + }; +/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */ + +/* Begin PBXFileSystemSynchronizedRootGroup section */ + 2A5622CC2CE7D2E500FC29DB /* TourOfSharing */ = { + isa = PBXFileSystemSynchronizedRootGroup; + exceptions = ( + 2AC40EFC2CEBECBD001DE136 /* Exceptions for "TourOfSharing" folder in "TourOfSharing" target */, + ); + path = TourOfSharing; + sourceTree = ""; + }; + 2A5622DD2CE7D2E600FC29DB /* TourOfSharingTests */ = { + isa = PBXFileSystemSynchronizedRootGroup; + path = TourOfSharingTests; + sourceTree = ""; + }; + 2A5622E72CE7D2E600FC29DB /* TourOfSharingUITests */ = { + isa = PBXFileSystemSynchronizedRootGroup; + path = TourOfSharingUITests; + sourceTree = ""; + }; +/* End PBXFileSystemSynchronizedRootGroup section */ + +/* Begin PBXFrameworksBuildPhase section */ + 2A5622C72CE7D2E500FC29DB /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 2A6E8B342CE7E25E00319151 /* Sharing in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 2A5622D72CE7D2E600FC29DB /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 2A5622E12CE7D2E600FC29DB /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 2A5622C12CE7D2E400FC29DB = { + isa = PBXGroup; + children = ( + 2A5622CC2CE7D2E500FC29DB /* TourOfSharing */, + 2A5622DD2CE7D2E600FC29DB /* TourOfSharingTests */, + 2A5622E72CE7D2E600FC29DB /* TourOfSharingUITests */, + 2A5622CB2CE7D2E500FC29DB /* Products */, + ); + sourceTree = ""; + }; + 2A5622CB2CE7D2E500FC29DB /* Products */ = { + isa = PBXGroup; + children = ( + 2A5622CA2CE7D2E500FC29DB /* TourOfSharing.app */, + 2A5622DA2CE7D2E600FC29DB /* TourOfSharingTests.xctest */, + 2A5622E42CE7D2E600FC29DB /* TourOfSharingUITests.xctest */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 2A5622C92CE7D2E500FC29DB /* TourOfSharing */ = { + isa = PBXNativeTarget; + buildConfigurationList = 2A5622EE2CE7D2E600FC29DB /* Build configuration list for PBXNativeTarget "TourOfSharing" */; + buildPhases = ( + 2A5622C62CE7D2E500FC29DB /* Sources */, + 2A5622C72CE7D2E500FC29DB /* Frameworks */, + 2A5622C82CE7D2E500FC29DB /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + fileSystemSynchronizedGroups = ( + 2A5622CC2CE7D2E500FC29DB /* TourOfSharing */, + ); + name = TourOfSharing; + packageProductDependencies = ( + 2A6E8B332CE7E25E00319151 /* Sharing */, + ); + productName = TourOfSharing; + productReference = 2A5622CA2CE7D2E500FC29DB /* TourOfSharing.app */; + productType = "com.apple.product-type.application"; + }; + 2A5622D92CE7D2E600FC29DB /* TourOfSharingTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 2A5622F12CE7D2E600FC29DB /* Build configuration list for PBXNativeTarget "TourOfSharingTests" */; + buildPhases = ( + 2A5622D62CE7D2E600FC29DB /* Sources */, + 2A5622D72CE7D2E600FC29DB /* Frameworks */, + 2A5622D82CE7D2E600FC29DB /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 2A5622DC2CE7D2E600FC29DB /* PBXTargetDependency */, + ); + fileSystemSynchronizedGroups = ( + 2A5622DD2CE7D2E600FC29DB /* TourOfSharingTests */, + ); + name = TourOfSharingTests; + packageProductDependencies = ( + ); + productName = TourOfSharingTests; + productReference = 2A5622DA2CE7D2E600FC29DB /* TourOfSharingTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; + 2A5622E32CE7D2E600FC29DB /* TourOfSharingUITests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 2A5622F42CE7D2E600FC29DB /* Build configuration list for PBXNativeTarget "TourOfSharingUITests" */; + buildPhases = ( + 2A5622E02CE7D2E600FC29DB /* Sources */, + 2A5622E12CE7D2E600FC29DB /* Frameworks */, + 2A5622E22CE7D2E600FC29DB /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 2A5622E62CE7D2E600FC29DB /* PBXTargetDependency */, + ); + fileSystemSynchronizedGroups = ( + 2A5622E72CE7D2E600FC29DB /* TourOfSharingUITests */, + ); + name = TourOfSharingUITests; + packageProductDependencies = ( + ); + productName = TourOfSharingUITests; + productReference = 2A5622E42CE7D2E600FC29DB /* TourOfSharingUITests.xctest */; + productType = "com.apple.product-type.bundle.ui-testing"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 2A5622C22CE7D2E400FC29DB /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1610; + LastUpgradeCheck = 1610; + TargetAttributes = { + 2A5622C92CE7D2E500FC29DB = { + CreatedOnToolsVersion = 16.1; + }; + 2A5622D92CE7D2E600FC29DB = { + CreatedOnToolsVersion = 16.1; + TestTargetID = 2A5622C92CE7D2E500FC29DB; + }; + 2A5622E32CE7D2E600FC29DB = { + CreatedOnToolsVersion = 16.1; + TestTargetID = 2A5622C92CE7D2E500FC29DB; + }; + }; + }; + buildConfigurationList = 2A5622C52CE7D2E400FC29DB /* Build configuration list for PBXProject "TourOfSharing" */; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 2A5622C12CE7D2E400FC29DB; + minimizedProjectReferenceProxies = 1; + packageReferences = ( + 2A6E8B322CE7E25E00319151 /* XCRemoteSwiftPackageReference "swift-sharing" */, + ); + preferredProjectObjectVersion = 77; + productRefGroup = 2A5622CB2CE7D2E500FC29DB /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 2A5622C92CE7D2E500FC29DB /* TourOfSharing */, + 2A5622D92CE7D2E600FC29DB /* TourOfSharingTests */, + 2A5622E32CE7D2E600FC29DB /* TourOfSharingUITests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 2A5622C82CE7D2E500FC29DB /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 2A5622D82CE7D2E600FC29DB /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 2A5622E22CE7D2E600FC29DB /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 2A5622C62CE7D2E500FC29DB /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 2A5622D62CE7D2E600FC29DB /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 2A5622E02CE7D2E600FC29DB /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 2A5622DC2CE7D2E600FC29DB /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 2A5622C92CE7D2E500FC29DB /* TourOfSharing */; + targetProxy = 2A5622DB2CE7D2E600FC29DB /* PBXContainerItemProxy */; + }; + 2A5622E62CE7D2E600FC29DB /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 2A5622C92CE7D2E500FC29DB /* TourOfSharing */; + targetProxy = 2A5622E52CE7D2E600FC29DB /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + 2A5622EC2CE7D2E600FC29DB /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + 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; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + 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 = 18.1; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 6.0; + }; + name = Debug; + }; + 2A5622ED2CE7D2E600FC29DB /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + 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; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + 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 = 18.1; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_VERSION = 6.0; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 2A5622EF2CE7D2E600FC29DB /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = TourOfSharing/Info.plist; + 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 = co.pointfree.TourOfSharing; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 2A5622F02CE7D2E600FC29DB /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = TourOfSharing/Info.plist; + 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 = co.pointfree.TourOfSharing; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + 2A5622F22CE7D2E600FC29DB /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 18.1; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = co.pointfree.TourOfSharingTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TourOfSharing.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/TourOfSharing"; + }; + name = Debug; + }; + 2A5622F32CE7D2E600FC29DB /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 18.1; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = co.pointfree.TourOfSharingTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TourOfSharing.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/TourOfSharing"; + }; + name = Release; + }; + 2A5622F52CE7D2E600FC29DB /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = co.pointfree.TourOfSharingUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = TourOfSharing; + }; + name = Debug; + }; + 2A5622F62CE7D2E600FC29DB /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + GENERATE_INFOPLIST_FILE = YES; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = co.pointfree.TourOfSharingUITests; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_TARGET_NAME = TourOfSharing; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 2A5622C52CE7D2E400FC29DB /* Build configuration list for PBXProject "TourOfSharing" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 2A5622EC2CE7D2E600FC29DB /* Debug */, + 2A5622ED2CE7D2E600FC29DB /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 2A5622EE2CE7D2E600FC29DB /* Build configuration list for PBXNativeTarget "TourOfSharing" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 2A5622EF2CE7D2E600FC29DB /* Debug */, + 2A5622F02CE7D2E600FC29DB /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 2A5622F12CE7D2E600FC29DB /* Build configuration list for PBXNativeTarget "TourOfSharingTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 2A5622F22CE7D2E600FC29DB /* Debug */, + 2A5622F32CE7D2E600FC29DB /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 2A5622F42CE7D2E600FC29DB /* Build configuration list for PBXNativeTarget "TourOfSharingUITests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 2A5622F52CE7D2E600FC29DB /* Debug */, + 2A5622F62CE7D2E600FC29DB /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + 2A6E8B322CE7E25E00319151 /* XCRemoteSwiftPackageReference "swift-sharing" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/pointfreeco/swift-sharing"; + requirement = { + branch = 1.0.0; + kind = branch; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 2A6E8B332CE7E25E00319151 /* Sharing */ = { + isa = XCSwiftPackageProductDependency; + package = 2A6E8B322CE7E25E00319151 /* XCRemoteSwiftPackageReference "swift-sharing" */; + productName = Sharing; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = 2A5622C22CE7D2E400FC29DB /* Project object */; +} diff --git a/0307-sharing-pt3/TourOfSharing/TourOfSharing.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/0307-sharing-pt3/TourOfSharing/TourOfSharing.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/0307-sharing-pt3/TourOfSharing/TourOfSharing.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/0307-sharing-pt3/TourOfSharing/TourOfSharing/Assets.xcassets/AccentColor.colorset/Contents.json b/0307-sharing-pt3/TourOfSharing/TourOfSharing/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 00000000..eb878970 --- /dev/null +++ b/0307-sharing-pt3/TourOfSharing/TourOfSharing/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/0307-sharing-pt3/TourOfSharing/TourOfSharing/Assets.xcassets/AppIcon.appiconset/Contents.json b/0307-sharing-pt3/TourOfSharing/TourOfSharing/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..23058801 --- /dev/null +++ b/0307-sharing-pt3/TourOfSharing/TourOfSharing/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,35 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "tinted" + } + ], + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/0307-sharing-pt3/TourOfSharing/TourOfSharing/Assets.xcassets/Contents.json b/0307-sharing-pt3/TourOfSharing/TourOfSharing/Assets.xcassets/Contents.json new file mode 100644 index 00000000..73c00596 --- /dev/null +++ b/0307-sharing-pt3/TourOfSharing/TourOfSharing/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/0307-sharing-pt3/TourOfSharing/TourOfSharing/ContentView.swift b/0307-sharing-pt3/TourOfSharing/TourOfSharing/ContentView.swift new file mode 100644 index 00000000..bd55734e --- /dev/null +++ b/0307-sharing-pt3/TourOfSharing/TourOfSharing/ContentView.swift @@ -0,0 +1,253 @@ +import Sharing +import SwiftUI + +struct ManyCountersView: View { + @Dependency(\.defaultAppStorage) var store + + var body: some View { + Form { + Section { + CounterView() + } header: { + Text("@Shared in an observable model") + } + + Section { + AnotherCounterView() + } header: { + Text("@Shared in a view") + } + + Section { + AppStorageCounterView() + } header: { + Text("@AppStorage") + } + + Section { + CounterViewController.Representable() + } header: { + Text("@Shared in a view controller") + } + + Button(#"UserDefaults.set(0, "count")"#) { + UIView.animate(withDuration: 0.35) { + withAnimation { + store.set(0, forKey: "count") + } + } + } + } + } +} + +@Observable +class CounterModel { + @ObservationIgnored + @Shared(.count) var count + //@AppStorage("co.pointfree.countermodel.count") var count = 0 +} + +struct CounterView: View { + @State var model = CounterModel() + + var body: some View { + HStack { + Text("\(model.count)") + .font(.largeTitle) + Button("Decrement") { + model.$count.withLock { $0 -= 1 } + } + Button("Increment") { + model.$count.withLock { $0 += 1 } + } + } + .buttonStyle(.borderless) + } +} + +struct AnotherCounterView: View { + @Shared(.count) var count + + var body: some View { + HStack { + Text("\(count)") + .font(.largeTitle) + Button("Decrement") { + $count.withLock { $0 -= 1 } + } + Button("Increment") { + $count.withLock { $0 += 1 } + } + } + .buttonStyle(.borderless) + } +} + +struct ToggleView: View { + @AppStorage(.count) var count = false + var body: some View { + HStack { + Text("\(count)") + Button("Toggle") { count.toggle() } + } + } +} +struct OtherView: View { + @AppStorage(.count) var count = 100 + var body: some View { EmptyView() } +} +extension String { static var count: String { "count" } } + +struct AppStorageCounterView: View { + @AppStorage(.count) var count = 0 + + var body: some View { + HStack { + Text("\(count)") + .font(.largeTitle) + Button("Decrement") { + count -= 1 + } + Button("Increment") { + count += 1 + } + } + .buttonStyle(.borderless) + + ToggleView() + } +} + +extension SharedKey where Self == AppStorageKey.Default { + static var count: Self { + Self[.appStorage("count"), default: 0] + } +} + +#Preview("CounterView") { + CounterView() +} + +import Dependencies +#Preview( + "ManyCountersView" +) { + @Dependency(\.defaultAppStorage) var store + ManyCountersView() + .defaultAppStorage(store) +} + +import Combine + +final class CounterViewController: UIViewController { + @Shared(.count) var count + var cancellables: Set = [] + + struct Representable: UIViewControllerRepresentable { + func makeUIViewController(context: Context) -> CounterViewController { + CounterViewController() + } + func updateUIViewController(_ uiViewController: CounterViewController, context: Context) { + } + } + + override func viewDidLoad() { + super.viewDidLoad() + + let stackView = UIStackView() + stackView.translatesAutoresizingMaskIntoConstraints = false + stackView.distribution = .fillProportionally + stackView.spacing = 8 + view.addSubview(stackView) + + let countLabel = UILabel() + countLabel.textColor = .black + countLabel.font = .preferredFont(forTextStyle: .largeTitle) + stackView.addArrangedSubview(countLabel) + + let decrementButton = UIButton(type: .system) + decrementButton.setTitle("Decrement", for: .normal) + decrementButton.titleLabel?.font = .preferredFont(forTextStyle: .body) + decrementButton.addAction( + UIAction { [$count] _ in + $count.withLock { $0 -= 1 } + }, + for: .touchUpInside + ) + stackView.addArrangedSubview(decrementButton) + + let incrementButton = UIButton(type: .system) + incrementButton.setTitle("Increment", for: .normal) + incrementButton.titleLabel?.font = .preferredFont(forTextStyle: .body) + incrementButton.addAction( + UIAction { [$count] _ in + $count.withLock { $0 += 1 } + }, + for: .touchUpInside + ) + stackView.addArrangedSubview(incrementButton) + + NSLayoutConstraint.activate([ + stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor), + stackView.topAnchor.constraint(equalTo: view.topAnchor), + stackView.bottomAnchor.constraint(equalTo: view.bottomAnchor), + stackView.heightAnchor.constraint(equalToConstant: 300) + ]) + + $count.publisher + .sink { + countLabel.text = $0.description + } + .store(in: &cancellables) + +// observe { [weak self] in +// guard let self else { return } +// countLabel.text = count.description +// } + } +} + +struct AppStorageRaceCondition: View { + @AppStorage("racey-count") var count = 0 + var body: some View { + Form { + Text("\(count)") + Button("Race!") { + Task { + await withTaskGroup(of: Void.self) { group in + for _ in 1...1_000 { + group.addTask { + await MainActor.run { + count += 1 + } + //_count.wrappedValue += 1 + } + } + } + } + } + } + } +} + +#Preview("AppStorage race condition") { + AppStorageRaceCondition() +} + +#Preview("AppStorageCounterView: Large count") { + let _ = UserDefaults.standard.set(10_000, forKey: "count") + AppStorageCounterView() +} +#Preview("AppStorageCounterView: Version 2") { + let _ = UserDefaults.standard.set(0, forKey: "count") + AppStorageCounterView() +} + +#Preview("CounterView: Large count") { + @Shared(.count) var count = 1_000_000 + CounterView() +} +#Preview("CounterView: Version 2") { + CounterView() +} diff --git a/0307-sharing-pt3/TourOfSharing/TourOfSharing/FactClient.swift b/0307-sharing-pt3/TourOfSharing/TourOfSharing/FactClient.swift new file mode 100644 index 00000000..5ebeee41 --- /dev/null +++ b/0307-sharing-pt3/TourOfSharing/TourOfSharing/FactClient.swift @@ -0,0 +1,16 @@ +import Dependencies +import Foundation + +struct FactClient: DependencyKey { + var fetch: @Sendable (Int) async throws -> String + + static let liveValue = FactClient { number in + try await String(decoding: URLSession.shared.data(from: URL(string: "http://numbersapi.com/\(number)")!).0, as: UTF8.self) + } + + static let previewValue = goodFacts + + static let goodFacts = FactClient { number in + "\(number) is a good number!" + } +} diff --git a/0307-sharing-pt3/TourOfSharing/TourOfSharing/FactFeature.swift b/0307-sharing-pt3/TourOfSharing/TourOfSharing/FactFeature.swift new file mode 100644 index 00000000..98430220 --- /dev/null +++ b/0307-sharing-pt3/TourOfSharing/TourOfSharing/FactFeature.swift @@ -0,0 +1,131 @@ +import Dependencies +import IssueReporting +import Sharing +import SwiftUI + +struct Fact: Codable, Identifiable { + let id: UUID + var number: Int + var savedAt: Date + var value: String +} + +@Observable +@MainActor +class FactFeatureModel { + @ObservationIgnored + @Shared(.count) var count + + var fact: String? + + @ObservationIgnored + @Shared(.favoriteFacts) var favoriteFacts + + @ObservationIgnored + @Dependency(FactClient.self) var factClient + + func incrementButtonTapped() { + $count.withLock { $0 += 1 } + fact = nil + } + + func decrementButtonTapped() { + $count.withLock { $0 -= 1 } + fact = nil + } + + func getFactButtonTapped() async { + do { + let fact = try await factClient.fetch(count) + withAnimation { + self.fact = fact + } + } catch { + reportIssue(error) + } + } + + func favoriteFactButtonTapped() { + guard let fact else { return } + withAnimation { + self.fact = nil + $favoriteFacts.withLock { + $0.insert(Fact(id: UUID(), number: count, savedAt: Date(), value: fact), at: 0) + } + } + } + + func deleteFacts(indexSet: IndexSet) { + $favoriteFacts.withLock { + $0.remove(atOffsets: indexSet) + } + } +} + +struct FactFeatureView: View { + @State var model = FactFeatureModel() + + var body: some View { + Form { + Section { + Text("\(model.count)") + Button("Decrement") { model.decrementButtonTapped() } + Button("Increment") { model.incrementButtonTapped() } + } + Section { + Button("Get fact") { + Task { + await model.getFactButtonTapped() + } + } + if let fact = model.fact { + HStack { + Text(fact) + Button { + model.favoriteFactButtonTapped() + } label: { + Image(systemName: "star") + } + } + } + } + if !model.favoriteFacts.isEmpty { + Section { + ForEach(model.favoriteFacts) { fact in + Text(fact.value) + } + .onDelete { indexSet in + model.deleteFacts(indexSet: indexSet) + } + } header: { + Text("Favorites") + } + } + } + } +} + +extension SharedKey where Self == FileStorageKey<[Fact]>.Default { + static var favoriteFacts: Self { + Self[.fileStorage(dump(.documentsDirectory.appending(component: "favorite-facts.json"))), default: []] + } +} + +#Preview { + @Shared(.count) var count = 101 + @Shared(.favoriteFacts) var favoriteFacts = (1...100).map { index in + Fact(id: UUID(), number: index, savedAt: Date(), value: "\(index) is a really good number!") + } + FactFeatureView() +} + +#Preview { + FactFeatureView() +} + +#Preview( + "Live", + traits: .dependency(\.context, .live) +) { + FactFeatureView() +} diff --git a/0307-sharing-pt3/TourOfSharing/TourOfSharing/Info.plist b/0307-sharing-pt3/TourOfSharing/TourOfSharing/Info.plist new file mode 100644 index 00000000..6a6654d9 --- /dev/null +++ b/0307-sharing-pt3/TourOfSharing/TourOfSharing/Info.plist @@ -0,0 +1,11 @@ + + + + + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + + + diff --git a/0307-sharing-pt3/TourOfSharing/TourOfSharing/TourOfSharingApp.swift b/0307-sharing-pt3/TourOfSharing/TourOfSharing/TourOfSharingApp.swift new file mode 100644 index 00000000..9533a52f --- /dev/null +++ b/0307-sharing-pt3/TourOfSharing/TourOfSharing/TourOfSharingApp.swift @@ -0,0 +1,12 @@ +import SwiftUI + +@main +struct TourOfSharingApp: App { + var body: some Scene { + WindowGroup { + FactFeatureView() + //ManyCountersView() + //CounterView() + } + } +} diff --git a/0307-sharing-pt3/TourOfSharing/TourOfSharingTests/TourOfSharingTests.swift b/0307-sharing-pt3/TourOfSharing/TourOfSharingTests/TourOfSharingTests.swift new file mode 100644 index 00000000..7087a6c9 --- /dev/null +++ b/0307-sharing-pt3/TourOfSharing/TourOfSharingTests/TourOfSharingTests.swift @@ -0,0 +1,17 @@ +// +// TourOfSharingTests.swift +// TourOfSharingTests +// +// Created by Point-Free on 11/15/24. +// + +import Testing +@testable import TourOfSharing + +struct TourOfSharingTests { + + @Test func example() async throws { + // Write your test here and use APIs like `#expect(...)` to check expected conditions. + } + +} diff --git a/0307-sharing-pt3/TourOfSharing/TourOfSharingUITests/TourOfSharingUITests.swift b/0307-sharing-pt3/TourOfSharing/TourOfSharingUITests/TourOfSharingUITests.swift new file mode 100644 index 00000000..5fac01f5 --- /dev/null +++ b/0307-sharing-pt3/TourOfSharing/TourOfSharingUITests/TourOfSharingUITests.swift @@ -0,0 +1,43 @@ +// +// TourOfSharingUITests.swift +// TourOfSharingUITests +// +// Created by Point-Free on 11/15/24. +// + +import XCTest + +final class TourOfSharingUITests: XCTestCase { + + override func setUpWithError() throws { + // Put setup code here. This method is called before the invocation of each test method in the class. + + // In UI tests it is usually best to stop immediately when a failure occurs. + continueAfterFailure = false + + // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. + } + + override func tearDownWithError() throws { + // Put teardown code here. This method is called after the invocation of each test method in the class. + } + + @MainActor + func testExample() throws { + // UI tests must launch the application that they test. + let app = XCUIApplication() + app.launch() + + // Use XCTAssert and related functions to verify your tests produce the correct results. + } + + @MainActor + func testLaunchPerformance() throws { + if #available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 7.0, *) { + // This measures how long it takes to launch your application. + measure(metrics: [XCTApplicationLaunchMetric()]) { + XCUIApplication().launch() + } + } + } +} diff --git a/0307-sharing-pt3/TourOfSharing/TourOfSharingUITests/TourOfSharingUITestsLaunchTests.swift b/0307-sharing-pt3/TourOfSharing/TourOfSharingUITests/TourOfSharingUITestsLaunchTests.swift new file mode 100644 index 00000000..30a26050 --- /dev/null +++ b/0307-sharing-pt3/TourOfSharing/TourOfSharingUITests/TourOfSharingUITestsLaunchTests.swift @@ -0,0 +1,33 @@ +// +// TourOfSharingUITestsLaunchTests.swift +// TourOfSharingUITests +// +// Created by Point-Free on 11/15/24. +// + +import XCTest + +final class TourOfSharingUITestsLaunchTests: XCTestCase { + + override class var runsForEachTargetApplicationUIConfiguration: Bool { + true + } + + override func setUpWithError() throws { + continueAfterFailure = false + } + + @MainActor + func testLaunch() throws { + let app = XCUIApplication() + app.launch() + + // Insert steps here to perform after app launch but before taking a screenshot, + // such as logging into a test account or navigating somewhere in the app + + let attachment = XCTAttachment(screenshot: app.screenshot()) + attachment.name = "Launch Screen" + attachment.lifetime = .keepAlways + add(attachment) + } +} diff --git a/README.md b/README.md index 59a15f37..08165ebe 100644 --- a/README.md +++ b/README.md @@ -306,5 +306,6 @@ This repository is the home of code written on episodes of [Point-Free](https:// 1. [SQLite: GRDB](0302-sqlite-pt2) 1. [SQLite: SwiftUI](0303-sqlite-pt3) 1. [SQLite: Observation](0304-sqlite-pt4) -1. [Tour of Sharing: App Storate, Part 1](0305-sharing-pt1) -1. [Tour of Sharing: App Storate, Part 2](0306-sharing-pt2) +1. [Tour of Sharing: App Storage, Part 1](0305-sharing-pt1) +1. [Tour of Sharing: App Storage, Part 2](0306-sharing-pt2) +1. [Tour of Sharing: File Storage, Part 1](0307-sharing-pt3)