Skip to content

Instantly share code, notes, and snippets.

Avatar

Jan Chaloupecky JanC

  • N26
  • Berlin
View GitHub Profile
View SwiftUIRepresentable.swift
import SwiftUI
import Combine
struct MyContentView: View {
@State var isPresentingModal = false
// comment this out
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
View SwiftUI.swift
import SwiftUI
/// If _anything_ changes in the `MainView` (e.g. Timer update), its `var body` is re-created and therefore a new instance of `DetailsView(presenter: DetailsViewPresenter())` is created (even if it is already pushed)
/// A new instance of `DetailsViewPresenter` has `isChecked` set to false so the checkbox is unchecked even if view is already presented
struct MainView: View {
let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
let formatter: DateFormatter = {
View mvvm.md

MVVM

A pseudo implememntation of a mvvm with different cell types in the same section. The table view displays a mixed list of User profiles and their Posts.

Each section's 1st row is the profile of a user and the next cells in that section are the posts of that user

// MARK: -  Models
View q3.m
NSOperation *operation = [[NSOperation alloc] init];
__weak typeof(operation) weakOperation = operation;
operation.completionBlock = ^{
__strong typeof(operation) strongOperation = weakOperation;
if (strongOperation.isCancelled) {
// do something
}
};
View q2.m
NSOperation *operation = [[NSOperation alloc] init];
operation.completionBlock = ^{
if (operation.isCancelled) {
// do something
}
};
View q1.m
NSObject *test;
NSArray *someArray = @[ @1, @2, @3 ]; // sample array
[someArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
test = obj;
}];