This file contains hidden or 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
// The SwiftUI Lab: https://swiftui-lab.com | |
// Article: Inspecting the View Tree – Part 2 | |
// https://swiftui-lab.com/communicating-with-the-view-tree-part-2/ | |
import SwiftUI | |
struct MyTextPreferenceData { | |
let viewIdx: Int | |
var topLeading: Anchor<CGPoint>? = nil | |
var bottomTrailing: Anchor<CGPoint>? = nil |
This file contains hidden or 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 Combine | |
struct AdaptsToSoftwareKeyboard: ViewModifier { | |
@State var currentHeight: CGFloat = 0 | |
func body(content: Content) -> some View { | |
content | |
.padding(.bottom, currentHeight) | |
.edgesIgnoringSafeArea(.bottom) |
This file contains hidden or 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 Combine | |
enum APIError: Error, LocalizedError { | |
case unknown, apiError(reason: String) | |
var errorDescription: String? { | |
switch self { | |
case .unknown: | |
return "Unknown error" |
This file contains hidden or 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 NaturalLanguage | |
let text = "All human beings are born free and equal in dignity and rights. They are endowed with reason and conscience and should act towards one another in a spirit of brotherhood." | |
let tokenizer = NLTokenizer(unit: .word) | |
tokenizer.string = text | |
//let tokenArray = tokenizer.tokens(for: strRange) | |
tokenizer.enumerateTokens(in: text.startIndex..<text.endIndex) { tokenRange, _ in | |
print(text[tokenRange]) | |
return true |
This file contains hidden or 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 UIKit | |
/// A UITextView subclass with placeholder text support. | |
/// It uses another UILabel to show the placeholder, shown when text is empty. | |
class PlaceholderTextView: UITextView { | |
lazy var placeholderLabel: UILabel = { | |
let label = UILabel() | |
label.textColor = UIColor(white: 0.5, alpha: 0.85) | |
label.backgroundColor = .clear |
This file contains hidden or 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 SceneKit | |
class ARQLThumbnailGenerator { | |
private let device = MTLCreateSystemDefaultDevice()! | |
/// Create a thumbnail image of the asset with the specified URL at the specified | |
/// animation time. Supports loading of .scn, .usd, .usdz, .obj, and .abc files, | |
/// and other formats supported by ModelIO. |
This file contains hidden or 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
// | |
// XCUIElement+GentleSwipe.swift | |
// | |
// Created by Robin Spinks on 11/10/2017. | |
// | |
import Foundation | |
import XCTest | |
extension XCUIElement |
This file contains hidden or 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 | |
struct User: Decodable { | |
let name: String | |
let age: Int? | |
// private enum CodingKeys: String, CodingKey { | |
// case name | |
// case NAME | |
// } |
This file contains hidden or 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 PlaygroundSupport | |
class WLCollectionCell: UICollectionViewCell { | |
required init?(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
This file contains hidden or 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
// Inspired by: http://stackoverflow.com/questions/4147311/finding-image-type-from-nsdata-or-uiimage/5042365#5042365 | |
import Foundation | |
enum DocumentType: String { | |
case jpeg = "image/jpeg" | |
case png = "image/png" | |
case gif = "image/gif" | |
case tiff = "image/tiff" |