Skip to content

Instantly share code, notes, and snippets.

View JanC's full-sized avatar

Jan Chaloupecky JanC

  • N26
  • Berlin
View GitHub Profile
import SwiftUI
import Combine
struct MyContentView: View {
@State var isPresentingModal = false
// comment this out
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
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 = {
@JanC
JanC / mvvm.md
Last active January 29, 2018 16:38
mvvm

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
@JanC
JanC / q3.m
Created August 12, 2015 13:27
NSOperation *operation = [[NSOperation alloc] init];
__weak typeof(operation) weakOperation = operation;
operation.completionBlock = ^{
__strong typeof(operation) strongOperation = weakOperation;
if (strongOperation.isCancelled) {
// do something
}
};
@JanC
JanC / q2.m
Created August 12, 2015 13:27
NSOperation *operation = [[NSOperation alloc] init];
operation.completionBlock = ^{
if (operation.isCancelled) {
// do something
}
};
@JanC
JanC / q1.m
Created August 12, 2015 13:26
NSObject *test;
NSArray *someArray = @[ @1, @2, @3 ]; // sample array
[someArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
test = obj;
}];