Skip to content

Instantly share code, notes, and snippets.

View scottfinkelstein's full-sized avatar

Scott Finkelstein scottfinkelstein

View GitHub Profile
import SwiftUI
@main
struct MyTodoList: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
import SwiftUI
struct ContentView: View {
@Environment(\.managedObjectContext) var context
@FetchRequest(entity: Todo.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \Todo.title, ascending: true)]) var todos: FetchedResults<Todo>
@State private var todoString: String = ""
var body: some View {
VStack {
HStack {
TextField("Add a Todo", text: $todoString)
@scottfinkelstein
scottfinkelstein / MyTodoListApp.swift
Last active July 14, 2020 00:17
SwiftUI App Entry Point
import SwiftUI
@main
struct MyTodoList: App {
let context = DataStore.shared.persistentContainer.viewContext
var body: some Scene {
WindowGroup {
ContentView().environment(\.managedObjectContext, context)
}
}
@scottfinkelstein
scottfinkelstein / DataStore.swift
Created July 13, 2020 23:48
CoreData Singleton class
import Foundation
import CoreData
class DataStore {
static let shared = DataStore()
let persistentContainer: NSPersistentContainer = {
let container = NSPersistentContainer(name: "MyDataModel")
container.loadPersistentStores { description, error in
if let error = error {
0x163CeB9b2BA2e8Fa58B4F1544b7Df2d1028bD625
@scottfinkelstein
scottfinkelstein / scriptr_weather_email.js
Created March 23, 2015 12:17
Scriptr.io Email Weather Script
// Include http module
var http=require('http');
// Get the ZIP code and email passed in by the request parameter sent to this script.
var zipCode=request.parameters.zipcode;
var email=request.parameters.email;
// Construct REST call to OpenWeatherMap API
var weatherService='http://api.openweathermap.org/data/2.5/weather?q='+zipCode+'&units=imperial';
var callResult=http.request({'url': weatherService});