Skip to content

Instantly share code, notes, and snippets.

View pradeepb28's full-sized avatar
🎯
Focusing

pradeep pradeepb28

🎯
Focusing
View GitHub Profile
@TyrfingMjolnir
TyrfingMjolnir / README.convert_iOS_icon.md
Last active February 26, 2019 06:23
Convert 1 image 2048x2048 to all needed sizes for an iOS app
@parrotbait
parrotbait / gist:a2b632a057a98f05230e554b11a6c590
Last active January 18, 2019 17:01
Some good iOS Dev Accounts to follow
@parrotbait
parrotbait / UniqueNos.swift
Created January 17, 2019 11:16
Algorithm to determine if a string has all unique characters. What if you cannot use any additional data structures?
import UIKit
// This code is based on implementing the following:
// Implement an algorithm to determine if a string has all unique characters. What if you cannot use any additional data structures?
extension Character {
func toString() -> String {
return String(self)
}
}
@IanKeen
IanKeen / Debounce.swift
Created January 16, 2019 19:13
Simple debouncer
func debounce<T>(delay: TimeInterval, function: @escaping (T) -> Void, complete: @escaping () -> Void = { }) -> (T) -> Void {
let queue = DispatchQueue(label: "Debouncer")
var current: DispatchWorkItem?
return { input in
current?.cancel()
let new = DispatchWorkItem {
function(input)
complete()
}
@IanKeen
IanKeen / Coordinator.swift
Last active April 13, 2020 23:26
Segue<Destination> to tame Storyboard segues
//
// Coordinator
//
// Created by Ian Keen.
// Copyright © 2018 Ian Keen. All rights reserved.
//
import ObjectiveC
import UIKit
@IanKeen
IanKeen / EncodableDictionary.swift
Last active April 13, 2019 18:37
Type-safe Encodable Dictionary - useful for building quick dynamic Encodable packets
public struct EncodableDictionary {
typealias EncodingFunction = (inout KeyedEncodingContainer<AnyCodingKey>) throws -> Void
// MARK: - Private Properties
private var data: [String: Any] = [:]
private var encodings: [String: EncodingFunction] = [:]
// MARK: - Lifecycle
public init() { }
@chriseidhof
chriseidhof / parsers.swift
Last active December 28, 2020 04:36
Faster Parsers
//
// Operators.swift
// FastParsing
//
// Created by Chris Eidhof on 26/12/2016.
// Copyright © 2016 objc.io. All rights reserved.
//
// TODO: give appropriate credit. Many parts were stolen from SwiftParsec.
@hollance
hollance / eliza.swift
Last active August 12, 2024 15:26
The classic ELIZA chat bot in Swift.
/*
Joseph Weizenbaum's classic ELIZA chat bot in Swift.
Based on the IBM PC BASIC program from CREATIVE COMPUTING by Patricia
Danielson and Paul Hashfield, and the Java adaptation by Jesper Juul.
Run this script from Terminal:
$ swift eliza.swift
Press Ctrl-C or Ctrl-D to quit. (Or type "shut up".)
@joshavant
joshavant / UITextView+HeightCalculation.swift
Created July 21, 2016 03:00
UITextView Height Calculation
extension UITextView {
// Note: This will trigger a text rendering!
func calculateViewHeightWithCurrentWidth() -> CGFloat {
let textWidth = self.frame.width -
self.textContainerInset.left -
self.textContainerInset.right -
self.textContainer.lineFragmentPadding * 2.0 -
self.contentInset.left -
self.contentInset.right
@gonzalezreal
gonzalezreal / ios-cell-registration-swift.md
Last active March 13, 2024 15:18
iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

iOS Cell Registration & Reusing with Swift Protocol Extensions and Generics

A common task when developing iOS apps is to register custom cell subclasses for both UITableView and UICollectionView. Well, that is if you don’t use Storyboards, of course.

Both UITableView and UICollectionView offer a similar API to register custom cell classes:

public func registerClass(cellClass: AnyClass?, forCellWithReuseIdentifier identifier: String)
public func registerNib(nib: UINib?, forCellWithReuseIdentifier identifier: String)