diff --git a/0282-modern-uikit-pt2/README.md b/0282-modern-uikit-pt2/README.md new file mode 100644 index 00000000..5c8e49a9 --- /dev/null +++ b/0282-modern-uikit-pt2/README.md @@ -0,0 +1,7 @@ +## [Point-Free](https://www.pointfree.co) + +> #### This directory contains code from Point-Free Episode: [Modern UIKit: Sneak Peek, Part 2](https://www.pointfree.co/episodes/ep282-modern-uikit-sneak-peek-part-2) +> +> We finish building a modern UIKit application with brand new state-driven tools, including a complex collection view that can navigate to two child features. And we will see that, thanks to our back-port of Swift’s observation tools, we will be able to deploy our app all the way back to iOS 13. + +This week's episode is a sneak peek so there is no code sample. diff --git a/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit.xcodeproj/project.pbxproj b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit.xcodeproj/project.pbxproj new file mode 100644 index 00000000..40a13dc7 --- /dev/null +++ b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit.xcodeproj/project.pbxproj @@ -0,0 +1,384 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + 2A1CEB272BFD271600753A66 /* Perception in Frameworks */ = {isa = PBXBuildFile; productRef = 2A1CEB262BFD271600753A66 /* Perception */; }; + 4B54C2252BFD0D1900E95174 /* ModernUIKitApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B54C2242BFD0D1900E95174 /* ModernUIKitApp.swift */; }; + 4B54C2292BFD0D1A00E95174 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B54C2282BFD0D1A00E95174 /* Assets.xcassets */; }; + 4B54C22C2BFD0D1A00E95174 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4B54C22B2BFD0D1A00E95174 /* Preview Assets.xcassets */; }; + 4B54C24F2BFD0D9B00E95174 /* CounterFeature.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B54C24E2BFD0D9B00E95174 /* CounterFeature.swift */; }; + 4B69F6382BFD151E009B28BB /* Observation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B69F6372BFD151E009B28BB /* Observation.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 2A1CEB242BFD1A3800753A66 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; + 4B54C2212BFD0D1900E95174 /* ModernUIKit.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ModernUIKit.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 4B54C2242BFD0D1900E95174 /* ModernUIKitApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModernUIKitApp.swift; sourceTree = ""; }; + 4B54C2282BFD0D1A00E95174 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 4B54C22B2BFD0D1A00E95174 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; + 4B54C24E2BFD0D9B00E95174 /* CounterFeature.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CounterFeature.swift; sourceTree = ""; }; + 4B69F6372BFD151E009B28BB /* Observation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Observation.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 4B54C21E2BFD0D1900E95174 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 2A1CEB272BFD271600753A66 /* Perception in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 4B54C2182BFD0D1900E95174 = { + isa = PBXGroup; + children = ( + 4B54C2232BFD0D1900E95174 /* ModernUIKit */, + 4B54C2222BFD0D1900E95174 /* Products */, + ); + sourceTree = ""; + }; + 4B54C2222BFD0D1900E95174 /* Products */ = { + isa = PBXGroup; + children = ( + 4B54C2212BFD0D1900E95174 /* ModernUIKit.app */, + ); + name = Products; + sourceTree = ""; + }; + 4B54C2232BFD0D1900E95174 /* ModernUIKit */ = { + isa = PBXGroup; + children = ( + 2A1CEB242BFD1A3800753A66 /* Info.plist */, + 4B54C24E2BFD0D9B00E95174 /* CounterFeature.swift */, + 4B69F6372BFD151E009B28BB /* Observation.swift */, + 4B54C2242BFD0D1900E95174 /* ModernUIKitApp.swift */, + 4B54C2282BFD0D1A00E95174 /* Assets.xcassets */, + 4B54C22A2BFD0D1A00E95174 /* Preview Content */, + ); + path = ModernUIKit; + sourceTree = ""; + }; + 4B54C22A2BFD0D1A00E95174 /* Preview Content */ = { + isa = PBXGroup; + children = ( + 4B54C22B2BFD0D1A00E95174 /* Preview Assets.xcassets */, + ); + path = "Preview Content"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 4B54C2202BFD0D1900E95174 /* ModernUIKit */ = { + isa = PBXNativeTarget; + buildConfigurationList = 4B54C2452BFD0D1A00E95174 /* Build configuration list for PBXNativeTarget "ModernUIKit" */; + buildPhases = ( + 4B54C21D2BFD0D1900E95174 /* Sources */, + 4B54C21E2BFD0D1900E95174 /* Frameworks */, + 4B54C21F2BFD0D1900E95174 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = ModernUIKit; + packageProductDependencies = ( + 2A1CEB262BFD271600753A66 /* Perception */, + ); + productName = ModernUIKit; + productReference = 4B54C2212BFD0D1900E95174 /* ModernUIKit.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 4B54C2192BFD0D1900E95174 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1540; + LastUpgradeCheck = 1540; + TargetAttributes = { + 4B54C2202BFD0D1900E95174 = { + CreatedOnToolsVersion = 15.4; + }; + }; + }; + buildConfigurationList = 4B54C21C2BFD0D1900E95174 /* Build configuration list for PBXProject "ModernUIKit" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 4B54C2182BFD0D1900E95174; + packageReferences = ( + 2A1CEB252BFD271600753A66 /* XCRemoteSwiftPackageReference "swift-perception" */, + ); + productRefGroup = 4B54C2222BFD0D1900E95174 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 4B54C2202BFD0D1900E95174 /* ModernUIKit */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 4B54C21F2BFD0D1900E95174 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4B54C22C2BFD0D1A00E95174 /* Preview Assets.xcassets in Resources */, + 4B54C2292BFD0D1A00E95174 /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 4B54C21D2BFD0D1900E95174 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4B54C2252BFD0D1900E95174 /* ModernUIKitApp.swift in Sources */, + 4B69F6382BFD151E009B28BB /* Observation.swift in Sources */, + 4B54C24F2BFD0D9B00E95174 /* CounterFeature.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 4B54C2432BFD0D1A00E95174 /* 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 = 16.0; + 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_STRICT_CONCURRENCY = complete; + }; + name = Debug; + }; + 4B54C2442BFD0D1A00E95174 /* 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 = 16.0; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_STRICT_CONCURRENCY = complete; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 4B54C2462BFD0D1A00E95174 /* 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 = "\"ModernUIKit/Preview Content\""; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = ModernUIKit/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.ModernUIKit; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 4B54C2472BFD0D1A00E95174 /* 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 = "\"ModernUIKit/Preview Content\""; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = ModernUIKit/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.ModernUIKit; + 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 */ + 4B54C21C2BFD0D1900E95174 /* Build configuration list for PBXProject "ModernUIKit" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4B54C2432BFD0D1A00E95174 /* Debug */, + 4B54C2442BFD0D1A00E95174 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 4B54C2452BFD0D1A00E95174 /* Build configuration list for PBXNativeTarget "ModernUIKit" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4B54C2462BFD0D1A00E95174 /* Debug */, + 4B54C2472BFD0D1A00E95174 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + +/* Begin XCRemoteSwiftPackageReference section */ + 2A1CEB252BFD271600753A66 /* XCRemoteSwiftPackageReference "swift-perception" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/pointfreeco/swift-perception"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 1.1.7; + }; + }; +/* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 2A1CEB262BFD271600753A66 /* Perception */ = { + isa = XCSwiftPackageProductDependency; + package = 2A1CEB252BFD271600753A66 /* XCRemoteSwiftPackageReference "swift-perception" */; + productName = Perception; + }; +/* End XCSwiftPackageProductDependency section */ + }; + rootObject = 4B54C2192BFD0D1900E95174 /* Project object */; +} diff --git a/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/Assets.xcassets/AccentColor.colorset/Contents.json b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 00000000..eb878970 --- /dev/null +++ b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/Assets.xcassets/AppIcon.appiconset/Contents.json b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..13613e3e --- /dev/null +++ b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,13 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/Assets.xcassets/Contents.json b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/Assets.xcassets/Contents.json new file mode 100644 index 00000000..73c00596 --- /dev/null +++ b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/CounterFeature.swift b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/CounterFeature.swift new file mode 100644 index 00000000..8e8d1794 --- /dev/null +++ b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/CounterFeature.swift @@ -0,0 +1,160 @@ +import Perception +@preconcurrency import SwiftUI + +@MainActor +@Perceptible +class CounterModel { + var count = 0 + var fact: String? + var factIsLoading = false + func incrementButtonTapped() { + count += 1 + fact = nil + } + func decrementButtonTapped() { + count -= 1 + fact = nil + } + func factButtonTapped() async { + withUIAnimation { + self.fact = nil + } + self.factIsLoading = true + defer { self.factIsLoading = false } + + do { + try await Task.sleep(for: .seconds(1)) + let loadedFact = try await String( + decoding: URLSession.shared + .data( + from: URL(string: "http://www.numberapi.com/\(count)")! + ).0, + as: UTF8.self + ) + withUIAnimation { + self.fact = loadedFact + } + } catch { + // TODO: error handling + } + } +} + +struct CounterView: View { + let model: CounterModel + var body: some View { + WithPerceptionTracking { + Form { + Text("\(model.count)") + Button("Decrement") { model.decrementButtonTapped() } + Button("Increment") { model.incrementButtonTapped() } + + if let fact = model.fact { + Text(fact) + } else if model.factIsLoading { + ProgressView().id(UUID()) + } + + Button("Get fact") { + Task { + await model.factButtonTapped() + } + } + } + .disabled(model.factIsLoading) + } + } +} + +#Preview("SwiftUI") { + CounterView(model: CounterModel()) +} + +final class CounterViewController: UIViewController { + let model: CounterModel + + init(model: CounterModel) { + self.model = model + super.init(nibName: nil, bundle: nil) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func viewDidLoad() { + super.viewDidLoad() + + let countLabel = UILabel() + countLabel.textAlignment = .center + let decrementButton = UIButton(type: .system, primaryAction: UIAction { [weak self] _ in + self?.model.decrementButtonTapped() + }) + decrementButton.setTitle("Decrement", for: .normal) + let incrementButton = UIButton(type: .system, primaryAction: UIAction { [weak self] _ in + self?.model.incrementButtonTapped() + }) + incrementButton.setTitle("Increment", for: .normal) + + let factLabel = UILabel() + factLabel.numberOfLines = 0 + let activityIndicator = UIActivityIndicatorView() + activityIndicator.startAnimating() + let factButton = UIButton(type: .system, primaryAction: UIAction { [weak self] _ in + guard let self else { return } + Task { await self.model.factButtonTapped() } + }) + factButton.setTitle("Get fact", for: .normal) + + let counterStack = UIStackView(arrangedSubviews: [ + countLabel, + decrementButton, + incrementButton, + factLabel, + activityIndicator, + factButton, + ]) + counterStack.axis = .vertical + counterStack.spacing = 12 + counterStack.translatesAutoresizingMaskIntoConstraints = false + + view.addSubview(counterStack) + NSLayoutConstraint.activate([ + counterStack.centerXAnchor.constraint(equalTo: view.centerXAnchor), + counterStack.centerYAnchor.constraint(equalTo: view.centerYAnchor), + counterStack.leadingAnchor.constraint(equalTo: view.leadingAnchor), + counterStack.trailingAnchor.constraint(equalTo: view.trailingAnchor), + ]) + + observe { [weak self] in + guard let self else { return } + countLabel.text = "\(model.count)" + + activityIndicator.isHidden = !model.factIsLoading + factLabel.text = model.fact + factLabel.isHidden = model.fact == nil + decrementButton.isEnabled = !model.factIsLoading + incrementButton.isEnabled = !model.factIsLoading + factButton.isEnabled = !model.factIsLoading + } + } +} + +#Preview("UIKit") { + UIViewControllerRepresenting { + CounterViewController(model: CounterModel()) + } +} + +struct UIViewControllerRepresenting: UIViewControllerRepresentable { + let base: UIViewController + init(base: () -> UIViewController) { + self.base = base() + } + + func makeUIViewController(context: Context) -> some UIViewController { + return base + } + func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) { + } +} diff --git a/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/Info.plist b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/Info.plist new file mode 100644 index 00000000..6a6654d9 --- /dev/null +++ b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/Info.plist @@ -0,0 +1,11 @@ + + + + + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + + + diff --git a/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/ModernUIKitApp.swift b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/ModernUIKitApp.swift new file mode 100644 index 00000000..4408c430 --- /dev/null +++ b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/ModernUIKitApp.swift @@ -0,0 +1,13 @@ +import SwiftUI + +@main +struct ModernUIKitApp: App { + var body: some Scene { + WindowGroup { + CounterView(model: CounterModel()) +// UIViewControllerRepresenting { +// CounterViewController(model: CounterModel()) +// } + } + } +} diff --git a/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/Observation.swift b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/Observation.swift new file mode 100644 index 00000000..917afe08 --- /dev/null +++ b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/Observation.swift @@ -0,0 +1,52 @@ +import Foundation +import Perception +import UIKit + +@MainActor +func observe( + apply: @escaping @MainActor @Sendable () -> Void +) { + onChange(apply: apply) +} +@MainActor +func onChange( + apply: @escaping @MainActor @Sendable () -> Void +) { + withPerceptionTracking { + apply() + } onChange: { + Task { @MainActor in + if let animation = UIAnimation.current { + UIView.animate(withDuration: animation.duration) { + onChange(apply: apply) + } + } else { + onChange(apply: apply) + } + } + } +} + +extension NSObject { + @MainActor + func observe( + apply: @escaping @MainActor @Sendable () -> Void + ) { + ModernUIKit.observe(apply: apply) + } +} + +struct UIAnimation { + @TaskLocal fileprivate static var current: Self? + var duration: TimeInterval +} + +@MainActor +func withUIAnimation( + _ animation: UIAnimation? = UIAnimation(duration: 0.3), + body: @escaping () -> Void +) { + UIAnimation.$current.withValue(animation) { + body() + } +} diff --git a/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/Preview Content/Preview Assets.xcassets/Contents.json b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/Preview Content/Preview Assets.xcassets/Contents.json new file mode 100644 index 00000000..73c00596 --- /dev/null +++ b/0283-modern-uikit-pt3/ModernUIKit/ModernUIKit/Preview Content/Preview Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/0283-modern-uikit-pt3/README.md b/0283-modern-uikit-pt3/README.md new file mode 100644 index 00000000..1360e84f --- /dev/null +++ b/0283-modern-uikit-pt3/README.md @@ -0,0 +1,6 @@ +## [Point-Free](https://www.pointfree.co) + +> #### This directory contains code from Point-Free Episode: [Modern UIKit: Observation](https://www.pointfree.co/episodes/ep283-modern-uikit-observation) +> +> It’s time to build modern tools for UIKit from scratch, heavily inspired by SwiftUI and using the Observation framework. Surprisingly, Swift 5.9’s observation tools _can_ be used in UIKit, and in fact they work _great_, despite being specifically tuned for SwiftUI. + diff --git a/README.md b/README.md index 15523e7d..ad78dc4c 100644 --- a/README.md +++ b/README.md @@ -283,3 +283,5 @@ This repository is the home of code written on episodes of [Point-Free](https:// 1. [Shared State in Practice: isowords, Part 1](0279-shared-state-in-practice-pt3) 1. [Shared State in Practice: isowords, Part 2](0280-shared-state-in-practice-pt4) 1. [Modern UIKit: Sneak Peek, Part 1](0281-modern-uikit-pt1) +1. [Modern UIKit: Sneak Peek, Part 2](0282-modern-uikit-pt2) +1. [Modern UIKit: Observation](0282-modern-uikit-pt3)