Skip to content

Instantly share code, notes, and snippets.

@mattyoung
mattyoung / DearSteve.txt
Last active January 26, 2016 22:42
Solution to the encryption conundrum
Dear Steve,
It's a impossible task for Apple and the likes to maintain a
store of device decryption keys.Where should these keys be stored?
China will not trust the US to hand over the keys. So China
will demand Apple to store the keys within its border.
According to the language of "manufactured… and sold", then
this means China can demand Apple to store all the keys
inside China and be readily available to the government
without any warrant as netizens of China have no privacy rights.
@mattyoung
mattyoung / leaderBoardStruct.swift
Created January 3, 2016 05:11
weheartswift.com Dictionary Excercise 11.6 Leaderboard with struct
struct Person {
let firstName: String
let lastName: String
let score: Int
}
var people: [Person] = [
Person(
firstName: "Calvin",
lastName: "Newton",
import Foundation
struct Person: Codable {
let name: String
}
let person = Person(name: "Paul")
if #available(macOS 10.12, *) {
import QuartzCore
// make an Int array of random elements
let array = Array((1...2000).map { _ in Int(arc4random_uniform(2000)) } )
let loopCount = 100_000
// closure in a variable
let compareGreater: (Int, Int) -> Bool = { $0 > $1 }
@mattyoung
mattyoung / leaderBoard.swift
Last active December 29, 2017 17:44
weheartswift.com Dictionary Excercise 11.6 Leaderboard
var people: [[String:Any]] = [
[
"firstName": "Calvin",
"lastName": "Newton",
"score": 13
],
[
"firstName": "Garry",
"lastName": "Mckenzie",
"score": 23
@mattyoung
mattyoung / AnimatedSlashSpeakerDemo.swift
Last active December 29, 2019 18:35
iOS Control Center volume widget slash animation
import SwiftUI
struct AnimatedSlashSpeakerDemo: View {
// 0 mute is off, 1 mute is on
@State private var muteState: CGFloat = 0
private static let imageDimension: CGFloat = 250
var body: some View {
ZStack {
LinearGradient(gradient: Gradient(colors: [.pink, .orange, .blue, .red, .green, .purple, .yellow]), startPoint: .topLeading, endPoint: .bottomTrailing)
// WARNING: this only works in Xcode 11.4 beta 2
// .minimumScaleFactor() is broken before and after
import SwiftUI
struct BigText: View {
private static let fontSize: CGFloat = 120
@State private var margin: CGFloat = 0
import SwiftUI
struct CheckboxToggleStyle: ToggleStyle {
@Environment (\.isEnabled) var isEnabled
func makeBody(configuration: Configuration) -> some View {
HStack {
configuration.label
Image(systemName: configuration.isOn ? "checkmark.square" : "square")
import SwiftUI
struct UndoRightToLeftMirroring: ViewModifier {
// @Environment(\.layoutDirection) var layoutDirection
// @ViewBuilder
func body(content: Content) -> some View {
content // !!! Just do this undo the mirroring
// VStack {
// if layoutDirection == .leftToRight {
import SwiftUI
struct NavViewFormLabelRightJustified: View {
@State private var width = 25
@State private var height = 50
@State private var updatePeriod: Double = 1.0
var body: some View {
NavigationView {
Form {