Skip to content

Instantly share code, notes, and snippets.

@yHomework
yHomework / .swift
Created September 20, 2020 20:31
Array Remove Duplicates
import Foundation
extension Array where Element:Equatable {
mutating func removeDuplicates() {
var result = [Element]()
for (key, value) in self.enumerated() {
if result.contains(value) {
self.remove(at: key)
} else {
@yHomework
yHomework / Working-With-XCode
Created September 16, 2020 09:13 — forked from quoha/Working-With-XCode
Using XCode with github
Using XCode with github
=======================
0. These steps were pulled from the documentation on github
1. Create an empty repository on GitHub
do not initialize with a README
2. Note the SSH path to the new repository
git@github.com:quoha/derp-octo-sansa.git
@yHomework
yHomework / Keyboard.swift
Created September 12, 2020 12:21 — forked from nickffox/Keyboard.swift
Adjusting a SwiftUI View for the Keyboard.
import Combine
final class Keyboard: ObservableObject {
// MARK: - Published Properties
@Published var state: Keyboard.State = .default
// MARK: - Private Properties
@yHomework
yHomework / Publisher+Unwrap.swift
Created September 10, 2020 17:21 — forked from rpassis/Publisher+Unwrap.swift
Combine Recipe - Unwrapping an optional type operator
public protocol OptionalType {
associatedtype Wrapped
var value: Wrapped? { get }
}
extension Optional: OptionalType {
public var value: Wrapped? {
return self
}
}
@yHomework
yHomework / ForPerformance.playground
Created September 10, 2020 16:58 — forked from AvdLee/ForPerformance.playground
For each vs for loop performance
//: Playground - noun: a place where people can play
import XCTest
class MyTests: XCTestCase {
lazy var testData: [Int] = {
return (0..<1000).map { Int($0) }
}()
@yHomework
yHomework / DarwinNotificationCenter.swift
Created September 10, 2020 16:55 — forked from AvdLee/DarwinNotificationCenter.swift
A notification center for Darwin Notifications. MIT License applies.
//
// DarwinNotificationCenter.swift
//
// Copyright © 2017 WeTransfer. All rights reserved.
//
import Foundation
/// A Darwin notification payload. It does not contain any userInfo, a Darwin notification is purely event handling.
public struct DarwinNotification {
@yHomework
yHomework / Demo.swift
Created September 7, 2020 05:35 — forked from AliSoftware/Demo.swift
NestableCodingKey: Nice way to define nested coding keys for properties
struct Contact: Decodable, CustomStringConvertible {
var id: String
@NestedKey
var firstname: String
@NestedKey
var lastname: String
@NestedKey
var address: String
enum CodingKeys: String, NestableCodingKey {
import SwiftUI
fileprivate struct MenuButtonView: View {
var body: some View {
MenuButton(color: .white)
.frame(width: 20, height: 20, alignment: .center)
}
}
import Foundation
public extension Dictionary where Key == String, Value == Any {
fileprivate func _get<T>(path: [String]) -> T? {
var root = self
for idx in 0 ..< path.count - 1 {
guard let _root = root[path[idx]] as? [String: Any] else {
return nil
}
@yHomework
yHomework / NestedDecodable.swift
Created June 15, 2020 13:34 — forked from ilyapuchka/NestedDecodable.swift
Decoding nested values with property wrapper
import Foundation
public struct Unit: Codable, Equatable {
init() {}
public init(from decoder: Decoder) {}
public func encode(to encoder: Encoder) throws {}
public static func ==(lhs: Self, rhs: Self) -> Bool {
return true
}
}