Removed not needed stuff from generation.

Started adding a view for adding data.

Signed-off-by: Louis Hollingworth <louis@hollingworth.ch>
This commit is contained in:
Louis Hollingworth 2023-05-21 13:52:47 +01:00
parent 81cb27dd6c
commit 9701c3428c
Signed by: lucxjo
GPG key ID: A11415CB3DC7809B
9 changed files with 118 additions and 139 deletions

View file

@ -8,22 +8,26 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
86B4633C2A1A382800CBBE76 /* LegantoApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86B4633B2A1A382800CBBE76 /* LegantoApp.swift */; }; 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 */; }; 86B463412A1A382800CBBE76 /* Leganto.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 86B4633F2A1A382800CBBE76 /* Leganto.xcdatamodeld */; };
86B463432A1A382800CBBE76 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86B463422A1A382800CBBE76 /* ContentView.swift */; }; 86B463432A1A382800CBBE76 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86B463422A1A382800CBBE76 /* ContentView.swift */; };
86B463452A1A382B00CBBE76 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 86B463442A1A382B00CBBE76 /* Assets.xcassets */; }; 86B463452A1A382B00CBBE76 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 86B463442A1A382B00CBBE76 /* Assets.xcassets */; };
86B463492A1A382B00CBBE76 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 86B463482A1A382B00CBBE76 /* Preview 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 */ /* End PBXBuildFile section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
86B463382A1A382800CBBE76 /* Leganto.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Leganto.app; sourceTree = BUILT_PRODUCTS_DIR; }; 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 = "<group>"; }; 86B4633B2A1A382800CBBE76 /* LegantoApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LegantoApp.swift; sourceTree = "<group>"; };
86B4633D2A1A382800CBBE76 /* Persistence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Persistence.swift; sourceTree = "<group>"; };
86B463402A1A382800CBBE76 /* Leganto.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Leganto.xcdatamodel; sourceTree = "<group>"; }; 86B463402A1A382800CBBE76 /* Leganto.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Leganto.xcdatamodel; sourceTree = "<group>"; };
86B463422A1A382800CBBE76 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; }; 86B463422A1A382800CBBE76 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
86B463442A1A382B00CBBE76 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; }; 86B463442A1A382B00CBBE76 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
86B463462A1A382B00CBBE76 /* Leganto.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Leganto.entitlements; sourceTree = "<group>"; }; 86B463462A1A382B00CBBE76 /* Leganto.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Leganto.entitlements; sourceTree = "<group>"; };
86B463482A1A382B00CBBE76 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; }; 86B463482A1A382B00CBBE76 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
86B463562A1A3ECE00CBBE76 /* en-GB */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "en-GB"; path = "en-GB.lproj/Localizable.strings"; sourceTree = "<group>"; };
86B463572A1A42D100CBBE76 /* DataController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataController.swift; sourceTree = "<group>"; };
86B463592A1A499300CBBE76 /* AddFeed.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddFeed.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -57,12 +61,14 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
86B4633B2A1A382800CBBE76 /* LegantoApp.swift */, 86B4633B2A1A382800CBBE76 /* LegantoApp.swift */,
86B4633D2A1A382800CBBE76 /* Persistence.swift */,
86B463422A1A382800CBBE76 /* ContentView.swift */, 86B463422A1A382800CBBE76 /* ContentView.swift */,
86B463572A1A42D100CBBE76 /* DataController.swift */,
86B463552A1A3E4700CBBE76 /* Localizable.strings */,
86B463442A1A382B00CBBE76 /* Assets.xcassets */, 86B463442A1A382B00CBBE76 /* Assets.xcassets */,
86B463462A1A382B00CBBE76 /* Leganto.entitlements */, 86B463462A1A382B00CBBE76 /* Leganto.entitlements */,
86B4633F2A1A382800CBBE76 /* Leganto.xcdatamodeld */, 86B4633F2A1A382800CBBE76 /* Leganto.xcdatamodeld */,
86B463472A1A382B00CBBE76 /* Preview Content */, 86B463472A1A382B00CBBE76 /* Preview Content */,
86B463592A1A499300CBBE76 /* AddFeed.swift */,
); );
path = Leganto; path = Leganto;
sourceTree = "<group>"; sourceTree = "<group>";
@ -112,11 +118,11 @@
}; };
buildConfigurationList = 86B463332A1A382800CBBE76 /* Build configuration list for PBXProject "Leganto" */; buildConfigurationList = 86B463332A1A382800CBBE76 /* Build configuration list for PBXProject "Leganto" */;
compatibilityVersion = "Xcode 14.0"; compatibilityVersion = "Xcode 14.0";
developmentRegion = en; developmentRegion = "en-GB";
hasScannedForEncodings = 0; hasScannedForEncodings = 0;
knownRegions = ( knownRegions = (
en,
Base, Base,
"en-GB",
); );
mainGroup = 86B4632F2A1A382800CBBE76; mainGroup = 86B4632F2A1A382800CBBE76;
productRefGroup = 86B463392A1A382800CBBE76 /* Products */; productRefGroup = 86B463392A1A382800CBBE76 /* Products */;
@ -134,6 +140,7 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
86B463492A1A382B00CBBE76 /* Preview Assets.xcassets in Resources */, 86B463492A1A382B00CBBE76 /* Preview Assets.xcassets in Resources */,
86B463532A1A3E4700CBBE76 /* Localizable.strings in Resources */,
86B463452A1A382B00CBBE76 /* Assets.xcassets in Resources */, 86B463452A1A382B00CBBE76 /* Assets.xcassets in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
@ -146,19 +153,32 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
86B463412A1A382800CBBE76 /* Leganto.xcdatamodeld in Sources */, 86B463412A1A382800CBBE76 /* Leganto.xcdatamodeld in Sources */,
86B463582A1A42D100CBBE76 /* DataController.swift in Sources */,
86B4635A2A1A499300CBBE76 /* AddFeed.swift in Sources */,
86B4633C2A1A382800CBBE76 /* LegantoApp.swift in Sources */, 86B4633C2A1A382800CBBE76 /* LegantoApp.swift in Sources */,
86B463432A1A382800CBBE76 /* ContentView.swift in Sources */, 86B463432A1A382800CBBE76 /* ContentView.swift in Sources */,
86B4633E2A1A382800CBBE76 /* Persistence.swift in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
/* End PBXSourcesBuildPhase section */ /* End PBXSourcesBuildPhase section */
/* Begin PBXVariantGroup section */
86B463552A1A3E4700CBBE76 /* Localizable.strings */ = {
isa = PBXVariantGroup;
children = (
86B463562A1A3ECE00CBBE76 /* en-GB */,
);
name = Localizable.strings;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */ /* Begin XCBuildConfiguration section */
86B4634A2A1A382B00CBBE76 /* Debug */ = { 86B4634A2A1A382B00CBBE76 /* Debug */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
@ -217,6 +237,7 @@
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
buildSettings = { buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO; ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NONNULL = YES;
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
@ -277,6 +298,7 @@
ENABLE_HARDENED_RUNTIME = YES; ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = Leganto;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
@ -315,6 +337,7 @@
ENABLE_HARDENED_RUNTIME = YES; ENABLE_HARDENED_RUNTIME = YES;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_CFBundleDisplayName = Leganto;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES; "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES; "INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;

30
Leganto/AddFeed.swift Normal file
View file

@ -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()
}
}

View file

@ -9,82 +9,22 @@ import SwiftUI
import CoreData import CoreData
struct ContentView: View { struct ContentView: View {
@Environment(\.managedObjectContext) private var viewContext @Environment(\.managedObjectContext) var moc
@FetchRequest( @FetchRequest(sortDescriptors: [], animation: .default) var feeds: FetchedResults<Feed>
sortDescriptors: [NSSortDescriptor(keyPath: \Item.timestamp, ascending: true)],
animation: .default)
private var items: FetchedResults<Item>
var body: some View { var body: some View {
NavigationView { Text("Hello World")
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() { func addItem() {}
withAnimation {
let newItem = Item(context: viewContext)
newItem.timestamp = Date()
do { func deleteItems() {}
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)")
}
}
}
}
private let itemFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .short
formatter.timeStyle = .medium
return formatter
}()
struct ContentView_Previews: PreviewProvider { struct ContentView_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
ContentView().environment(\.managedObjectContext, PersistenceController.preview.container.viewContext) ContentView()
} }
} }

View file

@ -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)")
}
}
}
}

View file

@ -1,9 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="1" systemVersion="11A491" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithCloudKit="true" userDefinedModelVersionIdentifier=""> <model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="21754" systemVersion="22F5059b" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithCloudKit="YES" userDefinedModelVersionIdentifier="">
<entity name="Item" representedClassName="Item" syncable="YES" codeGenerationType="class"> <entity name="Feed" representedClassName="Feed" syncable="YES" codeGenerationType="class">
<attribute name="timestamp" optional="YES" attributeType="Date" usesScalarValueType="NO"/> <attribute name="dateAdded" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="dateUpdated" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="desc" optional="YES" attributeType="String"/>
<attribute name="genre" optional="YES" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="id" optional="YES" attributeType="UUID" usesScalarValueType="NO"/>
<attribute name="name" optional="YES" attributeType="String"/>
<attribute name="url" optional="YES" attributeType="String"/>
</entity> </entity>
<elements>
<element name="Item" positionX="-63" positionY="-18" width="128" height="44"/>
</elements>
</model> </model>

View file

@ -9,12 +9,12 @@ import SwiftUI
@main @main
struct LegantoApp: App { struct LegantoApp: App {
let persistenceController = PersistenceController.shared @StateObject private var dataController = DataController()
var body: some Scene { var body: some Scene {
WindowGroup { WindowGroup {
ContentView() ContentView()
.environment(\.managedObjectContext, persistenceController.container.viewContext) .environment(\.managedObjectContext, dataController.container.viewContext)
} }
} }
} }

View file

@ -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
}
}

View file

@ -0,0 +1,9 @@
/*
Localizable.strings
Leganto
Created by Louis Hollingworth on 2023-05-21.
*/
"feeds" = "Feeds";

View file

@ -0,0 +1,9 @@
/*
Localizable.strings
Leganto
Created by Louis Hollingworth on 2023-05-21.
*/
"feeds" = "Feeds"