-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d5617c5
Showing
15 changed files
with
926 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
148 changes: 148 additions & 0 deletions
148
Shared/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "2x", | ||
"size" : "60x60" | ||
}, | ||
{ | ||
"idiom" : "iphone", | ||
"scale" : "3x", | ||
"size" : "60x60" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "20x20" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "29x29" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "40x40" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "1x", | ||
"size" : "76x76" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "76x76" | ||
}, | ||
{ | ||
"idiom" : "ipad", | ||
"scale" : "2x", | ||
"size" : "83.5x83.5" | ||
}, | ||
{ | ||
"idiom" : "ios-marketing", | ||
"scale" : "1x", | ||
"size" : "1024x1024" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "16x16" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "16x16" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "32x32" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "32x32" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "128x128" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "128x128" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "256x256" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "256x256" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "1x", | ||
"size" : "512x512" | ||
}, | ||
{ | ||
"idiom" : "mac", | ||
"scale" : "2x", | ||
"size" : "512x512" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// | ||
// ContentView.swift | ||
// Shared | ||
// | ||
// Created by Ananya George on 9/30/21. | ||
// | ||
|
||
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<Item> | ||
|
||
var body: some View { | ||
List { | ||
ForEach(items) { item in | ||
Text("Item at \(item.timestamp!, formatter: itemFormatter)") | ||
} | ||
.onDelete(perform: deleteItems) | ||
} | ||
.toolbar { | ||
#if os(iOS) | ||
EditButton() | ||
#endif | ||
|
||
Button(action: addItem) { | ||
Label("Add Item", systemImage: "plus") | ||
} | ||
} | ||
} | ||
|
||
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)") | ||
} | ||
} | ||
} | ||
} | ||
|
||
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// Persistence.swift | ||
// Shared | ||
// | ||
// Created by Ananya George on 9/30/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: NSPersistentContainer | ||
|
||
init(inMemory: Bool = false) { | ||
container = NSPersistentContainer(name: "Xpendi") | ||
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)") | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>_XCCurrentVersionName</key> | ||
<string>Shared.xcdatamodel</string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?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="false" userDefinedModelVersionIdentifier=""> | ||
<entity name="Item" representedClassName="Item" syncable="YES" codeGenerationType="class"> | ||
<attribute name="timestamp" optional="YES" attributeType="Date" usesScalarValueType="NO"/> | ||
</entity> | ||
<elements> | ||
<element name="Item" positionX="-63" positionY="-18" width="128" height="44"/> | ||
</elements> | ||
</model> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// XpendiApp.swift | ||
// Shared | ||
// | ||
// Created by Ananya George on 9/30/21. | ||
// | ||
|
||
import SwiftUI | ||
|
||
@main | ||
struct XpendiApp: App { | ||
let persistenceController = PersistenceController.shared | ||
|
||
var body: some Scene { | ||
WindowGroup { | ||
ContentView() | ||
.environment(\.managedObjectContext, persistenceController.container.viewContext) | ||
} | ||
} | ||
} |
Oops, something went wrong.