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 LinkPresentation | |
import Combine | |
extension LPMetadataProvider { | |
func startFetchingMetadataPublisher(for url: URL) -> AnyPublisher<LPLinkMetadata?, Error> { | |
Future<LPLinkMetadata?, Error> { completion in | |
self.startFetchingMetadata(for: url) { meta, error in | |
guard let error = error else { | |
return completion(.success(meta)) | |
} |
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
/* | |
Copyright © 2020 Apple Inc. | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR O |
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 | |
class BaseImageView: UIView{ | |
var roundedShape = CAShapeLayer() | |
var curvedPath: UIBezierPath! | |
var shapeColor: UIColor! | |
var circular: Bool! | |
var shadow: Bool! |
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
/* | |
iPadは縦横どちらの向きでもUIUserInterfaceSizeClassが.regularなので、AutoLayoutのOrientationによる表示変更ができない。 | |
以下のコードを必要なViewControllerに書いておくと`.regular × .compact`と判断するようになりiPhoneと同じルールでレイアウトできる。 | |
*/ | |
// MARK: - Trick for iPad device orientation | |
override public var traitCollection: UITraitCollection { | |
let device = UIDevice.current | |
let result: UITraitCollection |
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
// https://forums.swift.org/t/support-for-date/34797/2?u=griffin-stewie | |
func parseDate(_ formatter: DateFormatter) -> (String) throws -> Date { | |
{ arg in | |
guard let date = formatter.date(from: arg) else { | |
throw ValidationError("Invalid date") | |
} | |
return date | |
} | |
} |
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 | |
// O(n^2) | |
public extension Array where Element: Equatable { | |
/// Remove duplicated elements | |
/// Complexity: O(n^2), where n is the length of the sequence. | |
/// - Returns: A new Array containing those elements from self that are not duplicates | |
func unique() -> Array<Element> { | |
return reduce(into: []) { (array, r) in |
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 Cocoa | |
import Combine | |
class Timer: Cancellable, Publisher { | |
enum Error: Swift.Error { | |
case cancelled | |
} | |
typealias Output = Never | |
typealias Failure = 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
struct Contact: Decodable, CustomStringConvertible { | |
var id: String | |
@NestedKey | |
var firstname: String | |
@NestedKey | |
var lastname: String | |
@NestedKey | |
var address: String | |
enum CodingKeys: String, NestableCodingKey { |
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
#!/bin/sh | |
basename=`basename $0` | |
if [ -z "$*" ]; then | |
echo "usage: ${basename} <dot> [ -o | -r | <file> | - ]" | |
echo "" | |
echo "options:" | |
echo " -o open dot in window with keyboard focus" | |
echo " -r read contents of dot" |
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
@propertyWrapper | |
class YORO<T> { | |
private var value: T? | |
var wrappedValue: T? { | |
get { | |
let result = value | |
value = .none | |
return result | |
} | |
set { |