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
public func printDetail( _ items: Any..., | |
fileID: String = #fileID, | |
function: String = #function, | |
line: Int = #line, | |
separator: String = " ", | |
terminator: String = "\n") { | |
print("___________________________") | |
print(items.map{ "\($0)" }.joined(separator: separator)) | |
print( | |
""" |
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
import SwiftUI | |
enum Style: String, CaseIterable { | |
case grouped, inset, insetGrouped, plain, sidebar | |
} | |
struct ContentView: View { | |
@State private var selectedStyle: Style = .plain | |
var body: some View { |
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
import SwiftUI | |
struct PreviewLocation: ViewModifier { | |
enum LocationDir { | |
case documentsDirectory | |
case applicationSupportDirectory | |
} | |
let directory: LocationDir | |
func body(content: Content) -> some View { |
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
// Sample Use | |
struct ContentView: View { | |
@State private var size: CGSize = .zero | |
var body: some View { | |
VStack { | |
Text("\(size.width)") | |
Text("Hello World") | |
.getCGSize($size) | |
} | |
.padding() |
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
import SwiftUI | |
struct ContentView: View { | |
let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect() | |
@State private var totalSeconds = 30 | |
var body: some View { | |
Text(timeStringFromSeconds(totalSeconds)) | |
.monospaced() | |
.contentTransition(.numericText()) | |
.font(.system(size: 60)) |
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
// https://gist.github.com/StewartLynch/03372c873fef568e0a613a968adbae69 | |
import SwiftUI | |
/// A view of inline images that represents a rating. | |
/// Tapping on an image will change it from an unfilled to a filled version of the image. | |
/// | |
/// The following example shows a Ratings view with a maximum rating of 10 red flags, each with a width of 20: | |
/// | |
/// RatingsView(maxRating: 10, |
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
import Foundation | |
extension Book { | |
static let lastWeek = Calendar.current.date(byAdding: .day, value: -7, to: Date.now)! | |
static let lastMonth = Calendar.current.date(byAdding: .month, value: -1, to: Date.now)! | |
static var sampleBooks: [Book] { | |
[ | |
Book(title: "QBVII", | |
author: "Leon Uris"), | |
Book(title: "Macbeth", |
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
@Observable class SomeClass { | |
// @AppStorage("name") var name = "" // Does not work | |
/// This will do the same thing | |
var name: String { | |
get { | |
access(keyPath: \.name) | |
return UserDefaults.standard.string(forKey: "name") ?? "" | |
} | |
set { | |
withMutation (keyPath: \.name) { |
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
import UIKit | |
var Words = """ | |
""" | |
var keyWords: String { | |
Words.replacingOccurrences(of: " : {", with: "") | |
.replacingOccurrences(of:" \"", with: "") | |
.replacingOccurrences(of: "\"\n\n },", with: "") |