This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A { | |
var x = "a" | |
} | |
var a: A = A() | |
isUniquelyReferencedNonObjC(&a) | |
var b = a | |
isUniquelyReferencedNonObjC(&a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol QueueType { | |
typealias Element | |
mutating func enqueue(element: Element) | |
mutating func dequeue() -> Element? | |
func peek() -> Element? | |
} | |
final class Storage<Element> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Check If a string has all unique characters, without using additional data structure. | |
func isUnique(string: String) -> Bool { | |
// what type of characters // if ascii characters | |
if string.characters.count > 128 { | |
return true | |
} | |
var cIdx = 0 | |
for c in string.characters { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let staionary = ["Black Pen", "Blue Pen", "Red Pen", "Green Pen", "Notebook", "Science Book", "Physics Book", "Maths Book", "CD", "Laptop", "Flopy Disk", "Keyboard", "Mouse", "mac OS", "iOS", "LinuxOS", "AndroidOS", "tvOS", "watchOS", "WindowsOS", "iPad", "iPhone", "iPod"] | |
let books = staionary.filter { (item: String) -> Bool in | |
return item.containsString("Book") | |
} | |
let pens = staionary.filter { (item) in | |
return item.containsString("Pen") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
let x: String? = nil | |
let y: String? = "Hello Y" | |
switch (x,y) { | |
case (.some(let a), .some(let b)): | |
print("So \(a) and \(b)") | |
case (.none, .none): | |
print("None") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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: []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import XCPlayground | |
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true | |
typealias JSONDictionary = [String: Any] | |
enum SomeError : Error { | |
case zoError | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// How to: | |
// 1. Go in the Firebase Analytics Dashboard | |
// 2. Filter iOS Platform only | |
// 3. Scroll down, select `Device` under the "What is your audience like?" widget | |
// 4. Export the CSV data (top right of the corner, there's a `...` menu with Download CSV option) | |
// 5. Open the file and select the iOS breakdown raw data | |
// 6. Replace your data with the sample data in this script | |
// 7. Run the script in a Xcode Playground | |
// 8. See the terminal output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Open Terminal.app. | |
# 2. Type "cd Desktop" and Enter. | |
# 3. Type "open ~/Library/Safari/ ." and Enter. | |
# 4. Copy `Bookmarks.plist` file to the Desktop. | |
# 5. Back to the Terminal, type "ruby safari-readling-list-to-instapaper-csv.rb" and Enter. | |
# 6. Open Instapaper Settings (https://www.instapaper.com/user), and select "Import from Instapaper CSV." | |
# 7. Upload `instapaper-import.csv` from the Desktop. | |
require "plist" | |
require 'csv' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import PlaygroundSupport | |
struct ContentView: View { | |
@State var gradientAngle: Double = 0 | |
var colors = [ | |
Color(UIColor.systemRed), | |
Color(UIColor.systemOrange), | |
Color(UIColor.systemYellow), | |
Color(UIColor.systemGreen), |
OlderNewer