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
import SwiftUI | |
struct MaskedCornerRoundedRectangle: Shape { | |
let topLeadingRadius: CGFloat | |
let bottomLeadingRadius: CGFloat | |
let bottomTrailingRadius: CGFloat | |
let topTrailingRadius: CGFloat | |
init(topLeadingRadius: CGFloat = 0, bottomLeadingRadius: CGFloat = 0, bottomTrailingRadius: CGFloat = 0, topTrailingRadius: CGFloat = 0) { | |
self.topLeadingRadius = topLeadingRadius |
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
struct LayoutGenerator { | |
static func generate(handler: @escaping (Int) -> NSCollectionLayoutSection?) -> UICollectionViewCompositionalLayout { | |
return .init { section, environment in | |
handler(section) | |
} | |
} | |
} | |
struct SectionLayoutGenerator { | |
static func carousel(width: CGFloat, height: CGFloat, spacing: CGFloat = 8) -> NSCollectionLayoutSection { |
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 DateFormatter { | |
/** | |
SeeAlso: | |
[Date Field Symbol Table](http://www.unicode.org/reports/tr35/tr35-25.html#Date_Field_Symbol_Table) | |
*/ | |
enum Template: String, CaseIterable { | |
/** | |
Era - Replaced with the Era string for the current date. One to three letters for the abbreviated form, four letters for the long form, five for the narrow form. | |
*/ | |
case G |
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
protocol Api { | |
var path: String { get } | |
} | |
struct QiitaApi: Api { | |
var path: String { | |
protocolName + domain + "/" + version + "/" + directory | |
} | |
private let protocolName = "https://" |
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
func hit(percent: Float) -> Bool { | |
let max = Int(100 / fabsf(percent)) | |
let value = Int.random(in: 1 ... max) | |
return value == 1 | |
} |
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
// MARK: - get | |
extension UserDefaults { | |
/** | |
-objectForKey: will search the receiver's search list for a default with the key 'defaultName' and return it. If another process has changed defaults in the search list, NSUserDefaults will automatically update to the latest values. If the key in question has been marked as ubiquitous via a Defaults Configuration File, the latest value may not be immediately available, and the registered value will be returned instead. | |
*/ | |
public func object<T: RawRepresentable>(forKey defaultName: T) -> Any? where T.RawValue == String { | |
UserDefaults.standard.object(forKey: defaultName.rawValue) | |
} | |
/// -stringForKey: is equivalent to -objectForKey:, except that it will convert NSNumber values to their NSString representation. If a non-string non-number value is found, nil will be returned. |
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 UITableView { | |
func dequeueReusableCell<ROW: Identifiable>(with row: ROW, for indexPath: IndexPath) -> UITableViewCell where ROW.ID == String { | |
return self.dequeueReusableCell(withIdentifier: row.id, for: indexPath) | |
} | |
} |
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
struct DataProvider<T: Decodable> { | |
let function: (@escaping (Result<T, Error>) -> Void) -> Void | |
func completion(_ completion: @escaping (Result<T, Error>) -> Void) { | |
function(completion) | |
} | |
} |
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
enum SaizeriyaMenuCategory: String, Codable { | |
case saladSoup = "サラダ・スープ" | |
case appetizer = "前菜・おつまみ" | |
case fromItalyWine = "イタリアの味・ワイン" | |
case pizza = "ピザ" | |
case pasta = "パスタ" | |
case doriaRice = "ドリア・米料理" | |
case hamburgSteak = "肉料理" | |
case dessert = "デザート" |
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
struct TextAlertController { | |
func create(title: String, message: String, preferredStyle: UIAlertController.Style = .alert, defaultText: String? = nil, completion: @escaping (String?) -> Void) -> UIAlertController { | |
let actionController = UIAlertController(title: title, message: message, preferredStyle: preferredStyle) | |
let ok = UIAlertAction(title: "OK", style: .default, handler: { [weak actionController] (_) -> Void in | |
guard let textField = actionController?.textFields?.first else { | |
completion(nil) | |
return | |
} | |
NewerOlder