Skip to content

Instantly share code, notes, and snippets.

View Abizern's full-sized avatar
🎧
Working from home

Abizer Nasir Abizern

🎧
Working from home
View GitHub Profile
@sdarlington
sdarlington / fizzbuzz.swift
Last active August 29, 2015 14:03
FizzBuzz
import Foundation
func genericFizzBuzz<T> (number:T, tests:Array<(T)->String?>) -> String {
// Run each of the defined test replacements
let out = tests.map { t in t(number) }
// convert the nil's to empty strings
.map { v in v ?? "" }
// Concatenate all the replacements together
.reduce("", combine: +)
@samdeane
samdeane / GlobalSettings.plist
Created August 2, 2012 16:25
Script for generating appledoc docs
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>--project-company</key>
<string>Elegant Chaos</string>
<key>--company-id</key>
<string>com.elegantchaos</string>
<key>--keep-undocumented-objects</key>
<false/>
@douglashill
douglashill / LocalisedStrings.swift
Last active September 17, 2018 09:02
Generating an enum to ensure only defined localised string keys are used. For development on Apple platforms.
// Douglas Hill, February 2018
import Foundation
/// Returns a localised string with the key as an enum case so the compiler checks it exists.
/// The enum should be automatically generated using UpdateLocalisedStringKeys.swift.
public func localisedString(_ key: LocalisedStringKey) -> String {
return Bundle.main.localizedString(forKey: key.rawValue, value: nil, table: nil)
}
@erica
erica / gist:fa6c8f02f488d79c9644
Last active December 6, 2018 05:34
Nib Support
/*
ericasadun.com
Playground Support for NIB-based interaction: Add to playground's Sources folder
*/
import Cocoa
import XCPlayground
@danielctull
danielctull / UICollectionViewFlowLayout+DelegateAccess.swift
Last active May 16, 2019 14:00
Wraps the six UICollectionViewFlowLayout delegate methods and their equivalent properties using functional programming techniques, so that values are easier to retrieve. Full details at: http://danieltull.co.uk/blog/2018/04/13/simplifying-uicollectionviewflowlayout-delegate-method-usage-with-functional-programming/
extension UICollectionViewFlowLayout {
typealias DelegateMethod<Key, Value> = ((UICollectionView, UICollectionViewLayout, Key) -> Value)
private var delegate: UICollectionViewDelegateFlowLayout? {
return collectionView?.delegate as? UICollectionViewDelegateFlowLayout
}
func retrieve<Key, Value>(
@paulweichhart
paulweichhart / Template.swift
Created December 8, 2019 20:10
SwiftUI Playground Template
import Foundation
import PlaygroundSupport
import SwiftUI
struct Content: View {
var body: some View {
Text("👋🏻, 🌍!")
}
}
@jeremiegirault
jeremiegirault / UILayoutPriority+operations.swift
Created June 11, 2017 19:03
Helpers for UILayoutPriority for swift 4
extension UILayoutPriority: ExpressibleByFloatLiteral, ExpressibleByIntegerLiteral {
public init(floatLiteral value: Float) {
self.init(rawValue: value)
}
public init(integerLiteral value: Int) {
self.init(rawValue: Float(value))
}
public static func +(lhs: UILayoutPriority, rhs: UILayoutPriority) -> UILayoutPriority {
@kristopherjohnson
kristopherjohnson / SystemLog.swift
Last active November 6, 2020 05:59
Demo of using the Apple System Log (ASL) API from Swift
// Note: This must be used in an Xcode project that contains a bridging header
// that includes <asl.h>
import Foundation
/// Provides high-level methods to access the raw data in
/// an ASL message.
struct SystemLogEntry {
/// Key-value pairs read from ASL message
let data: [String : String]
@gwengrid
gwengrid / FurtherReading.md
Last active May 25, 2022 09:23
Type Erasure Further Reading
@CodaFi
CodaFi / alltheflags.md
Last active October 26, 2022 20:09
Every Option and Flag /swift (1.2) Accepts Ever

#Every Single Option Under The Sun

  • optimization level options
  • automatic crashing options
  • debug info options
  • swift internal options
  • swift debug/development internal options
  • linker-specific options
  • mode options