Skip to content

Instantly share code, notes, and snippets.

Working from home

Zeeshan Khan zeeshankhan

Working from home
View GitHub Profile
View webview-inject-javascript-full.swift
import UIKit
import WebKit
class ViewController: UIViewController {
override func viewDidLoad() {
// Configure the web view for JavaScript injection
ole / UIAlertController+TextField.swift
Last active Apr 24, 2021
A UIAlertController with a text field and the ability to perform validation on the text the user has entered while the alert is on screen. The OK button is only enabled when the entered text passes validation. More info:
View UIAlertController+TextField.swift
import UIKit
/// A validation rule for text input.
public enum TextValidationRule {
/// Any input is valid, including an empty string.
case noRestriction
/// The input must not be empty.
case nonEmpty
/// The enitre input must match a regular expression. A matching substring is not enough.
case regularExpression(NSRegularExpression)
shaps80 / 1. UserDefaults+Key.swift
Last active Sep 25, 2020
Adds a Swift extension to make UserDefaults more consistent to work with.
View 1. UserDefaults+Key.swift
// UserDefaults.swift
// Created by Shaps Benkau on 24/05/2018.
// Copyright © 2018 152percent Ltd. All rights reserved.
import Foundation
#if os(iOS)
kharrison / RSSFeed.swift
Last active Sep 1, 2021
Swift Decodable With Multiple Custom Dates
View RSSFeed.swift
import Foundation
extension DateFormatter {
static let iso8601Full: DateFormatter = {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
formatter.calendar = Calendar(identifier: .iso8601)
formatter.timeZone = TimeZone(secondsFromGMT: 0)
formatter.locale = Locale(identifier: "en_US_POSIX")
return formatter
DejanEnspyra / polygon.swift
Created Oct 3, 2017
Polygon Google Maps iOS SDK
View polygon.swift
func polygon(){
// Create a rectangular path
let rect = GMSMutablePath()
rect.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.0))
rect.add(CLLocationCoordinate2D(latitude: 37.45, longitude: -122.0))
rect.add(CLLocationCoordinate2D(latitude: 37.45, longitude: -122.2))
rect.add(CLLocationCoordinate2D(latitude: 37.36, longitude: -122.2))
// Create the polygon, and assign it to the map.
let polygon = GMSPolygon(path: rect)
View letteranimation.swift
import UIKit
import PlaygroundSupport
// Original Video:
// Video:
// Video: (with zoom and fade)
// String to animate and its attributes
var string = "Hello, playground"
let attributes: [String: Any] = [
damianesteban / result.swift
Last active Nov 13, 2016
Swift 3 updated code with simple examples from this fantastic article:
View result.swift
// A Gist.
struct Gist {
let id: String
typealias JSONDictionary = [String: AnyObject]
// These methods are "helpers" to transform Data -> JSON -> Result<[Gist]>
func jsonFrom(data: Data) -> Result<AnyObject> {
let json = try! JSONSerialization.jsonObject(with: data, options: [])
rnapier / gist:5c80d113895a796fc17b
Last active Feb 3, 2018
Wrapping funcs into protocols
View gist:5c80d113895a796fc17b
Stuff from [Crustacean](
(Wish I could hide this in a single-file playground somehow.)
import CoreGraphics
protocol Renderer {
func moveTo(position: CGPoint)
func lineTo(position: CGPoint)
func arcAt(center: CGPoint, radius: CGFloat, startAngle: CGFloat, endAngle: CGFloat)
AliSoftware / struct_vs_inheritance.swift
Last active May 11, 2022
Swift, Struct & Inheritance: How to balance the will of using Struct & Value Types and the need for Inheritance?
View struct_vs_inheritance.swift
// #!Swift-1.1
import Foundation
// MARK: - (1) classes
// Solution 1:
// - Use classes instead of struct
// Issue: Violate the concept of moving model to the value layer