Skip to content

Instantly share code, notes, and snippets.

@NeilsUltimateLab
NeilsUltimateLab / CodableResource.md
Last active April 5, 2021 03:30
Fetch resources using Alamofire with Codable.

CodableResource

Fetch resource using Alamofire with Codable.

This document shows the use of URLComponenent to decouple url by use of swift enums. By creating a Result<A> enum type error handling is done with ease. At the end defining the Codable User and Address structs allows the easy json-parsing.

import Foundation

URLScheme to declare the HTTP Scheme

enum URLScheme: String {

@smileyborg
smileyborg / InteractiveTransitionCollectionViewDeselection.m
Last active January 15, 2023 13:03
Animate table & collection view deselection alongside interactive transition (for iOS 11 and later)
// UICollectionView Objective-C example
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] firstObject];
if (selectedIndexPath != nil) {
id<UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator;
if (coordinator != nil) {
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
@NeilsUltimateLab
NeilsUltimateLab / Understanding UIViewController Rotation when embed in Container View Controllers.md
Last active November 7, 2023 11:59
Understanding UIViewController rotation when embed in Container View Controllers.

Understanding UIViewController Rotation

Problem

To enable the rotation of a single view controller used to display the preview of Images/Videos. It is intuitive to allow user to rotate there device and screen changes accordingly, so it feels pleasant. But to achieve this, we need to enable the (almost) all Supported Device orientations.

Ex: `Portrait`, `LandscapeLeft`, `LandscapeRight`.

WWDC 2019 Labs Questions

Size changes propagation to child view controller

In A Look Inside Presentation Controllers - WWDC 2014 session the following pattern was introduced.

  • A child view controller or a presented view controller can issue a request for size update by setting its preferredContentSize property.
  • A parent view controller or a presentation controller will receive a callback on preferredContentSizeDidChangeForChildContentContainer method.
  • At this point the receiver can decide if can allow the size request and layout the child view controller or the presented view controller.
import UIKit
import MessageUI
struct MailInfo {
var recipient: String
var subject: String?
var message: String?
var isHTML: Bool = false
}
@NeilsUltimateLab
NeilsUltimateLab / OneTimeCodeField.swift
Last active June 23, 2022 16:18
One Time Code field without UITextFields hacks.
import UIKit
class OneTimeCodeField: UIControl {
enum FieldState {
case empty
case filled
case respoding
}