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 | |
extension Binding { | |
func map<MappedValue>( | |
valueToMappedValue: @escaping (Value) -> MappedValue, | |
mappedValueToValue: @escaping (MappedValue) -> Value | |
) -> Binding<MappedValue> { | |
Binding<MappedValue>.init { () -> MappedValue in | |
return valueToMappedValue(wrappedValue) | |
} set: { mappedValue in |
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
// | |
// CalendarView.swift | |
// iWidget | |
// | |
// Created by Huy Nguyen on 10/2/20. | |
// | |
import SwiftUI | |
fileprivate extension DateFormatter { |
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
// IMPORTANCE: I don't use this anymore, because it has problem with a json that missing key. In normal, we can ignore a missing key by set a property optional. But in this case, setting property optional still causes no key error. | |
/* Huy Nguyen | |
Use property wrapper to reduce meaningless code in a decodable, when you need to customize how to parse just 1 key, but have to implement all keys. | |
This snippet assumes you need to decode some models that currency values are Strings with "$" prefix ("$20.3" to 20.3), and you want to parse them to Double values. | |
For example, the JSON of Product model: | |
{ | |
"price": "$20.3", |
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
# This file contains the fastlane.tools configuration | |
# You can find the documentation at https://docs.fastlane.tools | |
# | |
# For a list of all available actions, check out | |
# | |
# https://docs.fastlane.tools/actions | |
# | |
# For a list of all available plugins, check out | |
# | |
# https://docs.fastlane.tools/plugins/available-plugins |
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
name: On pull request | |
on: | |
pull_request: | |
branches: | |
- master | |
- develop | |
jobs: | |
test: |
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
# Set ADHOC_CERTIFICATE base64, ADHOC_PROVISIONING base64, ADHOC_CERTIFICATE_PASSWORD to Github secrets | |
# - File and base64: | |
# base64 -i <any-file> -o <text-file> | |
# base64 -D -i <text-file> -o <any-file> | |
name: Release using fastlane | |
on: | |
push: | |
branches: |
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 Foundation | |
// Assume the server return `Int` number in a `String`. If it happen on all models, we can't customise all models with `init(decoder:)` and `encode(encoder:)`, because it will make the code a mess. | |
// Conform this protocol to implement transformation | |
protocol Transformer { | |
associatedtype Origin: Codable | |
associatedtype Target | |
static func decode(value: Origin) throws -> Target |
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
class ContentSizeCollectionView: UICollectionView { | |
var contentSizeObservation: NSKeyValueObservation? | |
override var intrinsicContentSize: CGSize { | |
return shouldFullSize ? contentSizeWithInset : CGSize(width: UIView.noIntrinsicMetric, height: UIView.noIntrinsicMetric) | |
} | |
var shouldFullSize: Bool = true { | |
didSet { | |
invalidateIntrinsicContentSize() |
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
// | |
// XibLoaderView.swift | |
// | |
// | |
// Created by Nguyen Cong Huy on 20/11/2021. | |
// | |
import UIKit | |
/** |
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 MeasurementModifier: ViewModifier { | |
@Binding var isEnabled: Bool | |
let sizeChanged: (CGSize) -> Void | |
func body(content: Content) -> some View { | |
content.background(MeasurementView(isEnabled: $isEnabled, sizeChanged: sizeChanged)) | |
} | |
OlderNewer