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
| /// <summary> | |
| /// Joins two 16bit integers to a single 32bit value. | |
| /// </summary> | |
| /// <param name="int1">The integer to use for the high bits.</param> | |
| /// <param name="int2">The integer to use for the low bits.</param> | |
| /// <returns>An unsigned 32bit integer.</returns> | |
| public static UInt32 Join(this UInt16 int1, UInt16 int2) | |
| { | |
| return (uint) ((int1 << 16) | int2); | |
| } |
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
| // This is a live template for the JetBrains Rider IDE. It creates the boilerplat BindableProperty code. | |
| // In the C# section of Live Templates, add a new template. I called it "bindProp", but you can give it whatever | |
| // name you'll remember. Edit the variables and ensure that the order is 1) propertyName, 2) propertType, and 3) className. | |
| // Set the className variable to "Not editable" and change its macro to "Containing type name". | |
| // Now, typing bindProp will offer the Live Template you created as a completion option. | |
| public static readonly BindableProperty $propertyName$Property = BindableProperty.Create(nameof($propertyName$), typeof($propertyType$), typeof($className$), $END$); public $propertyType$ $propertyName$ | |
| { | |
| get => ($propertyType$)GetValue($className$.$propertyName$Property); | |
| set => SetValue($className$.$propertyName$Property, value); |
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
| // Bool+Integer.swift | |
| // Attribution 4.0 International (CC 4.0), see bottom for license details. | |
| // https://gist.github.com/dnedrow/de0eb8869e3909df595590a7e2404b47 | |
| import Foundation | |
| /// This extension enables the following behavior: | |
| /// let x = Bool(5) // true | |
| /// let y = Bool(0) // false | |
| /// let z = Bool(-1) // false |
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
| // | |
| // Queue.swift | |
| // StackQueueVisualDemo | |
| // | |
| // Created by Alexey Danilov on 23.05.2018. | |
| // Copyright © 2018 danilovdev. All rights reserved. | |
| // | |
| // FIFO - First In First Out | |
| struct Queue<T> { |
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
| // | |
| // Stack.swift | |
| // StackQueueVisualDemo | |
| // | |
| // Created by Alexey Danilov on 23.05.2018. | |
| // Copyright © 2018 danilovdev. All rights reserved. | |
| // | |
| // LIFO - Last In First Out | |
| struct Stack<T> { |
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
| #ifdef _WIN64 | |
| //define something for Windows (64-bit) | |
| #elif _WIN32 | |
| //define something for Windows (32-bit) | |
| #elif __APPLE__ | |
| #include "TargetConditionals.h" | |
| #if TARGET_OS_IPHONE && TARGET_IPHONE_SIMULATOR | |
| // define something for simulator | |
| #elif TARGET_OS_IPHONE | |
| // define something for iphone |
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 ProductFitInfo: SimpleViewModel, Hashable { | |
| let message: String? | |
| let imageName: String? | |
| public init?(attribute: FitAttribute, imageName: String? = nil) { | |
| let suffix = String(describing: attribute) | |
| if suffix.isEmpty { | |
| return nil | |
| } | |
| self.message = Constants.FitRecommendation.Strings.predicate + " " + suffix |
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
| self.fitLabel.isHidden = { (message: String?) -> Bool in | |
| guard let thisMessage = message else { | |
| return true | |
| } | |
| self.fitLabel.text = thisMessage | |
| self.fitLabel.textAlignment = self.traitCollection.horizontalSizeClass == .regular ? .right : .left | |
| return false | |
| }(vm.fitInfo?.message) |
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
| // Comparable+Extensions.swift | |
| // Attribution 4.0 International (CC 4.0), see bottom for license details. | |
| import Foundation | |
| extension Comparable { | |
| func clamp<T: Comparable>(lower: T, _ upper: T) -> T { | |
| assert(lower <= upper) | |
| return min(max(self as! T, lower), upper) |
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
| // Array+Extensions.swift | |
| // Attribution 4.0 International (CC 4.0), see bottom for license details. | |
| import Foundation | |
| extension Array where Element == String? { | |
| // converts an array of optional accessibility labels to a single accessibility label that can be set on an accessibility element | |
| var convertedToAccessibilityLabel: String { | |
| return self.compactMap { $0 }.joined(separator: ", ") |