Skip to content

Instantly share code, notes, and snippets.

struct ContentView: View {
@State var isOuterLoading1 = false
@State var isOuterLoading2 = false
var body: some View {
VStack {
HStack {
Spacer()
Circle() // Sun
extension UIImage {
class func gifImage(data: Data) -> UIImage? {
guard let source = CGImageSourceCreateWithData(data as CFData, nil) else { return nil }
let count = CGImageSourceGetCount(source)
let delays = (0..<count).map {
Int(delayForImage(at: $0, source: source) * 1000)
}
let duration = delays.reduce(0, +)
let gcd = delays.reduce(0, gcd)
struct BackgroundColorChange: View {
let gridItems = [GridItem(.flexible()), GridItem(.flexible(minimum: 20, maximum: 50)), GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible(minimum: 10, maximum: 20))]
var body: some View {
ScrollView {
LazyVGrid(columns: gridItems, spacing: 0) {
ForEach(0...100, id: \.self) {
Text("\($0)")
.padding()
extension View {
func debugOnlyModifier<T: View>(_ modifier: (Self) -> T) -> some View {
#if DEBUG
return modifier(self)
#else
return self
#endif
}
private var colors: [Color] {
struct PrintingChanges: View {
@State var counter = 0
var body: some View {
Self._printChanges()
return Button {
counter += 1
} label: {
Text("Current Value \(counter)")
}
import Foundation
import XCTest
struct ContentViewHelper {
static let app = XCUIApplication()
enum StaticText {
static let titleText = app.staticTexts["Normal Text"]
static let overriddenTitleText = app.staticTexts["Text Overridden for UI Tests"]
static let view1Text = app.staticTexts["View - 1"]
import XCTest
import SwiftUI
class SwiftUI_UITesting_MediumUITests: XCTestCase {
let app = XCUIApplication()
override func setUp() {
super.setUp()
continueAfterFailure = false
@main
struct SwiftUI_UITesting_MediumApp: App {
init() {
loadEnvironmentRelatedServices()
}
var body: some Scene {
WindowGroup {
ContentView()
}
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
//put custom code here
return true
}
}
class TestDetector {
private enum Keys: String {
case shouldOverrideTitleText = "Override-Label-titleText"
case showView2 = "Override-showView2"
}
static func isRunningUITests() -> Bool {
return ProcessInfo.processInfo.arguments.contains("isRunningUITests")
}