Skip to content

Instantly share code, notes, and snippets.

enum AppDestination: String {
case rectangle
case circle
}
struct ContentView: View {
@State private var selected: AppDestination = .circle
@simonnickel
simonnickel / gist:4d8d1ffd3f5d98482fbc293b0a11b8a1
Created October 22, 2024 20:57
Swift Actor - later accesses could race
actor SomeActor {
func doSomething() { }
}
class SomeClass {
private let someActor = SomeActor()
func doSomething() {
Task { // Task-isolated value of type '() async -> ()' passed as a strongly transferred parameter; later accesses could race
@simonnickel
simonnickel / ContentView.swift
Created June 29, 2024 12:51
Swift 6: SwiftUI Environment - nonisolated init with Non Sendable param
import SwiftUI
protocol DependencyValue {
var content: String { get }
}
@MainActor class Dependency {
var value: DependencyValue // NonSendable
@simonnickel
simonnickel / ContentView.swift
Created June 29, 2024 11:54
Swift 6: SwiftUI Environment
import SwiftUI
@MainActor class Dependency {
var value: String
nonisolated init(value: String? = nil) {
self.value = value ?? "Initial"
}
@simonnickel
simonnickel / UIView+Embed.swift
Last active July 13, 2021 05:41
Simple UIView extension to embed a view in a container.
extension UIView {
struct EmbedInsets {
let top: CGFloat?
let left: CGFloat?
let right: CGFloat?
let bottom: CGFloat?
init(top: CGFloat? = nil, bottom: CGFloat? = nil, left: CGFloat? = nil, right: CGFloat? = nil) {
self.top = top
pod "SNLInteractionTableView", "~> 1.3.0"
#pragma mark - SNLInteractionCell delegate
- (void)swipeAction:(SNLSwipeSide)swipeSide onCell:(SNLExampleTableViewCell *)cell {
// implement actions on successfull swipe gesture
if (swipeSide == SNLSwipeSideLeft) {
NSLog(@"Left on '%@'", cell.label.text);
}
else if (swipeSide == SNLSwipeSideRight) {
NSLog(@"Right on '%@'", cell.label.text);
[self performSegueWithIdentifier:@"detail" sender:self];
/*
// to override default/storyboard colors use:
self.colorBackground = [UIColor grayColor];
self.colorContainer = [UIColor whiteColor];
self.colorSelected = [UIColor greenColor];
self.colorToolbarBarTint = [UIColor blueColor];
self.colorToolbarTint = [UIColor greenColor];
self.colorIndicator = [UIColor redColor];
self.colorIndicatorSuccess = [UIColor greenColor];
self.colorCustomSeparatorTop = [UIColor whiteColor];
#pragma mark - SNLInteractionTableView delegate - Reorder
- (void)startedReorderAtIndexPath:(NSIndexPath *)indexPath {
// additional setup when reordering starts
NSLog(@"Reordering started");
}
// Update your data source when a cell is draged to a new position. This method is called every time 2 cells switch positions.
- (void)moveRowFromIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
// update DataSource when cells are switched
UIBarButtonItem *buttonA = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(buttonPressed:)];
buttonA.tag = 1;
UIBarButtonItem *buttonB = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(buttonPressed:)];
buttonB.tag = 2;
UIBarButtonItem *flexibleItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[self setToolbarButtons: [NSArray arrayWithObjects:flexibleItem, buttonA, flexibleItem, buttonB, flexibleItem, nil]];