Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Package.resolved
*.xcuserstate
**/*.xcworkspace/xcshareddata/
**/*.xcworkspace/contents.xcworkspacedata
**/.derivedData

# blanche
context/
61 changes: 54 additions & 7 deletions Examples/DiaryApp/DiaryApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
/* Begin PBXBuildFile section */
774570BB2DDD0216004AB32E /* Chiui in Frameworks */ = {isa = PBXBuildFile; productRef = 774570BA2DDD0216004AB32E /* Chiui */; };
77BF54992F7579CE00E1D60D /* Chiui in Frameworks */ = {isa = PBXBuildFile; productRef = 77BF54982F7579CE00E1D60D /* Chiui */; };
77BF55082F7D4D2100E1D60D /* Chiui in Frameworks */ = {isa = PBXBuildFile; productRef = 77BF55072F7D4D2100E1D60D /* Chiui */; };
77BF550B2F7D4D6400E1D60D /* Chiui in Frameworks */ = {isa = PBXBuildFile; productRef = 77BF550A2F7D4D6400E1D60D /* Chiui */; };
77BF550E2F7D4D7200E1D60D /* Chiui in Frameworks */ = {isa = PBXBuildFile; productRef = 77BF550D2F7D4D7200E1D60D /* Chiui */; };
77BF55652F8535DA00E1D60D /* Chiui in Frameworks */ = {isa = PBXBuildFile; productRef = 77BF55642F8535DA00E1D60D /* Chiui */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -57,8 +61,12 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
77BF55082F7D4D2100E1D60D /* Chiui in Frameworks */,
774570BB2DDD0216004AB32E /* Chiui in Frameworks */,
77BF54992F7579CE00E1D60D /* Chiui in Frameworks */,
77BF55652F8535DA00E1D60D /* Chiui in Frameworks */,
77BF550B2F7D4D6400E1D60D /* Chiui in Frameworks */,
77BF550E2F7D4D7200E1D60D /* Chiui in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -121,6 +129,10 @@
packageProductDependencies = (
774570BA2DDD0216004AB32E /* Chiui */,
77BF54982F7579CE00E1D60D /* Chiui */,
77BF55072F7D4D2100E1D60D /* Chiui */,
77BF550A2F7D4D6400E1D60D /* Chiui */,
77BF550D2F7D4D7200E1D60D /* Chiui */,
77BF55642F8535DA00E1D60D /* Chiui */,
);
productName = DiaryApp;
productReference = 774570542DDCFF04004AB32E /* DiaryApp.app */;
Expand Down Expand Up @@ -180,7 +192,7 @@
attributes = {
BuildIndependentTargetsInParallel = 1;
LastSwiftUpdateCheck = 1620;
LastUpgradeCheck = 1620;
LastUpgradeCheck = 2630;
TargetAttributes = {
774570532DDCFF04004AB32E = {
CreatedOnToolsVersion = 16.2;
Expand All @@ -205,7 +217,7 @@
mainGroup = 7745704B2DDCFF04004AB32E;
minimizedProjectReferenceProxies = 1;
packageReferences = (
77BF54972F7579CE00E1D60D /* XCLocalSwiftPackageReference "../../../Chiui" */,
77BF55632F8535DA00E1D60D /* XCRemoteSwiftPackageReference "chiui" */,
);
preferredProjectObjectVersion = 77;
productRefGroup = 774570552DDCFF04004AB32E /* Products */;
Expand Down Expand Up @@ -315,6 +327,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
Expand All @@ -337,6 +350,7 @@
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
STRING_CATALOG_GENERATE_SYMBOLS = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
Expand Down Expand Up @@ -376,6 +390,7 @@
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand All @@ -391,6 +406,7 @@
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
STRING_CATALOG_GENERATE_SYMBOLS = YES;
SWIFT_COMPILATION_MODE = wholemodule;
};
name = Release;
Expand All @@ -403,8 +419,11 @@
CODE_SIGN_ENTITLEMENTS = DiaryApp/DiaryApp.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"DiaryApp/Preview Content\"";
ENABLE_APP_SANDBOX = YES;
ENABLE_PREVIEWS = YES;
ENABLE_USER_SELECTED_FILES = readonly;
GENERATE_INFOPLIST_FILE = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
Expand Down Expand Up @@ -440,8 +459,11 @@
CODE_SIGN_ENTITLEMENTS = DiaryApp/DiaryApp.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"DiaryApp/Preview Content\"";
ENABLE_APP_SANDBOX = YES;
ENABLE_PREVIEWS = YES;
ENABLE_USER_SELECTED_FILES = readonly;
GENERATE_INFOPLIST_FILE = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
Expand Down Expand Up @@ -475,6 +497,7 @@
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 18.2;
MACOSX_DEPLOYMENT_TARGET = 15.2;
Expand All @@ -497,6 +520,7 @@
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 18.2;
MACOSX_DEPLOYMENT_TARGET = 15.2;
Expand All @@ -518,6 +542,7 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 18.2;
MACOSX_DEPLOYMENT_TARGET = 15.2;
Expand All @@ -539,6 +564,7 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
GENERATE_INFOPLIST_FILE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 18.2;
MACOSX_DEPLOYMENT_TARGET = 15.2;
Expand Down Expand Up @@ -596,12 +622,16 @@
};
/* End XCConfigurationList section */

/* Begin XCLocalSwiftPackageReference section */
77BF54972F7579CE00E1D60D /* XCLocalSwiftPackageReference "../../../Chiui" */ = {
isa = XCLocalSwiftPackageReference;
relativePath = ../../../Chiui;
/* Begin XCRemoteSwiftPackageReference section */
77BF55632F8535DA00E1D60D /* XCRemoteSwiftPackageReference "chiui" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/den-ree/chiui";
requirement = {
kind = exactVersion;
version = 1.0.1;
};
};
/* End XCLocalSwiftPackageReference section */
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
774570BA2DDD0216004AB32E /* Chiui */ = {
Expand All @@ -612,6 +642,23 @@
isa = XCSwiftPackageProductDependency;
productName = Chiui;
};
77BF55072F7D4D2100E1D60D /* Chiui */ = {
isa = XCSwiftPackageProductDependency;
productName = Chiui;
};
77BF550A2F7D4D6400E1D60D /* Chiui */ = {
isa = XCSwiftPackageProductDependency;
productName = Chiui;
};
77BF550D2F7D4D7200E1D60D /* Chiui */ = {
isa = XCSwiftPackageProductDependency;
productName = Chiui;
};
77BF55642F8535DA00E1D60D /* Chiui */ = {
isa = XCSwiftPackageProductDependency;
package = 77BF55632F8535DA00E1D60D /* XCRemoteSwiftPackageReference "chiui" */;
productName = Chiui;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 7745704C2DDCFF04004AB32E /* Project object */;
Expand Down
52 changes: 45 additions & 7 deletions Examples/DiaryApp/DiaryApp/Core/Entities/DiaryEntry.swift
Original file line number Diff line number Diff line change
@@ -1,22 +1,60 @@
import Foundation

/// Represents a single diary entry
enum DiaryEntryMood: String, CaseIterable, Equatable, Sendable {
case awful
case bad
case meh
case okay
case good
case great
case amazing

var title: String {
switch self {
case .awful: "Awful"
case .bad: "Bad"
case .meh: "Meh"
case .okay: "Okay"
case .good: "Good"
case .great: "Great"
case .amazing: "Amazing"
}
}
}

struct DiaryEntry: Identifiable, Equatable, Sendable {
/// Unique identifier for the entry
let id: UUID
/// Title of the diary entry
let title: String
/// Content of the diary entry
let content: String
/// Date when the entry was created
let createdAt: Date
let mood: DiaryEntryMood

init(
id: UUID,
title: String,
content: String,
createdAt: Date,
mood: DiaryEntryMood = .okay
) {
self.id = id
self.title = title
self.content = content
self.createdAt = createdAt
self.mood = mood
}

func new(title: String, content: String) -> Self {
func new(
title: String,
content: String,
createdAt: Date? = nil,
mood: DiaryEntryMood? = nil
) -> Self {
return .init(
id: id,
title: title,
content: content,
createdAt: createdAt
createdAt: createdAt ?? self.createdAt,
mood: mood ?? self.mood
)
}
}
7 changes: 1 addition & 6 deletions Examples/DiaryApp/DiaryApp/DiaryApp.entitlements
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?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>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
</dict>
<dict/>
</plist>
Original file line number Diff line number Diff line change
@@ -1,29 +1,50 @@
import SwiftUI
import Chiui

/// View for adding a new diary entry
struct DiaryEntryView: ContextualView {
/// View model for adding diary entries
@StateObject var viewModel: DiaryEntryViewModel
/// Environment presentation mode for dismissing the view
@Environment(\.presentationMode) private var presentationMode
/// Focus state for tracking which field is being edited
@FocusState private var focusedField: Field?

enum Field: Equatable {
case title
case content
}

/// Creates a new add diary entry view
/// - Parameter viewModel: View model to use
init(_ context: DiaryContext) {
_viewModel = .init(wrappedValue: .init(context))
}

var body: some View {
ZStack {
Form {
Section(header: Text("Date")) {
Button {
focusedField = nil
viewModel.openDateSelection()
} label: {
HStack {
Text("Entry Date")
Spacer()
Text(state.selectedDate, style: .date)
.foregroundStyle(.secondary)
}
}
}

Section(header: Text("Mood")) {
Button {
focusedField = nil
viewModel.openMoodSelection()
} label: {
HStack {
Text("Mood")
Spacer()
Text(state.selectedMood.title)
.foregroundStyle(.secondary)
}
}
}

Section(header: Text("Title")) {
TextField("Enter title", text: bindTo(\.title) { viewModel.updateTitle($0) })
.focused($focusedField, equals: .title)
Expand Down Expand Up @@ -68,10 +89,13 @@ struct DiaryEntryView: ContextualView {
}
}
}
.onChange(of: state.shouldDismiss) { _, newValue in
if newValue {
presentationMode.wrappedValue.dismiss()
}
.navigationDestination(
isPresented: bindTo(\.isDateSelectionPresented) { _ in }
) {
DiaryEntryDateSelectionView(viewModel.context)
}
.sheet(isPresented: bindTo(\.isMoodSelectionPresented) { _ in }) {
DiaryEntryMoodSelectionView(viewModel.context)
}

if state.savingStatus == .saving {
Expand Down
Loading
Loading