Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://code.jquery.com/jquery.min.js"></script>
<style id="jsbin-css">
body {
margin: 0;
@devjangir
devjangir / Stack.swift
Last active February 27, 2020 11:25
Generic Stack Implementation using protocol approach
import CoreFoundation
//Generic Type Protocol
public protocol Stackable {
//Generic Type
associatedtype E
// Push - add new element to stack array
mutating func push(_ element: E)
@devjangir
devjangir / Enum.swift
Last active June 13, 2017 11:59
Working with Enums ( Add functions using Protocol )
// A Protocol that has update function to update Device State
protocol State {
// function is mutating so that Enum and structure can update the self
mutating func update()
}
// Enum wit Active and Inactive Device state
enum DeviceState : State {
@devjangir
devjangir / currency.swift
Last active April 2, 2017 17:32
Use NSNumberFormatter in Swift to Make Currency Numbers Easy to Read
var currencyFormatter = NumberFormatter()
currencyFormatter.usesGroupingSeparator = true
currencyFormatter.numberStyle = NumberFormatter.Style.currency
// localize to your grouping and decimal separator
// set locale to Spanish
currencyFormatter.locale = Locale(identifier: "eu_ES")
var priceString = currencyFormatter.string(from: 12.50)
print(priceString) //output : ("12,50 €")
// set locale to US