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 {

@NeilsUltimateLab
NeilsUltimateLab / SelectionTableCell.swift
Last active October 14, 2021 07:10
SelectionViewController with multiple and single selection.
import UIKit
class SelectionTableCell: UITableViewCell {
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.selectionStyle = .none
}
required init?(coder aDecoder: NSCoder) {
@NeilsUltimateLab
NeilsUltimateLab / SystemAppType.swift
Created March 19, 2018 13:17
Open iOS system apps.
//
// SystemAppType.swift
// REIWA
//
// Created by Neil Jain on 19/03/18.
// Copyright © 2018 NeilsUltimateLab. All rights reserved.
//
import Foundation
@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`.
@NeilsUltimateLab
NeilsUltimateLab / Decoding Result type.playground
Created April 3, 2018 19:37
Decoding Result<A, E> types in swift
//: Playground - noun: a place where people can play
import UIKit
let errorJsonData = """
{
"message": "The message",
"reference_url": "https://www.api.refer.co"
}
""".data(using: .utf8)!
@NeilsUltimateLab
NeilsUltimateLab / AppleIRRemoteKeycode.txt
Created April 6, 2018 13:10
Apple IR Remote keycodes
Up key: 2011254800
Down key: 2011246608
Left key: 2011271184
Right key:2011258896
Menu key: 2011283472
PlayPause key: 2011298320 2011275280
@NeilsUltimateLab
NeilsUltimateLab / SectionProviderProtocol.swift
Created May 12, 2018 11:23
Generate IndexPaths from Sectioned DataSource
protocol SectionProviderProtocol {
associatedtype T
var header: String? { get }
var rows: [T] { get }
}
extension Array where Element: SectionProviderProtocol, Element.T: Equatable {
var indexPaths: [IndexPath] {
var paths: [IndexPath] = []
for (section, item) in self.enumerated() {
@NeilsUltimateLab
NeilsUltimateLab / CommandLineCalc.swift
Created June 3, 2018 12:16
Simple Command Line Calculator
//
// main.swift
// Calculator
//
// Created by NeilsUltimateLab on 03/06/18.
// Copyright © 2018 NeilsUltimateLab. All rights reserved.
//
import Foundation
@NeilsUltimateLab
NeilsUltimateLab / ShimmeringEffect.md
Created June 16, 2018 05:27
UIView shimmering effect

Shimmering Effect

import UIKit

extension UIView {
  func startShimmering() {
    let light = self.tintColor.cgColor
    let dark = UIColor(white: 0, alpha: 0.3).cgColor
@NeilsUltimateLab
NeilsUltimateLab / handleKeyboardNotification.swift
Last active July 6, 2018 03:00
Handle keyboard notification for custom transition. This implementation handles interaction with keyboard frame.
extension ViewController {
@objc func handleKeyboardWillShow(notification: Notification) {
guard notification.name == UIResponder.keyboardWillShowNotification else {
return
}
guard let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return }
let viewFrame = self.view.frame
let newRect = self.view.convert(self.view.frame, to: self.view.window)
print("KeyboardFrame: \(keyboardFrame)")