├── HabitTracker.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcuserdata │ └── AliMert.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── HabitTracker ├── App │ ├── ContentView.swift │ └── HabitTrackerApp.swift ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── Icon-App-20x20@1x.png │ │ ├── Icon-App-20x20@2x.png │ │ ├── Icon-App-20x20@3x.png │ │ ├── Icon-App-29x29@1x.png │ │ ├── Icon-App-29x29@2x.png │ │ ├── Icon-App-29x29@3x.png │ │ ├── Icon-App-40x40@1x.png │ │ ├── Icon-App-40x40@2x.png │ │ ├── Icon-App-40x40@3x.png │ │ ├── Icon-App-60x60@2x.png │ │ ├── Icon-App-60x60@3x.png │ │ ├── Icon-App-76x76@1x.png │ │ ├── Icon-App-76x76@2x.png │ │ ├── Icon-App-83.5x83.5@2x.png │ │ └── ItunesArtwork@2x.png │ ├── Card Colors │ │ ├── Card-1.colorset │ │ │ └── Contents.json │ │ ├── Card-2.colorset │ │ │ └── Contents.json │ │ ├── Card-3.colorset │ │ │ └── Contents.json │ │ ├── Card-4.colorset │ │ │ └── Contents.json │ │ ├── Card-5.colorset │ │ │ └── Contents.json │ │ ├── Card-6.colorset │ │ │ └── Contents.json │ │ ├── Card-7.colorset │ │ │ └── Contents.json │ │ └── Contents.json │ ├── Contents.json │ └── TFBG.colorset │ │ └── Contents.json ├── Common │ ├── Extensions │ │ └── View+Extensions.swift │ ├── ViewModifiers │ │ └── Delete.swift │ └── Views │ │ ├── DynamicFilteredView.swift │ │ └── RoundedCorner.swift ├── CoreData │ ├── CoreDataHabitManager.swift │ └── HabitTracker.xcdatamodeld │ │ ├── .xccurrentversion │ │ └── Shared.xcdatamodel │ │ └── contents └── Modules │ ├── AddHabit │ ├── View │ │ └── AddHabitView.swift │ └── ViewModel │ │ └── AddHabitViewModel.swift │ └── Habits │ ├── Delegate │ └── HabitDropDelegate.swift │ └── View │ ├── HabitCardView.swift │ └── HabitsView.swift ├── README.md └── screenshots ├── dark1.png ├── dark2.png ├── light1.png └── light2.png /HabitTracker.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 55; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | E1D53AFD283685B20089FD3C /* HabitTracker.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = E1D53AEA283685AF0089FD3C /* HabitTracker.xcdatamodeld */; }; 11 | E1D53AFF283685B20089FD3C /* HabitTrackerApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1D53AEC283685AF0089FD3C /* HabitTrackerApp.swift */; }; 12 | E1D53B01283685B20089FD3C /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1D53AED283685AF0089FD3C /* ContentView.swift */; }; 13 | E1D53B03283685B20089FD3C /* CoreDataHabitManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1D53AEE283685AF0089FD3C /* CoreDataHabitManager.swift */; }; 14 | E1D53B05283685B20089FD3C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E1D53AEF283685B20089FD3C /* Assets.xcassets */; }; 15 | E1D53B142836890E0089FD3C /* HabitsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1D53B132836890E0089FD3C /* HabitsView.swift */; }; 16 | E1D53B17283689D90089FD3C /* View+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1D53B16283689D90089FD3C /* View+Extensions.swift */; }; 17 | E1D53B1C28368DE50089FD3C /* DynamicFilteredView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1D53B1B28368DE50089FD3C /* DynamicFilteredView.swift */; }; 18 | E1D53B262836C0CE0089FD3C /* AddHabitView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1D53B252836C0CE0089FD3C /* AddHabitView.swift */; }; 19 | E1D53B2A2836C0E10089FD3C /* AddHabitViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1D53B292836C0E10089FD3C /* AddHabitViewModel.swift */; }; 20 | E1D53B312838F9FC0089FD3C /* HabitCardView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1D53B302838F9FC0089FD3C /* HabitCardView.swift */; }; 21 | E1D53B352839A4100089FD3C /* Delete.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1D53B342839A4100089FD3C /* Delete.swift */; }; 22 | E1D53B392839B89E0089FD3C /* HabitDropDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1D53B382839B89E0089FD3C /* HabitDropDelegate.swift */; }; 23 | E1D53B3C283AA4300089FD3C /* RoundedCorner.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1D53B3B283AA4300089FD3C /* RoundedCorner.swift */; }; 24 | /* End PBXBuildFile section */ 25 | 26 | /* Begin PBXFileReference section */ 27 | E1D53AEB283685AF0089FD3C /* Shared.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Shared.xcdatamodel; sourceTree = ""; }; 28 | E1D53AEC283685AF0089FD3C /* HabitTrackerApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HabitTrackerApp.swift; sourceTree = ""; }; 29 | E1D53AED283685AF0089FD3C /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 30 | E1D53AEE283685AF0089FD3C /* CoreDataHabitManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataHabitManager.swift; sourceTree = ""; }; 31 | E1D53AEF283685B20089FD3C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 32 | E1D53AF4283685B20089FD3C /* HabitTracker.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HabitTracker.app; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | E1D53B132836890E0089FD3C /* HabitsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HabitsView.swift; sourceTree = ""; }; 34 | E1D53B16283689D90089FD3C /* View+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "View+Extensions.swift"; sourceTree = ""; }; 35 | E1D53B1B28368DE50089FD3C /* DynamicFilteredView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DynamicFilteredView.swift; sourceTree = ""; }; 36 | E1D53B252836C0CE0089FD3C /* AddHabitView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddHabitView.swift; sourceTree = ""; }; 37 | E1D53B292836C0E10089FD3C /* AddHabitViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddHabitViewModel.swift; sourceTree = ""; }; 38 | E1D53B302838F9FC0089FD3C /* HabitCardView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HabitCardView.swift; sourceTree = ""; }; 39 | E1D53B342839A4100089FD3C /* Delete.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Delete.swift; sourceTree = ""; }; 40 | E1D53B382839B89E0089FD3C /* HabitDropDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HabitDropDelegate.swift; sourceTree = ""; }; 41 | E1D53B3B283AA4300089FD3C /* RoundedCorner.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundedCorner.swift; sourceTree = ""; }; 42 | /* End PBXFileReference section */ 43 | 44 | /* Begin PBXFrameworksBuildPhase section */ 45 | E1D53AF1283685B20089FD3C /* Frameworks */ = { 46 | isa = PBXFrameworksBuildPhase; 47 | buildActionMask = 2147483647; 48 | files = ( 49 | ); 50 | runOnlyForDeploymentPostprocessing = 0; 51 | }; 52 | /* End PBXFrameworksBuildPhase section */ 53 | 54 | /* Begin PBXGroup section */ 55 | E1D53AE4283685AF0089FD3C = { 56 | isa = PBXGroup; 57 | children = ( 58 | E1D53AE9283685AF0089FD3C /* HabitTracker */, 59 | E1D53AF5283685B20089FD3C /* Products */, 60 | ); 61 | sourceTree = ""; 62 | }; 63 | E1D53AE9283685AF0089FD3C /* HabitTracker */ = { 64 | isa = PBXGroup; 65 | children = ( 66 | E1D53B15283689C40089FD3C /* Common */, 67 | E1D53B0F283687ED0089FD3C /* App */, 68 | E1D53B102836880B0089FD3C /* Modules */, 69 | E1D53B2C2836E0CD0089FD3C /* CoreData */, 70 | E1D53AEF283685B20089FD3C /* Assets.xcassets */, 71 | ); 72 | path = HabitTracker; 73 | sourceTree = ""; 74 | }; 75 | E1D53AF5283685B20089FD3C /* Products */ = { 76 | isa = PBXGroup; 77 | children = ( 78 | E1D53AF4283685B20089FD3C /* HabitTracker.app */, 79 | ); 80 | name = Products; 81 | sourceTree = ""; 82 | }; 83 | E1D53B0F283687ED0089FD3C /* App */ = { 84 | isa = PBXGroup; 85 | children = ( 86 | E1D53AEC283685AF0089FD3C /* HabitTrackerApp.swift */, 87 | E1D53AED283685AF0089FD3C /* ContentView.swift */, 88 | ); 89 | path = App; 90 | sourceTree = ""; 91 | }; 92 | E1D53B102836880B0089FD3C /* Modules */ = { 93 | isa = PBXGroup; 94 | children = ( 95 | E1D53B232836C0670089FD3C /* AddHabit */, 96 | E1D53B11283688F70089FD3C /* Habits */, 97 | ); 98 | path = Modules; 99 | sourceTree = ""; 100 | }; 101 | E1D53B11283688F70089FD3C /* Habits */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | E1D53B372839B88B0089FD3C /* Delegate */, 105 | E1D53B12283689000089FD3C /* View */, 106 | ); 107 | path = Habits; 108 | sourceTree = ""; 109 | }; 110 | E1D53B12283689000089FD3C /* View */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | E1D53B132836890E0089FD3C /* HabitsView.swift */, 114 | E1D53B302838F9FC0089FD3C /* HabitCardView.swift */, 115 | ); 116 | path = View; 117 | sourceTree = ""; 118 | }; 119 | E1D53B15283689C40089FD3C /* Common */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | E1D53B332839A3E70089FD3C /* ViewModifiers */, 123 | E1D53B1A28368DE50089FD3C /* Views */, 124 | E1D53B1E2836908A0089FD3C /* Extensions */, 125 | ); 126 | path = Common; 127 | sourceTree = ""; 128 | }; 129 | E1D53B1A28368DE50089FD3C /* Views */ = { 130 | isa = PBXGroup; 131 | children = ( 132 | E1D53B1B28368DE50089FD3C /* DynamicFilteredView.swift */, 133 | E1D53B3B283AA4300089FD3C /* RoundedCorner.swift */, 134 | ); 135 | path = Views; 136 | sourceTree = ""; 137 | }; 138 | E1D53B1E2836908A0089FD3C /* Extensions */ = { 139 | isa = PBXGroup; 140 | children = ( 141 | E1D53B16283689D90089FD3C /* View+Extensions.swift */, 142 | ); 143 | path = Extensions; 144 | sourceTree = ""; 145 | }; 146 | E1D53B232836C0670089FD3C /* AddHabit */ = { 147 | isa = PBXGroup; 148 | children = ( 149 | E1D53B282836C0D10089FD3C /* ViewModel */, 150 | E1D53B242836C0960089FD3C /* View */, 151 | ); 152 | path = AddHabit; 153 | sourceTree = ""; 154 | }; 155 | E1D53B242836C0960089FD3C /* View */ = { 156 | isa = PBXGroup; 157 | children = ( 158 | E1D53B252836C0CE0089FD3C /* AddHabitView.swift */, 159 | ); 160 | path = View; 161 | sourceTree = ""; 162 | }; 163 | E1D53B282836C0D10089FD3C /* ViewModel */ = { 164 | isa = PBXGroup; 165 | children = ( 166 | E1D53B292836C0E10089FD3C /* AddHabitViewModel.swift */, 167 | ); 168 | path = ViewModel; 169 | sourceTree = ""; 170 | }; 171 | E1D53B2C2836E0CD0089FD3C /* CoreData */ = { 172 | isa = PBXGroup; 173 | children = ( 174 | E1D53AEA283685AF0089FD3C /* HabitTracker.xcdatamodeld */, 175 | E1D53AEE283685AF0089FD3C /* CoreDataHabitManager.swift */, 176 | ); 177 | path = CoreData; 178 | sourceTree = ""; 179 | }; 180 | E1D53B332839A3E70089FD3C /* ViewModifiers */ = { 181 | isa = PBXGroup; 182 | children = ( 183 | E1D53B342839A4100089FD3C /* Delete.swift */, 184 | ); 185 | path = ViewModifiers; 186 | sourceTree = ""; 187 | }; 188 | E1D53B372839B88B0089FD3C /* Delegate */ = { 189 | isa = PBXGroup; 190 | children = ( 191 | E1D53B382839B89E0089FD3C /* HabitDropDelegate.swift */, 192 | ); 193 | path = Delegate; 194 | sourceTree = ""; 195 | }; 196 | /* End PBXGroup section */ 197 | 198 | /* Begin PBXNativeTarget section */ 199 | E1D53AF3283685B20089FD3C /* HabitTracker */ = { 200 | isa = PBXNativeTarget; 201 | buildConfigurationList = E1D53B09283685B20089FD3C /* Build configuration list for PBXNativeTarget "HabitTracker" */; 202 | buildPhases = ( 203 | E1D53AF0283685B20089FD3C /* Sources */, 204 | E1D53AF1283685B20089FD3C /* Frameworks */, 205 | E1D53AF2283685B20089FD3C /* Resources */, 206 | ); 207 | buildRules = ( 208 | ); 209 | dependencies = ( 210 | ); 211 | name = HabitTracker; 212 | productName = "HabitTracker (iOS)"; 213 | productReference = E1D53AF4283685B20089FD3C /* HabitTracker.app */; 214 | productType = "com.apple.product-type.application"; 215 | }; 216 | /* End PBXNativeTarget section */ 217 | 218 | /* Begin PBXProject section */ 219 | E1D53AE5283685AF0089FD3C /* Project object */ = { 220 | isa = PBXProject; 221 | attributes = { 222 | BuildIndependentTargetsInParallel = 1; 223 | LastSwiftUpdateCheck = 1330; 224 | LastUpgradeCheck = 1330; 225 | TargetAttributes = { 226 | E1D53AF3283685B20089FD3C = { 227 | CreatedOnToolsVersion = 13.3.1; 228 | }; 229 | }; 230 | }; 231 | buildConfigurationList = E1D53AE8283685AF0089FD3C /* Build configuration list for PBXProject "HabitTracker" */; 232 | compatibilityVersion = "Xcode 13.0"; 233 | developmentRegion = en; 234 | hasScannedForEncodings = 0; 235 | knownRegions = ( 236 | en, 237 | Base, 238 | ); 239 | mainGroup = E1D53AE4283685AF0089FD3C; 240 | productRefGroup = E1D53AF5283685B20089FD3C /* Products */; 241 | projectDirPath = ""; 242 | projectRoot = ""; 243 | targets = ( 244 | E1D53AF3283685B20089FD3C /* HabitTracker */, 245 | ); 246 | }; 247 | /* End PBXProject section */ 248 | 249 | /* Begin PBXResourcesBuildPhase section */ 250 | E1D53AF2283685B20089FD3C /* Resources */ = { 251 | isa = PBXResourcesBuildPhase; 252 | buildActionMask = 2147483647; 253 | files = ( 254 | E1D53B05283685B20089FD3C /* Assets.xcassets in Resources */, 255 | ); 256 | runOnlyForDeploymentPostprocessing = 0; 257 | }; 258 | /* End PBXResourcesBuildPhase section */ 259 | 260 | /* Begin PBXSourcesBuildPhase section */ 261 | E1D53AF0283685B20089FD3C /* Sources */ = { 262 | isa = PBXSourcesBuildPhase; 263 | buildActionMask = 2147483647; 264 | files = ( 265 | E1D53AFD283685B20089FD3C /* HabitTracker.xcdatamodeld in Sources */, 266 | E1D53B1C28368DE50089FD3C /* DynamicFilteredView.swift in Sources */, 267 | E1D53B03283685B20089FD3C /* CoreDataHabitManager.swift in Sources */, 268 | E1D53AFF283685B20089FD3C /* HabitTrackerApp.swift in Sources */, 269 | E1D53B3C283AA4300089FD3C /* RoundedCorner.swift in Sources */, 270 | E1D53B142836890E0089FD3C /* HabitsView.swift in Sources */, 271 | E1D53B262836C0CE0089FD3C /* AddHabitView.swift in Sources */, 272 | E1D53B392839B89E0089FD3C /* HabitDropDelegate.swift in Sources */, 273 | E1D53B17283689D90089FD3C /* View+Extensions.swift in Sources */, 274 | E1D53B2A2836C0E10089FD3C /* AddHabitViewModel.swift in Sources */, 275 | E1D53B352839A4100089FD3C /* Delete.swift in Sources */, 276 | E1D53B01283685B20089FD3C /* ContentView.swift in Sources */, 277 | E1D53B312838F9FC0089FD3C /* HabitCardView.swift in Sources */, 278 | ); 279 | runOnlyForDeploymentPostprocessing = 0; 280 | }; 281 | /* End PBXSourcesBuildPhase section */ 282 | 283 | /* Begin XCBuildConfiguration section */ 284 | E1D53B07283685B20089FD3C /* Debug */ = { 285 | isa = XCBuildConfiguration; 286 | buildSettings = { 287 | ALWAYS_SEARCH_USER_PATHS = NO; 288 | CLANG_ANALYZER_NONNULL = YES; 289 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 290 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 291 | CLANG_ENABLE_MODULES = YES; 292 | CLANG_ENABLE_OBJC_ARC = YES; 293 | CLANG_ENABLE_OBJC_WEAK = YES; 294 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 295 | CLANG_WARN_BOOL_CONVERSION = YES; 296 | CLANG_WARN_COMMA = YES; 297 | CLANG_WARN_CONSTANT_CONVERSION = YES; 298 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 299 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 300 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 301 | CLANG_WARN_EMPTY_BODY = YES; 302 | CLANG_WARN_ENUM_CONVERSION = YES; 303 | CLANG_WARN_INFINITE_RECURSION = YES; 304 | CLANG_WARN_INT_CONVERSION = YES; 305 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 306 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 307 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 308 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 309 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 310 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 311 | CLANG_WARN_STRICT_PROTOTYPES = YES; 312 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 313 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 314 | CLANG_WARN_UNREACHABLE_CODE = YES; 315 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 316 | COPY_PHASE_STRIP = NO; 317 | DEBUG_INFORMATION_FORMAT = dwarf; 318 | ENABLE_STRICT_OBJC_MSGSEND = YES; 319 | ENABLE_TESTABILITY = YES; 320 | GCC_C_LANGUAGE_STANDARD = gnu11; 321 | GCC_DYNAMIC_NO_PIC = NO; 322 | GCC_NO_COMMON_BLOCKS = YES; 323 | GCC_OPTIMIZATION_LEVEL = 0; 324 | GCC_PREPROCESSOR_DEFINITIONS = ( 325 | "DEBUG=1", 326 | "$(inherited)", 327 | ); 328 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 329 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 330 | GCC_WARN_UNDECLARED_SELECTOR = YES; 331 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 332 | GCC_WARN_UNUSED_FUNCTION = YES; 333 | GCC_WARN_UNUSED_VARIABLE = YES; 334 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 335 | MTL_FAST_MATH = YES; 336 | ONLY_ACTIVE_ARCH = YES; 337 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 338 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 339 | }; 340 | name = Debug; 341 | }; 342 | E1D53B08283685B20089FD3C /* Release */ = { 343 | isa = XCBuildConfiguration; 344 | buildSettings = { 345 | ALWAYS_SEARCH_USER_PATHS = NO; 346 | CLANG_ANALYZER_NONNULL = YES; 347 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 348 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 349 | CLANG_ENABLE_MODULES = YES; 350 | CLANG_ENABLE_OBJC_ARC = YES; 351 | CLANG_ENABLE_OBJC_WEAK = YES; 352 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 353 | CLANG_WARN_BOOL_CONVERSION = YES; 354 | CLANG_WARN_COMMA = YES; 355 | CLANG_WARN_CONSTANT_CONVERSION = YES; 356 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 357 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 358 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 359 | CLANG_WARN_EMPTY_BODY = YES; 360 | CLANG_WARN_ENUM_CONVERSION = YES; 361 | CLANG_WARN_INFINITE_RECURSION = YES; 362 | CLANG_WARN_INT_CONVERSION = YES; 363 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 364 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 365 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 366 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 367 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 368 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 369 | CLANG_WARN_STRICT_PROTOTYPES = YES; 370 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 371 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 372 | CLANG_WARN_UNREACHABLE_CODE = YES; 373 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 374 | COPY_PHASE_STRIP = NO; 375 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 376 | ENABLE_NS_ASSERTIONS = NO; 377 | ENABLE_STRICT_OBJC_MSGSEND = YES; 378 | GCC_C_LANGUAGE_STANDARD = gnu11; 379 | GCC_NO_COMMON_BLOCKS = YES; 380 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 381 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 382 | GCC_WARN_UNDECLARED_SELECTOR = YES; 383 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 384 | GCC_WARN_UNUSED_FUNCTION = YES; 385 | GCC_WARN_UNUSED_VARIABLE = YES; 386 | MTL_ENABLE_DEBUG_INFO = NO; 387 | MTL_FAST_MATH = YES; 388 | SWIFT_COMPILATION_MODE = wholemodule; 389 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 390 | }; 391 | name = Release; 392 | }; 393 | E1D53B0A283685B20089FD3C /* Debug */ = { 394 | isa = XCBuildConfiguration; 395 | buildSettings = { 396 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 397 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 398 | CODE_SIGN_STYLE = Automatic; 399 | CURRENT_PROJECT_VERSION = 1; 400 | DEVELOPMENT_TEAM = R38K25C8UB; 401 | ENABLE_PREVIEWS = YES; 402 | GENERATE_INFOPLIST_FILE = YES; 403 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 404 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 405 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 406 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 407 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 408 | IPHONEOS_DEPLOYMENT_TARGET = 15.4; 409 | LD_RUNPATH_SEARCH_PATHS = ( 410 | "$(inherited)", 411 | "@executable_path/Frameworks", 412 | ); 413 | MARKETING_VERSION = 1.0; 414 | PRODUCT_BUNDLE_IDENTIFIER = com.ozhayta.HabitTracker; 415 | PRODUCT_NAME = HabitTracker; 416 | SDKROOT = iphoneos; 417 | SWIFT_EMIT_LOC_STRINGS = YES; 418 | SWIFT_VERSION = 5.0; 419 | TARGETED_DEVICE_FAMILY = "1,2"; 420 | }; 421 | name = Debug; 422 | }; 423 | E1D53B0B283685B20089FD3C /* Release */ = { 424 | isa = XCBuildConfiguration; 425 | buildSettings = { 426 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 427 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 428 | CODE_SIGN_STYLE = Automatic; 429 | CURRENT_PROJECT_VERSION = 1; 430 | DEVELOPMENT_TEAM = R38K25C8UB; 431 | ENABLE_PREVIEWS = YES; 432 | GENERATE_INFOPLIST_FILE = YES; 433 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 434 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 435 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 436 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 437 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 438 | IPHONEOS_DEPLOYMENT_TARGET = 15.4; 439 | LD_RUNPATH_SEARCH_PATHS = ( 440 | "$(inherited)", 441 | "@executable_path/Frameworks", 442 | ); 443 | MARKETING_VERSION = 1.0; 444 | PRODUCT_BUNDLE_IDENTIFIER = com.ozhayta.HabitTracker; 445 | PRODUCT_NAME = HabitTracker; 446 | SDKROOT = iphoneos; 447 | SWIFT_EMIT_LOC_STRINGS = YES; 448 | SWIFT_VERSION = 5.0; 449 | TARGETED_DEVICE_FAMILY = "1,2"; 450 | VALIDATE_PRODUCT = YES; 451 | }; 452 | name = Release; 453 | }; 454 | /* End XCBuildConfiguration section */ 455 | 456 | /* Begin XCConfigurationList section */ 457 | E1D53AE8283685AF0089FD3C /* Build configuration list for PBXProject "HabitTracker" */ = { 458 | isa = XCConfigurationList; 459 | buildConfigurations = ( 460 | E1D53B07283685B20089FD3C /* Debug */, 461 | E1D53B08283685B20089FD3C /* Release */, 462 | ); 463 | defaultConfigurationIsVisible = 0; 464 | defaultConfigurationName = Release; 465 | }; 466 | E1D53B09283685B20089FD3C /* Build configuration list for PBXNativeTarget "HabitTracker" */ = { 467 | isa = XCConfigurationList; 468 | buildConfigurations = ( 469 | E1D53B0A283685B20089FD3C /* Debug */, 470 | E1D53B0B283685B20089FD3C /* Release */, 471 | ); 472 | defaultConfigurationIsVisible = 0; 473 | defaultConfigurationName = Release; 474 | }; 475 | /* End XCConfigurationList section */ 476 | 477 | /* Begin XCVersionGroup section */ 478 | E1D53AEA283685AF0089FD3C /* HabitTracker.xcdatamodeld */ = { 479 | isa = XCVersionGroup; 480 | children = ( 481 | E1D53AEB283685AF0089FD3C /* Shared.xcdatamodel */, 482 | ); 483 | currentVersion = E1D53AEB283685AF0089FD3C /* Shared.xcdatamodel */; 484 | path = HabitTracker.xcdatamodeld; 485 | sourceTree = ""; 486 | versionGroupType = wrapper.xcdatamodel; 487 | }; 488 | /* End XCVersionGroup section */ 489 | }; 490 | rootObject = E1D53AE5283685AF0089FD3C /* Project object */; 491 | } 492 | -------------------------------------------------------------------------------- /HabitTracker.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /HabitTracker.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /HabitTracker.xcodeproj/xcuserdata/AliMert.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | HabitTracker.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | E1D53AF3283685B20089FD3C 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /HabitTracker/App/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // Shared 4 | // 5 | // Created by Ali Mert Özhayta on 19.05.2022. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct ContentView: View { 11 | 12 | var body: some View { 13 | HabitsView() 14 | } 15 | } 16 | 17 | struct ContentView_Previews: PreviewProvider { 18 | static var previews: some View { 19 | ContentView() 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /HabitTracker/App/HabitTrackerApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HabitTrackerApp.swift 3 | // Shared 4 | // 5 | // Created by Ali Mert Özhayta on 19.05.2022. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @main 11 | struct HabitTrackerApp: App { 12 | 13 | var body: some Scene { 14 | WindowGroup { 15 | ContentView() 16 | .environment(\.managedObjectContext, CoreDataHabitManager.context) 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Icon-App-20x20@2x.png", 5 | "idiom" : "iphone", 6 | "scale" : "2x", 7 | "size" : "20x20" 8 | }, 9 | { 10 | "filename" : "Icon-App-20x20@3x.png", 11 | "idiom" : "iphone", 12 | "scale" : "3x", 13 | "size" : "20x20" 14 | }, 15 | { 16 | "filename" : "Icon-App-29x29@1x.png", 17 | "idiom" : "iphone", 18 | "scale" : "1x", 19 | "size" : "29x29" 20 | }, 21 | { 22 | "filename" : "Icon-App-29x29@2x.png", 23 | "idiom" : "iphone", 24 | "scale" : "2x", 25 | "size" : "29x29" 26 | }, 27 | { 28 | "filename" : "Icon-App-29x29@3x.png", 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "29x29" 32 | }, 33 | { 34 | "filename" : "Icon-App-40x40@2x.png", 35 | "idiom" : "iphone", 36 | "scale" : "2x", 37 | "size" : "40x40" 38 | }, 39 | { 40 | "filename" : "Icon-App-40x40@3x.png", 41 | "idiom" : "iphone", 42 | "scale" : "3x", 43 | "size" : "40x40" 44 | }, 45 | { 46 | "filename" : "Icon-App-60x60@2x.png", 47 | "idiom" : "iphone", 48 | "scale" : "2x", 49 | "size" : "60x60" 50 | }, 51 | { 52 | "filename" : "Icon-App-60x60@3x.png", 53 | "idiom" : "iphone", 54 | "scale" : "3x", 55 | "size" : "60x60" 56 | }, 57 | { 58 | "filename" : "Icon-App-20x20@1x.png", 59 | "idiom" : "ipad", 60 | "scale" : "1x", 61 | "size" : "20x20" 62 | }, 63 | { 64 | "filename" : "Icon-App-20x20@2x.png", 65 | "idiom" : "ipad", 66 | "scale" : "2x", 67 | "size" : "20x20" 68 | }, 69 | { 70 | "filename" : "Icon-App-29x29@1x.png", 71 | "idiom" : "ipad", 72 | "scale" : "1x", 73 | "size" : "29x29" 74 | }, 75 | { 76 | "filename" : "Icon-App-29x29@2x.png", 77 | "idiom" : "ipad", 78 | "scale" : "2x", 79 | "size" : "29x29" 80 | }, 81 | { 82 | "filename" : "Icon-App-40x40@1x.png", 83 | "idiom" : "ipad", 84 | "scale" : "1x", 85 | "size" : "40x40" 86 | }, 87 | { 88 | "filename" : "Icon-App-40x40@2x.png", 89 | "idiom" : "ipad", 90 | "scale" : "2x", 91 | "size" : "40x40" 92 | }, 93 | { 94 | "filename" : "Icon-App-76x76@1x.png", 95 | "idiom" : "ipad", 96 | "scale" : "1x", 97 | "size" : "76x76" 98 | }, 99 | { 100 | "filename" : "Icon-App-76x76@2x.png", 101 | "idiom" : "ipad", 102 | "scale" : "2x", 103 | "size" : "76x76" 104 | }, 105 | { 106 | "filename" : "Icon-App-83.5x83.5@2x.png", 107 | "idiom" : "ipad", 108 | "scale" : "2x", 109 | "size" : "83.5x83.5" 110 | }, 111 | { 112 | "filename" : "ItunesArtwork@2x.png", 113 | "idiom" : "ios-marketing", 114 | "scale" : "1x", 115 | "size" : "1024x1024" 116 | } 117 | ], 118 | "info" : { 119 | "author" : "xcode", 120 | "version" : 1 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliMert/HabitTracker-SwiftUI/ef35c752399b4efa6a1857e94c65565dd73cb9b8/HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliMert/HabitTracker-SwiftUI/ef35c752399b4efa6a1857e94c65565dd73cb9b8/HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliMert/HabitTracker-SwiftUI/ef35c752399b4efa6a1857e94c65565dd73cb9b8/HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliMert/HabitTracker-SwiftUI/ef35c752399b4efa6a1857e94c65565dd73cb9b8/HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliMert/HabitTracker-SwiftUI/ef35c752399b4efa6a1857e94c65565dd73cb9b8/HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliMert/HabitTracker-SwiftUI/ef35c752399b4efa6a1857e94c65565dd73cb9b8/HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliMert/HabitTracker-SwiftUI/ef35c752399b4efa6a1857e94c65565dd73cb9b8/HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliMert/HabitTracker-SwiftUI/ef35c752399b4efa6a1857e94c65565dd73cb9b8/HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliMert/HabitTracker-SwiftUI/ef35c752399b4efa6a1857e94c65565dd73cb9b8/HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliMert/HabitTracker-SwiftUI/ef35c752399b4efa6a1857e94c65565dd73cb9b8/HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliMert/HabitTracker-SwiftUI/ef35c752399b4efa6a1857e94c65565dd73cb9b8/HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliMert/HabitTracker-SwiftUI/ef35c752399b4efa6a1857e94c65565dd73cb9b8/HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliMert/HabitTracker-SwiftUI/ef35c752399b4efa6a1857e94c65565dd73cb9b8/HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliMert/HabitTracker-SwiftUI/ef35c752399b4efa6a1857e94c65565dd73cb9b8/HabitTracker/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/AppIcon.appiconset/ItunesArtwork@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliMert/HabitTracker-SwiftUI/ef35c752399b4efa6a1857e94c65565dd73cb9b8/HabitTracker/Assets.xcassets/AppIcon.appiconset/ItunesArtwork@2x.png -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/Card Colors/Card-1.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "color" : { 5 | "color-space" : "srgb", 6 | "components" : { 7 | "alpha" : "1.000", 8 | "blue" : "0.404", 9 | "green" : "0.397", 10 | "red" : "0.942" 11 | } 12 | }, 13 | "idiom" : "universal" 14 | } 15 | ], 16 | "info" : { 17 | "author" : "xcode", 18 | "version" : 1 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/Card Colors/Card-2.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "color" : { 5 | "color-space" : "srgb", 6 | "components" : { 7 | "alpha" : "1.000", 8 | "blue" : "0.524", 9 | "green" : "0.946", 10 | "red" : "0.966" 11 | } 12 | }, 13 | "idiom" : "universal" 14 | } 15 | ], 16 | "info" : { 17 | "author" : "xcode", 18 | "version" : 1 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/Card Colors/Card-3.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "color" : { 5 | "color-space" : "srgb", 6 | "components" : { 7 | "alpha" : "1.000", 8 | "blue" : "0.466", 9 | "green" : "0.786", 10 | "red" : "0.180" 11 | } 12 | }, 13 | "idiom" : "universal" 14 | } 15 | ], 16 | "info" : { 17 | "author" : "xcode", 18 | "version" : 1 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/Card Colors/Card-4.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "color" : { 5 | "color-space" : "srgb", 6 | "components" : { 7 | "alpha" : "1.000", 8 | "blue" : "0.952", 9 | "green" : "0.399", 10 | "red" : "0.337" 11 | } 12 | }, 13 | "idiom" : "universal" 14 | } 15 | ], 16 | "info" : { 17 | "author" : "xcode", 18 | "version" : 1 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/Card Colors/Card-5.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "color" : { 5 | "color-space" : "srgb", 6 | "components" : { 7 | "alpha" : "1.000", 8 | "blue" : "0.966", 9 | "green" : "0.526", 10 | "red" : "0.570" 11 | } 12 | }, 13 | "idiom" : "universal" 14 | } 15 | ], 16 | "info" : { 17 | "author" : "xcode", 18 | "version" : 1 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/Card Colors/Card-6.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "color" : { 5 | "color-space" : "srgb", 6 | "components" : { 7 | "alpha" : "1.000", 8 | "blue" : "0.445", 9 | "green" : "0.559", 10 | "red" : "0.686" 11 | } 12 | }, 13 | "idiom" : "universal" 14 | } 15 | ], 16 | "info" : { 17 | "author" : "xcode", 18 | "version" : 1 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/Card Colors/Card-7.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "color" : { 5 | "color-space" : "srgb", 6 | "components" : { 7 | "alpha" : "1.000", 8 | "blue" : "0.633", 9 | "green" : "0.633", 10 | "red" : "0.633" 11 | } 12 | }, 13 | "idiom" : "universal" 14 | } 15 | ], 16 | "info" : { 17 | "author" : "xcode", 18 | "version" : 1 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/Card Colors/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /HabitTracker/Assets.xcassets/TFBG.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "color" : { 5 | "color-space" : "srgb", 6 | "components" : { 7 | "alpha" : "0.102", 8 | "blue" : "0.205", 9 | "green" : "0.205", 10 | "red" : "0.204" 11 | } 12 | }, 13 | "idiom" : "universal" 14 | }, 15 | { 16 | "appearances" : [ 17 | { 18 | "appearance" : "luminosity", 19 | "value" : "dark" 20 | } 21 | ], 22 | "color" : { 23 | "color-space" : "srgb", 24 | "components" : { 25 | "alpha" : "1.000", 26 | "blue" : "0.205", 27 | "green" : "0.205", 28 | "red" : "0.204" 29 | } 30 | }, 31 | "idiom" : "universal" 32 | } 33 | ], 34 | "info" : { 35 | "author" : "xcode", 36 | "version" : 1 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /HabitTracker/Common/Extensions/View+Extensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // View+Extensions.swift 3 | // HabitTracker 4 | // 5 | // Created by Ali Mert Özhayta on 19.05.2022. 6 | // 7 | 8 | import SwiftUI 9 | 10 | // MARK: - Constraints 11 | 12 | public extension View { 13 | 14 | // MARK: Vertical Center 15 | func vCenter() -> some View { 16 | self 17 | .frame(maxHeight: . infinity, alignment: .center) 18 | } 19 | 20 | // MARK: Vertical Top 21 | func vTop() -> some View { 22 | self 23 | .frame(maxHeight: . infinity, alignment: .top) 24 | } 25 | // MARK: Vertical Bottom 26 | func vBottom() -> some View { 27 | self 28 | .frame(maxHeight: . infinity, alignment: .bottom) 29 | } 30 | 31 | // MARK: Horizontal Center 32 | func hCenter() -> some View { 33 | self 34 | .frame(maxWidth: . infinity, alignment: .center) 35 | } 36 | 37 | // MARK: Horizontal Leading 38 | func hLeading() -> some View { 39 | self 40 | .frame(maxWidth: . infinity, alignment: .leading) 41 | } 42 | 43 | // MARK: Horizontal Trailing 44 | func hTrailing() -> some View { 45 | self 46 | .frame(maxWidth: . infinity, alignment: .trailing) 47 | } 48 | 49 | // MARK: Max Width 50 | func maxWidth() -> some View { 51 | self 52 | .frame(maxWidth: . infinity) 53 | } 54 | 55 | // MARK: Max Height 56 | func maxHeight() -> some View { 57 | self 58 | .frame(maxHeight: . infinity) 59 | } 60 | } 61 | 62 | //MARK: - add corner radius to desired corners 63 | 64 | public extension View { 65 | 66 | func cornerRadius(_ radius: CGFloat, corners: UIRectCorner = .allCorners) -> some View { 67 | clipShape(RoundedCorner(radius: radius, corners: corners)) 68 | } 69 | } 70 | 71 | //MARK: - Swipe right to Delete an Item 72 | 73 | public extension View { 74 | 75 | func onDelete(style: Delete.CornerRadiusStyle? = nil, perform action: @escaping () -> Void) -> some View { 76 | self.modifier(Delete(action: action, cornerRadiusStyle: style)) 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /HabitTracker/Common/ViewModifiers/Delete.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Delete.swift 3 | // HabitTracker 4 | // 5 | // Created by Ali Mert Özhayta on 22.05.2022. 6 | // 7 | 8 | import SwiftUI 9 | 10 | public struct Delete: ViewModifier { 11 | public struct CornerRadiusStyle { 12 | let radius: CGFloat 13 | let corners: UIRectCorner 14 | } 15 | 16 | //MARK: Constants 17 | 18 | private let deletionDistance = CGFloat(200) 19 | private let halfDeletionDistance = CGFloat(50) 20 | private let tappableDeletionWidth = CGFloat(100) 21 | 22 | //MARK: Properties 23 | 24 | private let action: () -> Void 25 | private let cornerRadiusStyle: CornerRadiusStyle? 26 | 27 | @State private var offset: CGSize = .zero 28 | @State private var initialOffset: CGSize = .zero 29 | @State private var contentWidth: CGFloat = 0.0 30 | @State private var willDeleteIfReleased = false 31 | 32 | //MARK: Init 33 | 34 | init(action: @escaping () -> Void, cornerRadiusStyle: CornerRadiusStyle? = nil) { 35 | self.action = action 36 | self.cornerRadiusStyle = cornerRadiusStyle 37 | } 38 | 39 | //MARK: UI 40 | 41 | public func body(content: Content) -> some View { 42 | content 43 | .background( 44 | GeometryReader { geometry in 45 | ZStack { 46 | Rectangle() 47 | .foregroundColor(.red) 48 | .cornerRadius(cornerRadiusStyle?.radius ?? .zero, corners: cornerRadiusStyle?.corners ?? []) 49 | 50 | Image(systemName: "trash") 51 | .foregroundColor(.white) 52 | .font(.title2.bold()) 53 | .layoutPriority(-1) 54 | .opacity(offset.width < -10 ? 1 : 0) 55 | }.frame(width: -offset.width) 56 | .offset(x: geometry.size.width) 57 | .onAppear { 58 | contentWidth = geometry.size.width 59 | } 60 | .gesture( 61 | TapGesture() 62 | .onEnded { 63 | delete() 64 | } 65 | ) 66 | } 67 | ) 68 | .offset(x: offset.width, y: 0) 69 | .gesture ( 70 | DragGesture() 71 | .onChanged { gesture in 72 | if gesture.translation.width + initialOffset.width <= 0 { 73 | self.offset.width = gesture.translation.width + initialOffset.width 74 | } 75 | if self.offset.width < -deletionDistance && !willDeleteIfReleased { 76 | hapticFeedback() 77 | willDeleteIfReleased.toggle() 78 | } else if offset.width > -deletionDistance && willDeleteIfReleased { 79 | hapticFeedback() 80 | willDeleteIfReleased.toggle() 81 | } 82 | } 83 | .onEnded { _ in 84 | if offset.width < -deletionDistance { 85 | delete() 86 | } else if offset.width < -halfDeletionDistance { 87 | offset.width = -tappableDeletionWidth 88 | initialOffset.width = -tappableDeletionWidth 89 | } else { 90 | offset = .zero 91 | initialOffset = .zero 92 | } 93 | } 94 | ) 95 | .animation(.interactiveSpring(), value: offset) 96 | } 97 | 98 | //MARK: Methods 99 | 100 | private func delete() { 101 | offset.width = -contentWidth 102 | action() 103 | } 104 | 105 | private func hapticFeedback() { 106 | let generator = UIImpactFeedbackGenerator(style: .medium) 107 | generator.impactOccurred() 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /HabitTracker/Common/Views/DynamicFilteredView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DynamicFilteredView.swift 3 | // HabitTracker 4 | // 5 | // Created by Ali Mert Özhayta on 19.05.2022. 6 | // 7 | 8 | import SwiftUI 9 | import CoreData 10 | 11 | struct DynamicFilteredView: View where T: NSManagedObject { 12 | // MARK: Core Data Request 13 | @FetchRequest private var request: FetchedResults 14 | private let content: (T)->Content 15 | private let emptyView: (()->EContent)? 16 | 17 | // MARK: Building Custom ForEach which will give Coredata object to build View 18 | init( 19 | entity: NSEntityDescription = T.entity(), 20 | sortDescriptors: [NSSortDescriptor] = [], 21 | predicate: NSPredicate? = nil, 22 | animation: Animation? = nil, 23 | emptyView: (() ->EContent)? = nil, 24 | @ViewBuilder content: @escaping (T)->Content 25 | ) { 26 | // Intializing Request With NSPredicate 27 | // Adding Sort 28 | _request = FetchRequest( 29 | entity: entity, 30 | sortDescriptors: sortDescriptors, 31 | predicate: predicate, 32 | animation: animation 33 | ) 34 | 35 | self.content = content 36 | self.emptyView = emptyView 37 | } 38 | 39 | init( 40 | fetchRequest: FetchRequest, 41 | emptyView: (() ->EContent)? = nil, 42 | @ViewBuilder content: @escaping (T)->Content 43 | ) { 44 | _request = fetchRequest 45 | self.content = content 46 | self.emptyView = emptyView 47 | } 48 | 49 | var body: some View { 50 | Group{ 51 | if request.isEmpty { 52 | if let emptyView = emptyView { 53 | emptyView() 54 | } else { 55 | Text("No data found!!!") 56 | .font(.system(size: 16)) 57 | .fontWeight(.light) 58 | .offset(y: 100) 59 | } 60 | } else{ 61 | ForEach(request, id: \.objectID) { object in 62 | content(object) 63 | } 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /HabitTracker/Common/Views/RoundedCorner.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RoundedCorner.swift 3 | // HabitTracker 4 | // 5 | // Created by Ali Mert Özhayta on 22.05.2022. 6 | // 7 | 8 | import SwiftUI 9 | 10 | public struct RoundedCorner: Shape { 11 | 12 | var radius: CGFloat = .infinity 13 | var corners: UIRectCorner = .allCorners 14 | 15 | public func path(in rect: CGRect) -> Path { 16 | let path = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)) 17 | return Path(path.cgPath) 18 | } 19 | } 20 | 21 | 22 | -------------------------------------------------------------------------------- /HabitTracker/CoreData/CoreDataHabitManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CoreDataHabitManager.swift 3 | // HabitTracker 4 | // 5 | // Created by Ali Mert Özhayta on 19.05.2022. 6 | // 7 | 8 | import CoreData 9 | 10 | struct CoreDataHabitManager { 11 | static let shared = CoreDataHabitManager() 12 | 13 | let container: NSPersistentContainer 14 | 15 | static var context: NSManagedObjectContext { 16 | shared.container.viewContext 17 | } 18 | 19 | static var preview: CoreDataHabitManager = { 20 | let result = CoreDataHabitManager(inMemory: true) 21 | let viewContext = result.container.viewContext 22 | for i in 1..<5 { 23 | let habit = Habit(context: viewContext) 24 | habit.rowID = Int64(i) 25 | habit.color = "Card-\(i)" 26 | habit.title = "Workout-\(i)" 27 | var weekdays = [String]() 28 | 29 | for randomDayCount in 0...Int.random(in: 0..<7) { 30 | let day = Calendar.current.weekdaySymbols.randomElement() 31 | ?? Calendar.current.weekdaySymbols[randomDayCount] 32 | weekdays.append(day) 33 | } 34 | habit.weekdays = weekdays 35 | } 36 | do { 37 | try viewContext.save() 38 | } catch { 39 | // Replace this implementation with code to handle the error appropriately. 40 | // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 41 | let nsError = error as NSError 42 | fatalError("Unresolved error \(nsError), \(nsError.userInfo)") 43 | } 44 | return result 45 | }() 46 | 47 | 48 | init(inMemory: Bool = false) { 49 | container = NSPersistentContainer(name: "HabitTracker") 50 | if inMemory { 51 | container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null") 52 | } 53 | container.loadPersistentStores(completionHandler: { (storeDescription, error) in 54 | if let error = error as NSError? { 55 | // Replace this implementation with code to handle the error appropriately. 56 | // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 57 | 58 | /* 59 | Typical reasons for an error here include: 60 | * The parent directory does not exist, cannot be created, or disallows writing. 61 | * The persistent store is not accessible, due to permissions or data protection when the device is locked. 62 | * The device is out of space. 63 | * The store could not be migrated to the current model version. 64 | Check the error message to determine what the actual problem was. 65 | */ 66 | fatalError("Unresolved error \(error), \(error.userInfo)") 67 | } 68 | }) 69 | container.viewContext.automaticallyMergesChangesFromParent = true 70 | } 71 | 72 | @discardableResult 73 | static func delete(_ object: NSManagedObject, from context: NSManagedObjectContext) -> Bool { 74 | context.delete(object) 75 | return CoreDataHabitManager.save(to: context) 76 | } 77 | 78 | @discardableResult 79 | static func save(to context: NSManagedObjectContext) -> Bool { 80 | do { 81 | try context.save() 82 | return true 83 | } catch let error { 84 | print(error) 85 | return false 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /HabitTracker/CoreData/HabitTracker.xcdatamodeld/.xccurrentversion: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | _XCCurrentVersionName 6 | Shared.xcdatamodel 7 | 8 | 9 | -------------------------------------------------------------------------------- /HabitTracker/CoreData/HabitTracker.xcdatamodeld/Shared.xcdatamodel/contents: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /HabitTracker/Modules/AddHabit/View/AddHabitView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AddHabitView.swift 3 | // HabitTracker 4 | // 5 | // Created by Ali Mert Özhayta on 19.05.2022. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct AddHabitView: View { 11 | @StateObject private var viewModel: AddHabitViewModel 12 | @Environment(\.self) private var env 13 | 14 | init(editHabit: Habit? = nil) { 15 | _viewModel = StateObject(wrappedValue: AddHabitViewModel(editHabit: editHabit)) 16 | } 17 | 18 | var body: some View { 19 | NavigationView { 20 | VStack(spacing: 15) { 21 | 22 | // MARK: TextField - Title 23 | TextField("Title", text: $viewModel.title) 24 | .padding(.horizontal) 25 | .padding(.vertical, 10) 26 | .background(Color("TFBG").opacity(0.4), in: RoundedRectangle(cornerRadius: 6, style: .continuous)) 27 | 28 | // MARK: Habit Color Picker 29 | HStack(spacing: 0) { 30 | ForEach(1...7, id: \.self) { index in 31 | let color = "Card-\(index)" 32 | Circle() 33 | .fill(Color(color)) 34 | .frame(width: 30, height: 30) 35 | .maxWidth() 36 | .overlay { 37 | if color == viewModel.habitColor { 38 | Image(systemName: "checkmark") 39 | .font(.caption.bold()) 40 | .foregroundColor(.white) 41 | .shadow(color: .black, radius: 0.5, x: 0.5, y: 0.5) 42 | } 43 | } 44 | .onTapGesture { 45 | withAnimation { 46 | viewModel.habitColor = color 47 | } 48 | } 49 | } 50 | } 51 | .padding(.vertical) 52 | 53 | Divider() 54 | 55 | // MARK: Frequency Selection (weekdays) 56 | VStack(alignment: .leading, spacing: 6) { 57 | Text("Frequency") 58 | HStack(spacing: 10) { 59 | let weekdays = Calendar.current.weekdaySymbols 60 | ForEach(weekdays, id: \.self) { day in 61 | let index = viewModel.weekdays.firstIndex(where: { $0 == day }) 62 | // MARK: Limiting to First 2 Letters 63 | Text(day.prefix(3)) 64 | .font(.callout) 65 | .fontWeight(.semibold) 66 | .lineLimit(1) 67 | .maxWidth() 68 | .padding(.vertical, 12) 69 | .padding(.horizontal, 3) 70 | .background { 71 | let color = index == nil ? Color("TFBG") : Color(viewModel.habitColor) 72 | RoundedRectangle(cornerRadius: 10, style: .continuous) 73 | .fill(color.opacity(0.4)) 74 | } 75 | .onTapGesture { 76 | withAnimation { 77 | if let index = index { 78 | viewModel.weekdays.remove(at: index) 79 | } else { 80 | viewModel.weekdays.append(day) 81 | } 82 | } 83 | } 84 | } 85 | } 86 | .padding(.vertical, 15) 87 | } 88 | .padding(.vertical, 10) 89 | 90 | if viewModel.notificationAccess { 91 | Divider() 92 | 93 | // MARK: Reminder Toggle 94 | // Hiding If Notification access is rejected 95 | HStack { 96 | VStack(alignment: .leading, spacing: 6) { 97 | Text("Reminder") 98 | .fontWeight(.semibold) 99 | 100 | Text("Just notification") 101 | .font(.caption) 102 | .foregroundColor(.gray) 103 | } 104 | .frame(maxWidth: .infinity, alignment: .leading) 105 | 106 | Toggle(isOn: $viewModel.isReminderOn, label: {}) 107 | .labelsHidden() 108 | } 109 | 110 | // MARK: Reminder Date and TextField 111 | // Hiding If Notification access is rejected 112 | HStack(spacing: 12) { 113 | Label { 114 | Text(viewModel.reminderDate.formatted(date: .omitted, time: .shortened)) 115 | } icon: { 116 | Image(systemName: "clock") 117 | } 118 | .padding(.horizontal) 119 | .padding(.vertical, 12) 120 | .background { 121 | RoundedRectangle(cornerRadius: 10, style: .continuous) 122 | .fill(Color("TFBG").opacity(0.4)) 123 | } 124 | .onTapGesture { 125 | withAnimation { 126 | viewModel.showTimePicker.toggle() 127 | } 128 | } 129 | 130 | TextField("Reminder Text...", text: $viewModel.reminderText) 131 | .padding(.horizontal) 132 | .padding(.vertical, 10) 133 | .background { 134 | RoundedRectangle(cornerRadius: 10, style: .continuous) 135 | .fill(Color("TFBG").opacity(0.4)) 136 | } 137 | } 138 | .animation(.easeInOut, value: viewModel.isReminderOn) 139 | .frame(height: viewModel.isReminderOn ? nil : 0) 140 | .opacity(viewModel.isReminderOn ? 1 : 0) 141 | } 142 | 143 | } 144 | .padding() 145 | .frame(maxHeight: .infinity, alignment: .top) 146 | .navigationBarTitleDisplayMode(.inline) 147 | .navigationTitle(viewModel.editHabit != nil ? "Update Habit" : "Add Habit") 148 | .toolbar { 149 | ToolbarItem(placement: .navigationBarLeading) { 150 | Button { 151 | env.dismiss() 152 | } label: { 153 | Image(systemName: "xmark.circle") 154 | } 155 | .tint(.init(.label)) 156 | } 157 | 158 | ToolbarItem(placement: .navigationBarTrailing) { 159 | Button("Done") { 160 | if viewModel.upsertHabbit(context: env.managedObjectContext) { 161 | env.dismiss() 162 | } 163 | } 164 | .tint(.init(.label)) 165 | .disabled(!viewModel.doneStatus()) 166 | .opacity(viewModel.doneStatus() ? 1 : 0.6) 167 | } 168 | } 169 | } 170 | .overlay { 171 | if viewModel.showTimePicker { 172 | ZStack { 173 | Rectangle() 174 | .fill(.ultraThinMaterial) 175 | .ignoresSafeArea() 176 | .onTapGesture { 177 | withAnimation { 178 | viewModel.showTimePicker.toggle() 179 | } 180 | } 181 | 182 | DatePicker("", selection: $viewModel.reminderDate, displayedComponents: .hourAndMinute) 183 | .datePickerStyle(.wheel) 184 | .labelsHidden() 185 | .padding() 186 | .background { 187 | RoundedRectangle(cornerRadius: 10) 188 | .fill(Color("TFBG")) 189 | } 190 | .padding() 191 | } 192 | } 193 | } 194 | } 195 | } 196 | 197 | struct AddHabitView_Previews: PreviewProvider { 198 | static var previews: some View { 199 | AddHabitView() 200 | .preferredColorScheme(.dark) 201 | .environment(\.managedObjectContext, CoreDataHabitManager.preview.container.viewContext) 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /HabitTracker/Modules/AddHabit/ViewModel/AddHabitViewModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AddHabitViewModel.swift 3 | // HabitTracker 4 | // 5 | // Created by Ali Mert Özhayta on 19.05.2022. 6 | // 7 | import SwiftUI 8 | import CoreData 9 | import UserNotifications 10 | 11 | final class AddHabitViewModel: ObservableObject { 12 | 13 | // MARK: Habit Properties 14 | 15 | @Published var title: String 16 | @Published var habitColor: String 17 | @Published var weekdays: [String] 18 | @Published var isReminderOn: Bool 19 | @Published var reminderText: String 20 | @Published var reminderDate: Date 21 | 22 | // MARK: Reminder Time Picker 23 | @Published var showTimePicker: Bool = false 24 | 25 | // MARK: Editing Habit 26 | @Published var editHabit: Habit? 27 | 28 | // MARK: Notification Access Status 29 | @Published var notificationAccess: Bool = false 30 | 31 | // MARK: Init 32 | init(editHabit: Habit? = nil) { 33 | self.editHabit = editHabit 34 | self.title = editHabit?.title ?? "" 35 | self.habitColor = editHabit?.color ?? "Card-1" 36 | self.weekdays = editHabit?.weekdays ?? [] 37 | self.isReminderOn = editHabit?.isReminderOn ?? false 38 | self.reminderText = editHabit?.reminderText ?? "" 39 | self.reminderDate = editHabit?.notificationDate ?? Date() 40 | 41 | requestNotificationAccess() 42 | } 43 | 44 | 45 | // MARK: Done Button Status 46 | func doneStatus() -> Bool { 47 | let reminderStatus = isReminderOn ? reminderText == "" : false 48 | 49 | if title == "" || weekdays.isEmpty || reminderStatus { 50 | return false 51 | } 52 | return true 53 | } 54 | 55 | func requestNotificationAccess() { 56 | UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound]) { [weak self] (status, _) in 57 | DispatchQueue.main.async { 58 | self?.notificationAccess = status 59 | } 60 | } 61 | } 62 | 63 | private func getCurrentRowId() -> Int64? { 64 | let request = Habit.fetchRequest() 65 | // filter the maximum rowID 66 | request.predicate = NSPredicate(format: "rowID==max(rowID)") 67 | request.fetchLimit = 1 68 | 69 | do { 70 | let habits = try CoreDataHabitManager.context.fetch(request) 71 | if let id = habits.first?.rowID { 72 | return id + 1 73 | } else { 74 | return 1 75 | } 76 | } catch { 77 | print(error.localizedDescription) 78 | } 79 | 80 | return nil 81 | } 82 | 83 | // MARK: Inserting/Updating Habit to Database 84 | func upsertHabbit(context: NSManagedObjectContext) -> Bool { 85 | guard let rowID = getCurrentRowId() else { 86 | return false 87 | } 88 | 89 | let habit = editHabit ?? Habit(context: context) 90 | habit.title = title 91 | habit.color = habitColor 92 | habit.weekdays = weekdays 93 | habit.isReminderOn = isReminderOn 94 | habit.reminderText = reminderText 95 | habit.notificationDate = reminderDate 96 | habit.dateAdded = editHabit?.dateAdded ?? Date() 97 | habit.dateUpdated = Date() 98 | habit.notificationIDs = editHabit?.notificationIDs ?? [] 99 | habit.rowID = editHabit?.rowID ?? rowID 100 | 101 | if let notificationIDs = editHabit?.notificationIDs, 102 | !notificationIDs.isEmpty { 103 | UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: notificationIDs) 104 | } 105 | 106 | if isReminderOn { 107 | // MARK: Scheduling Notifications 108 | let notificationIDs = scheduleNotificationAndGetIDs() 109 | habit.notificationIDs = notificationIDs 110 | 111 | if CoreDataHabitManager.save(to: context) { 112 | return true 113 | } else { 114 | UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: notificationIDs) 115 | return false 116 | } 117 | } 118 | 119 | return CoreDataHabitManager.save(to: context) 120 | } 121 | 122 | // MARK: Adding Notifications 123 | private func scheduleNotificationAndGetIDs() -> [String] { 124 | let notificationContent = UNMutableNotificationContent() 125 | notificationContent.title = "Habit Tracker" 126 | notificationContent.subtitle = reminderText 127 | notificationContent.sound = UNNotificationSound.default 128 | 129 | // Scheduled Ids 130 | var notificationIDs: [String] = [] 131 | let calendar = Calendar.current 132 | let weekdaySymbols: [String] = calendar.weekdaySymbols 133 | 134 | // MARK: Scheduling Notification 135 | for day in weekdays { 136 | guard let index = weekdaySymbols.firstIndex(where: { $0 == day }) else { 137 | return notificationIDs 138 | } 139 | 140 | // UNIQUE ID FOR EACH NOTIFICATION 141 | let id = UUID().uuidString 142 | let hour = calendar.component(.hour, from: reminderDate) 143 | let min = calendar.component(.minute, from: reminderDate) 144 | 145 | // MARK: Since Week Day Starts from 1-7 146 | // Thus Adding +1 to Index 147 | var components = DateComponents() 148 | components.hour = hour 149 | components.minute = min 150 | components.weekday = index + 1 151 | 152 | // MARK: Trigger Notification on Each Selected Day 153 | let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: true) 154 | 155 | // MARK: Notification Request 156 | let request = UNNotificationRequest(identifier: id, content: notificationContent, trigger: trigger) 157 | 158 | // ADDING ID 159 | notificationIDs.append(id) 160 | 161 | UNUserNotificationCenter.current().add(request) 162 | } 163 | 164 | return notificationIDs 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /HabitTracker/Modules/Habits/Delegate/HabitDropDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HabitDropDelegate.swift 3 | // HabitTracker 4 | // 5 | // Created by Ali Mert Özhayta on 22.05.2022. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct HabitDropDelegate : DropDelegate { 11 | private let habit : Habit 12 | @Binding private var draggedHabit : Habit? 13 | 14 | init(draggedHabit: Binding, habit: Habit) { 15 | self.habit = habit 16 | self._draggedHabit = draggedHabit 17 | } 18 | 19 | func performDrop(info: DropInfo) -> Bool { 20 | return true 21 | } 22 | 23 | func dropEntered(info: DropInfo) { 24 | guard let draggedHabit = self.draggedHabit else { 25 | return 26 | } 27 | 28 | if draggedHabit != habit { 29 | let rowID = draggedHabit.rowID 30 | draggedHabit.rowID = habit.rowID 31 | habit.rowID = rowID 32 | CoreDataHabitManager.save(to: CoreDataHabitManager.context) 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /HabitTracker/Modules/Habits/View/HabitCardView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HabitCardView.swift 3 | // HabitTracker 4 | // 5 | // Created by Ali Mert Özhayta on 21.05.2022. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct HabitCardView: View { 11 | 12 | @Binding private var habit: Habit 13 | @State private var editHabit = false 14 | 15 | init(habit: Habit) { 16 | self._habit = .constant(habit) 17 | } 18 | 19 | var body: some View { 20 | VStack(spacing: 6) { 21 | HStack { 22 | Text(habit.title ?? "") 23 | .font(.callout) 24 | .fontWeight(.semibold) 25 | .lineLimit(1) 26 | 27 | Image(systemName: "bell.badge.fill") 28 | .font(.callout) 29 | .foregroundColor(Color(habit.color ?? "Card-1")) 30 | .scaleEffect(0.8) 31 | .offset(x: -3, y: -3) 32 | .shadow(color: .black, radius: 0.1, x: 0.1, y: -0.1) 33 | .opacity(habit.isReminderOn ? 1 : 0) 34 | 35 | Spacer() 36 | 37 | let count = habit.weekdays?.count ?? 0 38 | Text(count == 7 ? "Everyday" : "\(count) times a week") 39 | .font(.caption) 40 | .foregroundColor(.gray) 41 | } 42 | .padding(.horizontal, 10) 43 | 44 | // MARK: Displaying Current Week and Marking Active Dates of Habit 45 | let activePlot = getActivePlot() 46 | 47 | HStack { 48 | ForEach(activePlot.indices, id: \.self) { index in 49 | let item = activePlot[index] 50 | 51 | VStack(spacing: 6) { 52 | Text(item.dayName.prefix(3)) 53 | .font(.caption) 54 | .foregroundColor(.gray) 55 | 56 | let status = (habit.weekdays ?? []).contains { $0 == item.dayName } 57 | 58 | Text(formatDate(date: item.date)) 59 | .font(.system(size: 14)) 60 | .fontWeight(.semibold) 61 | .shadow(color: Color(.systemBackground), radius: 0.4, x: 0.3, y: 0.3) 62 | .padding(8) 63 | .background { 64 | Circle() 65 | .fill(Color(habit.color ?? "Card-1" )) 66 | .opacity(status ? 1 : 0) 67 | } 68 | } 69 | .maxWidth() 70 | } 71 | } 72 | .padding(.top, 15) 73 | } 74 | .padding() 75 | .background( Color("TFBG").opacity(0.35), in: RoundedRectangle(cornerRadius: 10, style: .continuous)) 76 | .padding(.horizontal) 77 | .frame(maxWidth: 600) 78 | .onTapGesture { 79 | editHabit.toggle() 80 | } 81 | .sheet(isPresented: $editHabit) { 82 | AddHabitView(editHabit: habit) 83 | } 84 | } 85 | 86 | private func getActivePlot() -> [(dayName: String, date: Date)] { 87 | let calendar = Calendar.current 88 | let currentWeek = calendar.dateInterval(of: .weekOfMonth, for: Date()) 89 | let weekdaySymbols = calendar.weekdaySymbols 90 | let startDate = currentWeek?.start ?? Date() 91 | 92 | return weekdaySymbols.indices.compactMap { index -> (String, Date)? in 93 | guard let currentDate = calendar.date(byAdding: .day, value: index, to: startDate) else { 94 | return nil 95 | } 96 | return (weekdaySymbols[index], currentDate) 97 | } 98 | } 99 | 100 | private func formatDate(date: Date) -> String { 101 | let formatter = DateFormatter() 102 | formatter.dateFormat = "dd" 103 | return formatter.string(from: date) 104 | } 105 | } 106 | 107 | struct HabitCardView_Previews: PreviewProvider { 108 | static let habit: Habit = { 109 | let habit = Habit(context: CoreDataHabitManager.context) 110 | habit.title = "Workout" 111 | return habit 112 | }() 113 | 114 | static var previews: some View { 115 | HabitCardView(habit: habit) 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /HabitTracker/Modules/Habits/View/HabitsView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HabitsView.swift 3 | // HabitTracker (iOS) 4 | // 5 | // Created by Ali Mert Özhayta on 19.05.2022. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct HabitsView: View { 11 | 12 | @State private var addNewHabit: Bool = false 13 | @State private var draggedHabit: Habit? 14 | @Environment(\.self) private var env 15 | 16 | @FetchRequest( 17 | sortDescriptors: [NSSortDescriptor(keyPath: \Habit.rowID, ascending: false)], 18 | animation: .interactiveSpring().speed(0.5) 19 | ) private var habits 20 | 21 | var body: some View { 22 | VStack(spacing: 0) { 23 | Text("Habits") 24 | .font(.title2.bold()) 25 | .maxWidth() 26 | .overlay(alignment: .trailing) { 27 | Button { 28 | 29 | } label: { 30 | Image(systemName: "gearshape") 31 | .font(.title3) 32 | .foregroundColor(Color(.label)) 33 | } 34 | .padding(.trailing) 35 | } 36 | .padding(.bottom) 37 | 38 | ScrollView(habits.isEmpty ? .init() : .vertical) { 39 | VStack(spacing: 15) { 40 | // MARK: HabitCardView 41 | DynamicFilteredView( 42 | fetchRequest: _habits, 43 | emptyView: { EmptyView() } 44 | ) { (habit: Habit) in 45 | HabitCardView(habit: habit) 46 | .onDelete(style: .init(radius: 10, corners: [.topRight, .bottomRight])) { 47 | CoreDataHabitManager.delete(habit, from: env.managedObjectContext) 48 | } 49 | .onDrag { 50 | draggedHabit = habit 51 | return NSItemProvider(item: nil, typeIdentifier: "\(habit.rowID)") 52 | } 53 | .onDrop(of: [.data], delegate: HabitDropDelegate(draggedHabit: $draggedHabit, habit: habit)) 54 | } 55 | 56 | // MARK: Add Habit Button 57 | VStack { 58 | Button { 59 | addNewHabit.toggle() 60 | } label: { 61 | Label { 62 | Text("New Habit") 63 | } icon: { 64 | Image(systemName: "plus.circle") 65 | } 66 | .font(.callout.bold()) 67 | .foregroundColor(.white) 68 | } 69 | .padding(.vertical, 10) 70 | .padding(.horizontal) 71 | .background { 72 | RoundedRectangle(cornerRadius: 10, style: .continuous) 73 | .fill(Color(.darkGray).opacity(env.colorScheme == .dark ? 1 : 0.6)) 74 | } 75 | } 76 | .padding(.top, 15) 77 | .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center) 78 | } 79 | .padding(.vertical) 80 | } 81 | } 82 | .padding(.bottom, 0.1) 83 | .frame(maxHeight: .infinity, alignment: .top) 84 | 85 | .sheet(isPresented: $addNewHabit) { 86 | AddHabitView() 87 | } 88 | } 89 | } 90 | 91 | struct HabitsView_Previews: PreviewProvider { 92 | static var previews: some View { 93 | HabitsView() 94 | .preferredColorScheme(.dark) 95 | .environment(\.managedObjectContext, CoreDataHabitManager.preview.container.viewContext) 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HabitTracker-SwiftUI 2 |
3 | In this SwiftUI project, you can create habits and add reminder to notify you.
4 |
5 | The following technologies/features are used: 6 | 7 | * MVVM design pattern, 8 | * Core Data, 9 | * NotificationCenter, 10 | * swipe to delete an item in VStack by using ViewModifier, 11 | * drag and drop to organize items in VStack and save the order to Core Data. 12 | 13 |
14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 27 | 30 | 31 | 32 | 35 | 38 | 39 | 40 | 45 | 46 | 47 | 54 | 55 |
Screenshots
25 | 26 | 28 | 29 |
33 | 34 | 36 | 37 |
41 |
42 | Demo 43 |
44 |
48 | 49 | 50 | https://user-images.githubusercontent.com/37440706/169711770-f62e94ba-ac1e-4b11-bcbc-6f4862da46fc.mp4 51 | 52 | 53 |
56 | -------------------------------------------------------------------------------- /screenshots/dark1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliMert/HabitTracker-SwiftUI/ef35c752399b4efa6a1857e94c65565dd73cb9b8/screenshots/dark1.png -------------------------------------------------------------------------------- /screenshots/dark2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliMert/HabitTracker-SwiftUI/ef35c752399b4efa6a1857e94c65565dd73cb9b8/screenshots/dark2.png -------------------------------------------------------------------------------- /screenshots/light1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliMert/HabitTracker-SwiftUI/ef35c752399b4efa6a1857e94c65565dd73cb9b8/screenshots/light1.png -------------------------------------------------------------------------------- /screenshots/light2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AliMert/HabitTracker-SwiftUI/ef35c752399b4efa6a1857e94c65565dd73cb9b8/screenshots/light2.png --------------------------------------------------------------------------------