This file contains hidden or 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
const path = require('path'); | |
const fs = require('fs'); | |
const basePathToData = path.join(__dirname, 'path-to-your-json-data-file'); | |
const getJsonData = function (basePathToData, filename) { | |
var filename = path.join(basePathToData, filename); | |
return JSON.parse(fs.readFileSync(filename, 'utf-8')); | |
}; |
This file contains hidden or 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
[ | |
{ | |
"id": 1, | |
"name": "sample-name-1" | |
}, | |
{ | |
"id": 2, | |
"name": "sample-name-2" | |
}, | |
] |
This file contains hidden or 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
func loadData() { | |
guard let url = URL(string: "https://jsonplaceholder.typicode.com/todos") else { | |
print("Invalid URL") | |
return | |
} | |
let request = URLRequest(url: url) | |
URLSession.shared.dataTask(with: request) { data, response, error in | |
if let data = data { | |
if let response = try? JSONDecoder().decode([TaskEntry].self, from: data) { |
This file contains hidden or 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
import SwiftUI | |
struct ContentView: View { | |
@State var results = [TaskEntry]() | |
var body: some View { | |
List(results, id: \.id) { item in | |
VStack(alignment: .leading) { | |
Text(item.title) |
This file contains hidden or 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
import SwiftUI | |
class Favorites: ObservableObject { | |
private var tasks: Set<String> | |
let defaults = UserDefaults.standard | |
init() { | |
let decoder = JSONDecoder() | |
if let data = defaults.value(forKey: "Favorites") as? Data { | |
let taskData = try? decoder.decode(Set<String>.self, from: data) |
This file contains hidden or 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
func scheduleNotifications() { | |
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { success, error in | |
if success { | |
print("Success") | |
//To add badgeNumber | |
//UIApplication.shared.applicationIconBadgeNumber = badgeNumber (Integer Value) | |
} else if let error = error { | |
print(error.localizedDescription) | |
} |
This file contains hidden or 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
import SwiftUI | |
import PlaygroundSupport | |
struct Screen: View { | |
var body: some View { | |
ScrollView { | |
HStack { | |
VStack (alignment: .leading) { | |
Text("TUESDAY, MAY 12").foregroundColor(.secondary).bold().font(.footnote) |
This file contains hidden or 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
struct Breathe: View { | |
@State var scale = false | |
@State var rotate = false | |
var body: some View { | |
ZStack { | |
Group { | |
ZStack { | |
Circle().frame(width: 80, height: 80).foregroundColor(Color(UIColor.systemBlue)).offset(y: -42) | |
Circle().frame(width: 80, height: 80).foregroundColor(Color(UIColor.systemBlue)).offset(y: 42) |