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
// | |
// FacebookAuth.swift | |
// GitHub: ethanhuang13 | |
// Twitter: @ethanhuang13 | |
import AuthenticationServices | |
import SafariServices | |
/* | |
Updated: |
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
// | |
// VirtualKeyboard.swift | |
// MacBook Air M1 Zhuyin Keyboard | |
// Written with SwiftUI ~=300 LOC, < 4hrs | |
// Created by Ethan Huang on 2021/1/13. | |
// Twitter: @ethanhuang13 | |
import SwiftUI | |
struct VirtualKeyboard: View { |
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
// iOS 17's JSONEncoder is rarely producing a different key sorting order(< 5%), which is ok for JSON itself, but will cause flaky tests. | |
// It wasn't happened pre-iOS 17. | |
// https://mastodon.social/@ethanhuang13/110904915670262949 | |
import XCTest | |
final class JSONEncoderTests: XCTestCase { | |
func testEncode() { | |
struct Model: Codable { | |
var a: String = "" |
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
@ViewBuilder | |
private func build<#name#>(_ viewStore: ViewStoreType) -> some View { | |
} |
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
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/13.2/ /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport | |
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/WatchOS.platform/DeviceSupport/6.1/ /Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/DeviceSupport | |
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/AppleTVOS.platform/DeviceSupport/13.2/ /Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/DeviceSupport |
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
extension UIView { | |
func isPossiblyVisible() -> Bool { | |
guard isHidden == false, | |
alpha > 0, | |
bounds != .zero, | |
let window = window, // In a window's view hierarchy | |
window.isKeyWindow, // Does not consider cases covered by another transparent window | |
window.hitTest(convert(center, to: nil), with: nil) != self | |
else { return false } |
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
// | |
// ContentView.swift | |
// ErrorAlert | |
// | |
// Created by Ethan Huang on 2022/6/4. | |
// | |
import SwiftUI | |
enum AError: Error { |
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 | |
// | |
// The result is not guaranteed to be accurate. Typically, the function requires 200-400 characters to reliably guess the language of a string. | |
// Reference: [CFStringTokenizerCopyBestStringLanguage(_:_:)](https://developer.apple.com/reference/corefoundation/1542136-cfstringtokenizercopybeststringl) | |
// | |
import Foundation | |
extension String { | |
func guessLanguage() -> String { |
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 challenge from https://twitter.com/hanyu_chen_ios/status/1395533041989079045 | |
// Screenshots of performance tests https://twitter.com/ethanhuang13/status/1395577548151541760?s=21 | |
import XCTest | |
let maxValue = 100 | |
let minValue = 0 | |
final class ClampTests: XCTestCase { | |
func testMeasureNaiveCompare() throws { |
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
// An (useless) example of Swift 4.2 @dynamicMemberLookup attributes. | |
// let color1 = HexColor().cbcbcb | |
// let color2 = HexColor().000000 // This can also be built. Will be treat as "000000" | |
import Foundation | |
@dynamicMemberLookup | |
struct HexColor { | |
subscript(dynamicMember member: String) -> UIColor? { | |
do { |
NewerOlder