Skip to content

Instantly share code, notes, and snippets.

View eonist's full-sized avatar
🎯
Focusing

André J eonist

🎯
Focusing
View GitHub Profile
@emckee4
emckee4 / Range+Extensions.swift
Created January 12, 2017 22:23
Prospective Range+Extensions for swift 3 intensityAttributingKit
//
// Range+Extensions.swift
// IntensityAttributingKit
//
// Created by Evan Mckee on 3/23/16.
// Copyright © 2016 McKeeMaKer. All rights reserved.
//
import Foundation

Using Swift Package Manager with iOS

Step 1:

File > New > Project...

Step 2:

Create a Package.swift file in your root project directory, add dependencies, then run swift package fetch on the command line in the same directory. We’re not going to run swift build because it will just complain.

@seckincengiz
seckincengiz / ExampleUsage.swift
Last active July 10, 2018 19:21 — forked from s-aska/Keychain.swift
Swift Keychain class ( supported Xcode 8.1 Beta and IOS 10.1 ) [swift3]
import UIKit
let scoresStringArray : [String] = ["Mike","Tom","Bily"]
let scoresDataArray = NSKeyedArchiver.archivedData(withRootObject: scoresStringArray)
//Save data
_ = Keychain.save(key: "scoresKey", data: scores)
//Load data
if Keychain.load(key: "scoresKey") != nil{
@russbishop
russbishop / TypeErasure.swift
Last active May 18, 2022 01:20
Type erasure with multiple adopting types
// Paste me into a playground!
import Cocoa
//: # Basic Setup
protocol FancyProtocol {
associatedtype Thing
func holdPinkyUp(x: Thing)
}
//: [Previous](@previous)
import AppKit
import XCPlayground
extension NSLayoutConstraint {
convenience init(view item: NSView, to toItem: NSView, attribute: NSLayoutAttribute, constant c: CGFloat = 0) {
self.init(item: item, attribute: attribute,
relatedBy: .Equal,
toItem: toItem, attribute: attribute,
multiplier: 1.0, constant: c)
@danimal141
danimal141 / TypeErasure.swift
Last active March 9, 2017 09:47 — forked from gwengrid/TypeErasure.swift
Example of type erasure with Pokemon
class Thunder { }
class Fire { }
protocol Pokemon {
typealias PokemonType
func attack(move: PokemonType)
}
struct Pikachu: Pokemon {
typealias PokemonType = Thunder
@gwengrid
gwengrid / TypeErasure.swift
Last active September 12, 2018 05:14
Example of type erasure with Pokemon
class Thunder { }
class Fire { }
protocol Pokemon {
typealias PokemonType
func attack(move:PokemonType)
}
struct Pikachu: Pokemon {
typealias PokemonType = Thunder
@sohayb
sohayb / ArrayDeepCopy.swift
Last active October 13, 2023 07:58
Array deep copy in Swift
//Protocal that copyable class should conform
protocol Copying {
init(original: Self)
}
//Concrete class extension
extension Copying {
func copy() -> Self {
return Self.init(original: self)
}
@joepie91
joepie91 / monolithic-vs-modular.md
Last active August 2, 2023 08:17
Monolithic vs. modular - what's the difference?

When you're developing in Node.js, you're likely to run into these terms - "monolithic" and "modular". They're usually used to describe the different types of frameworks and libraries; not just HTTP frameworks, but modules in general.

At a glance

  • Monolithic: "Batteries-included" and typically tightly coupled, it tries to include all the stuff that's needed for common usecases. An example of a monolithic web framework would be Sails.js.
  • Modular: "Minimal" and loosely coupled. Only includes the bare minimum of functionality and structure, and the rest is a plugin. Fundamentally, it generally only has a single 'responsibility'. An example of a modular web framework would be Express.

Coupled?

In software development, the terms "tightly coupled" and "loosely coupled" are used to indicate how much components rely on each other; or more specifically, how many assumptions they make about each other. This directly translates to how easy it is to repla

func openAndSelectFile(filename:String){
let files = [NSURL(fileURLWithPath: filename)];
NSWorkspace.sharedWorkspace().activateFileViewerSelectingURLs(files);
}