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
// collections | |
let filtered = string.filter { $0 != "🙀" } | |
// substrings | |
let substring = string[index...] | |
// multi line literals |
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
/* | |
* TableViewcontroller.swift | |
*/ | |
import UIKit | |
class TableViewcontroller: UIViewController, UITableViewDataSource, UITableViewDelegate { | |
// MARK: - PROPERTIES |
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
//: Playground - noun: a place where people can play | |
import UIKit | |
import Foundation | |
import PlaygroundSupport | |
// so we can run asynchronous code in a playground | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
let iso8601Full: DateFormatter = |
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 UIKit | |
@objc class CollectionViewLayout: UICollectionViewLayout { | |
var contentSize: CGSize = .zero | |
var cachedAttributes = [IndexPath: UICollectionViewLayoutAttributes]() | |
override func prepare() { | |
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 CryptoKit | |
import Foundation | |
let path = Bundle.main.path(forResource: "video", ofType: "mp4")! | |
let data = FileManager.default.contents(atPath: path)! | |
let digest = SHA256.hash(data: data) | |
print(digest) |
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
var hasher = SHA256() | |
let path = Bundle.main.path(forResource: "video", ofType: "mp4")! | |
let stream = InputStream(fileAtPath: path)! | |
stream.open() | |
let bufferSize = 512 | |
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: bufferSize) | |
while stream.hasBytesAvailable { | |
let read = stream.read(buffer, maxLength: bufferSize) |
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 key = SymmetricKey(size: .bits256) | |
let path = Bundle.main.path(forResource: "video", ofType: "mp4")! | |
let data = FileManager.default.contents(atPath: path)! | |
// To encrypt | |
let encryptedData = try! ChaChaPoly.seal(data, using: key) | |
// To decrypt | |
let sealedBox = try! ChaChaPoly.SealedBox(combined: encryptedData) |
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 privateKey = Curve25519.Signing.PrivateKey() | |
let publicKey = privateKey.publicKey // publicize freely | |
let publicKeyData = publicKey.rawRepresentation | |
let signingPublicKey = try! Curve25519.Signing.PublicKey(rawRepresentation: publicKeyData) | |
// sign some data with your private key | |
let data = "All your base are belong to us".data(using: .utf8)! | |
let signature = try! privateKey.signature(for: data) | |
if signingPublicKey.isValidSignature(signature, for: data) { |
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 path = Bundle.main.path(forResource: "video", ofType: "mp4")! | |
let data = FileManager.default.contents(atPath: path)! | |
let key = SymmetricKey(size: .bits256) // key shared by both parties | |
let authentication = HMAC<SHA256>.authenticationCode(for: data, | |
using: key) | |
let authenticationData = Data(authentication) | |
// ~~~~~~ travel accross the network ~~~~~~~ | |
if (HMAC<SHA256>.isValidAuthenticationCode(authenticationData, |
OlderNewer