From 9701c3428c215f04b891329ecacf482981dcc2c6 Mon Sep 17 00:00:00 2001 From: Louis Hollingworth Date: Sun, 21 May 2023 13:52:47 +0100 Subject: [PATCH] Removed not needed stuff from generation. Started adding a view for adding data. Signed-off-by: Louis Hollingworth --- Leganto.xcodeproj/project.pbxproj | 35 +++++++-- Leganto/AddFeed.swift | 30 +++++++ Leganto/ContentView.swift | 78 +++---------------- Leganto/DataController.swift | 21 +++++ .../Leganto.xcdatamodel/contents | 15 ++-- Leganto/LegantoApp.swift | 4 +- Leganto/Persistence.swift | 56 ------------- Leganto/en-GB.lproj/Localizable.strings | 9 +++ Leganto/en.lproj/Localizable.strings | 9 +++ 9 files changed, 118 insertions(+), 139 deletions(-) create mode 100644 Leganto/AddFeed.swift create mode 100644 Leganto/DataController.swift delete mode 100644 Leganto/Persistence.swift create mode 100644 Leganto/en-GB.lproj/Localizable.strings create mode 100644 Leganto/en.lproj/Localizable.strings diff --git a/Leganto.xcodeproj/project.pbxproj b/Leganto.xcodeproj/project.pbxproj index 136aed1..ec68a3d 100644 --- a/Leganto.xcodeproj/project.pbxproj +++ b/Leganto.xcodeproj/project.pbxproj @@ -8,22 +8,26 @@ /* Begin PBXBuildFile section */ 86B4633C2A1A382800CBBE76 /* LegantoApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86B4633B2A1A382800CBBE76 /* LegantoApp.swift */; }; - 86B4633E2A1A382800CBBE76 /* Persistence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86B4633D2A1A382800CBBE76 /* Persistence.swift */; }; 86B463412A1A382800CBBE76 /* Leganto.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 86B4633F2A1A382800CBBE76 /* Leganto.xcdatamodeld */; }; 86B463432A1A382800CBBE76 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86B463422A1A382800CBBE76 /* ContentView.swift */; }; 86B463452A1A382B00CBBE76 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 86B463442A1A382B00CBBE76 /* Assets.xcassets */; }; 86B463492A1A382B00CBBE76 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 86B463482A1A382B00CBBE76 /* Preview Assets.xcassets */; }; + 86B463532A1A3E4700CBBE76 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 86B463552A1A3E4700CBBE76 /* Localizable.strings */; }; + 86B463582A1A42D100CBBE76 /* DataController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86B463572A1A42D100CBBE76 /* DataController.swift */; }; + 86B4635A2A1A499300CBBE76 /* AddFeed.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86B463592A1A499300CBBE76 /* AddFeed.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ 86B463382A1A382800CBBE76 /* Leganto.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Leganto.app; sourceTree = BUILT_PRODUCTS_DIR; }; 86B4633B2A1A382800CBBE76 /* LegantoApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegantoApp.swift; sourceTree = ""; }; - 86B4633D2A1A382800CBBE76 /* Persistence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Persistence.swift; sourceTree = ""; }; 86B463402A1A382800CBBE76 /* Leganto.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Leganto.xcdatamodel; sourceTree = ""; }; 86B463422A1A382800CBBE76 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 86B463442A1A382B00CBBE76 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 86B463462A1A382B00CBBE76 /* Leganto.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Leganto.entitlements; sourceTree = ""; }; 86B463482A1A382B00CBBE76 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; + 86B463562A1A3ECE00CBBE76 /* en-GB */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "en-GB"; path = "en-GB.lproj/Localizable.strings"; sourceTree = ""; }; + 86B463572A1A42D100CBBE76 /* DataController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataController.swift; sourceTree = ""; }; + 86B463592A1A499300CBBE76 /* AddFeed.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddFeed.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -57,12 +61,14 @@ isa = PBXGroup; children = ( 86B4633B2A1A382800CBBE76 /* LegantoApp.swift */, - 86B4633D2A1A382800CBBE76 /* Persistence.swift */, 86B463422A1A382800CBBE76 /* ContentView.swift */, + 86B463572A1A42D100CBBE76 /* DataController.swift */, + 86B463552A1A3E4700CBBE76 /* Localizable.strings */, 86B463442A1A382B00CBBE76 /* Assets.xcassets */, 86B463462A1A382B00CBBE76 /* Leganto.entitlements */, 86B4633F2A1A382800CBBE76 /* Leganto.xcdatamodeld */, 86B463472A1A382B00CBBE76 /* Preview Content */, + 86B463592A1A499300CBBE76 /* AddFeed.swift */, ); path = Leganto; sourceTree = ""; @@ -112,11 +118,11 @@ }; buildConfigurationList = 86B463332A1A382800CBBE76 /* Build configuration list for PBXProject "Leganto" */; compatibilityVersion = "Xcode 14.0"; - developmentRegion = en; + developmentRegion = "en-GB"; hasScannedForEncodings = 0; knownRegions = ( - en, Base, + "en-GB", ); mainGroup = 86B4632F2A1A382800CBBE76; productRefGroup = 86B463392A1A382800CBBE76 /* Products */; @@ -134,6 +140,7 @@ buildActionMask = 2147483647; files = ( 86B463492A1A382B00CBBE76 /* Preview Assets.xcassets in Resources */, + 86B463532A1A3E4700CBBE76 /* Localizable.strings in Resources */, 86B463452A1A382B00CBBE76 /* Assets.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -146,19 +153,32 @@ buildActionMask = 2147483647; files = ( 86B463412A1A382800CBBE76 /* Leganto.xcdatamodeld in Sources */, + 86B463582A1A42D100CBBE76 /* DataController.swift in Sources */, + 86B4635A2A1A499300CBBE76 /* AddFeed.swift in Sources */, 86B4633C2A1A382800CBBE76 /* LegantoApp.swift in Sources */, 86B463432A1A382800CBBE76 /* ContentView.swift in Sources */, - 86B4633E2A1A382800CBBE76 /* Persistence.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ +/* Begin PBXVariantGroup section */ + 86B463552A1A3E4700CBBE76 /* Localizable.strings */ = { + isa = PBXVariantGroup; + children = ( + 86B463562A1A3ECE00CBBE76 /* en-GB */, + ); + name = Localizable.strings; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + /* Begin XCBuildConfiguration section */ 86B4634A2A1A382B00CBBE76 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; @@ -217,6 +237,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; @@ -277,6 +298,7 @@ ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_CFBundleDisplayName = Leganto; "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; @@ -315,6 +337,7 @@ ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_CFBundleDisplayName = Leganto; "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; diff --git a/Leganto/AddFeed.swift b/Leganto/AddFeed.swift new file mode 100644 index 0000000..6659c88 --- /dev/null +++ b/Leganto/AddFeed.swift @@ -0,0 +1,30 @@ +// +// AddFeed.swift +// Leganto +// +// Created by Louis Hollingworth on 2023-05-21. +// + +import SwiftUI + +enum Genre: Int16 { + case uncategorised = 0 + case technology = 1 + case news = 2 +} + +struct AddFeed: View { + @State private var name = "" + @State private var desc = "" + @State private var genre = Genre.uncategorised.rawValue + @State private var url = "" + var body: some View { + Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) + } +} + +struct AddFeed_Previews: PreviewProvider { + static var previews: some View { + AddFeed() + } +} diff --git a/Leganto/ContentView.swift b/Leganto/ContentView.swift index bd21b1f..2f26ca5 100644 --- a/Leganto/ContentView.swift +++ b/Leganto/ContentView.swift @@ -9,82 +9,22 @@ import SwiftUI import CoreData struct ContentView: View { - @Environment(\.managedObjectContext) private var viewContext - - @FetchRequest( - sortDescriptors: [NSSortDescriptor(keyPath: \Item.timestamp, ascending: true)], - animation: .default) - private var items: FetchedResults + @Environment(\.managedObjectContext) var moc + + @FetchRequest(sortDescriptors: [], animation: .default) var feeds: FetchedResults var body: some View { - NavigationView { - List { - ForEach(items) { item in - NavigationLink { - Text("Item at \(item.timestamp!, formatter: itemFormatter)") - } label: { - Text(item.timestamp!, formatter: itemFormatter) - } - } - .onDelete(perform: deleteItems) - } - .toolbar { -#if os(iOS) - ToolbarItem(placement: .navigationBarTrailing) { - EditButton() - } -#endif - ToolbarItem { - Button(action: addItem) { - Label("Add Item", systemImage: "plus") - } - } - } - Text("Select an item") - } - } - - private func addItem() { - withAnimation { - let newItem = Item(context: viewContext) - newItem.timestamp = Date() - - do { - try viewContext.save() - } catch { - // Replace this implementation with code to handle the error appropriately. - // 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. - let nsError = error as NSError - fatalError("Unresolved error \(nsError), \(nsError.userInfo)") - } - } - } - - private func deleteItems(offsets: IndexSet) { - withAnimation { - offsets.map { items[$0] }.forEach(viewContext.delete) - - do { - try viewContext.save() - } catch { - // Replace this implementation with code to handle the error appropriately. - // 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. - let nsError = error as NSError - fatalError("Unresolved error \(nsError), \(nsError.userInfo)") - } - } + Text("Hello World") } + + func addItem() {} + + func deleteItems() {} } -private let itemFormatter: DateFormatter = { - let formatter = DateFormatter() - formatter.dateStyle = .short - formatter.timeStyle = .medium - return formatter -}() struct ContentView_Previews: PreviewProvider { static var previews: some View { - ContentView().environment(\.managedObjectContext, PersistenceController.preview.container.viewContext) + ContentView() } } diff --git a/Leganto/DataController.swift b/Leganto/DataController.swift new file mode 100644 index 0000000..066f9da --- /dev/null +++ b/Leganto/DataController.swift @@ -0,0 +1,21 @@ +// +// DataController.swift +// Leganto +// +// Created by Louis Hollingworth on 2023-05-21. +// + +import Foundation +import CoreData + +class DataController: ObservableObject { + let container = NSPersistentContainer(name: "Leganto") + + init() { + container.loadPersistentStores { desc, err in + if let err = err { + print("Core Data failed to load: \(err.localizedDescription)") + } + } + } +} diff --git a/Leganto/Leganto.xcdatamodeld/Leganto.xcdatamodel/contents b/Leganto/Leganto.xcdatamodeld/Leganto.xcdatamodel/contents index e8d6ec8..6a0c338 100644 --- a/Leganto/Leganto.xcdatamodeld/Leganto.xcdatamodel/contents +++ b/Leganto/Leganto.xcdatamodeld/Leganto.xcdatamodel/contents @@ -1,9 +1,12 @@ - - - + + + + + + + + + - - - \ No newline at end of file diff --git a/Leganto/LegantoApp.swift b/Leganto/LegantoApp.swift index 77c7ed6..881ddee 100644 --- a/Leganto/LegantoApp.swift +++ b/Leganto/LegantoApp.swift @@ -9,12 +9,12 @@ import SwiftUI @main struct LegantoApp: App { - let persistenceController = PersistenceController.shared + @StateObject private var dataController = DataController() var body: some Scene { WindowGroup { ContentView() - .environment(\.managedObjectContext, persistenceController.container.viewContext) + .environment(\.managedObjectContext, dataController.container.viewContext) } } } diff --git a/Leganto/Persistence.swift b/Leganto/Persistence.swift deleted file mode 100644 index f28cca1..0000000 --- a/Leganto/Persistence.swift +++ /dev/null @@ -1,56 +0,0 @@ -// -// Persistence.swift -// Leganto -// -// Created by Louis Hollingworth on 2023-05-21. -// - -import CoreData - -struct PersistenceController { - static let shared = PersistenceController() - - static var preview: PersistenceController = { - let result = PersistenceController(inMemory: true) - let viewContext = result.container.viewContext - for _ in 0..<10 { - let newItem = Item(context: viewContext) - newItem.timestamp = Date() - } - do { - try viewContext.save() - } catch { - // Replace this implementation with code to handle the error appropriately. - // 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. - let nsError = error as NSError - fatalError("Unresolved error \(nsError), \(nsError.userInfo)") - } - return result - }() - - let container: NSPersistentCloudKitContainer - - init(inMemory: Bool = false) { - container = NSPersistentCloudKitContainer(name: "Leganto") - if inMemory { - container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null") - } - container.loadPersistentStores(completionHandler: { (storeDescription, error) in - if let error = error as NSError? { - // Replace this implementation with code to handle the error appropriately. - // 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. - - /* - Typical reasons for an error here include: - * The parent directory does not exist, cannot be created, or disallows writing. - * The persistent store is not accessible, due to permissions or data protection when the device is locked. - * The device is out of space. - * The store could not be migrated to the current model version. - Check the error message to determine what the actual problem was. - */ - fatalError("Unresolved error \(error), \(error.userInfo)") - } - }) - container.viewContext.automaticallyMergesChangesFromParent = true - } -} diff --git a/Leganto/en-GB.lproj/Localizable.strings b/Leganto/en-GB.lproj/Localizable.strings new file mode 100644 index 0000000..ced3eab --- /dev/null +++ b/Leganto/en-GB.lproj/Localizable.strings @@ -0,0 +1,9 @@ +/* + Localizable.strings + Leganto + + Created by Louis Hollingworth on 2023-05-21. + +*/ + +"feeds" = "Feeds"; diff --git a/Leganto/en.lproj/Localizable.strings b/Leganto/en.lproj/Localizable.strings new file mode 100644 index 0000000..7e576bf --- /dev/null +++ b/Leganto/en.lproj/Localizable.strings @@ -0,0 +1,9 @@ +/* + Localizable.strings + Leganto + + Created by Louis Hollingworth on 2023-05-21. + +*/ + +"feeds" = "Feeds"