Skip to content

Instantly share code, notes, and snippets.

View MojtabaHs's full-sized avatar

Seyed Mojtaba Hosseini Zeidabadi MojtabaHs

View GitHub Profile
#if DEBUG
import SwiftUI
protocol UIViewControllerRepresentableHelper: UIViewControllerRepresentable {
var configuration: (UIViewControllerType) -> () { get set }
}
extension UIViewControllerRepresentableHelper {
func makeUIViewController(context: Context) -> UIViewControllerType { UIViewControllerType() }
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) { configuration(uiViewController) }
@MojtabaHs
MojtabaHs / convertFromUpperCamelCase.swift
Last active February 26, 2024 14:47
Strategy for decoding UpperCamelCase JSONs to preferred lowerCamelCase version.
public extension JSONDecoder.KeyDecodingStrategy {
/// Convert from "UpperCamelCaseKeys" to "lowerCamelCaseKeys" before attempting to match a key with the one specified by each type.
///
/// The conversion to upper case uses `Locale.system`, also known as the ICU "root" locale. This means the result is consistent regardless of the current user's locale and language preferences.
///
/// - Copyright: This function is based on this [source](https://gist.github.com/MojtabaHs/1f9a0f19bafaecd0c94f585648244303)
static var convertFromUpperCamelCase: Self {
.custom { keys in
/// - Precondition: `Keys` array must never be empty.
guard let key = keys.last else { fatalError("Keys should not be empty") }
@MojtabaHs
MojtabaHs / NSViewForSwiftUI.swift
Last active January 11, 2020 06:42
This is a simple file you can use to bring any AppKit NSView in to the SwiftUI. Fully customizable.
struct <#NSViewForSwiftUI#>: NSViewRepresentable {
typealias TheNSView = <#The Original UIView Type#> /* e.g. NSProgressIndicator */
var configuration = { (view: TheNSView) in }
func makeNSView(context: NSViewRepresentableContext<ProgressIndicator>) -> NSProgressIndicator {
TheNSView()
}
func updateNSView(_ nsView: NSProgressIndicator, context: NSViewRepresentableContext<ProgressIndicator>) {
struct <#NSViewForSwiftUI#>: NSViewRepresentable {
typealias TheNSView = <#The Original UIView Type#> /* e.g. NSProgressIndicator */
var configuration = { (view: TheNSView) in }
func makeNSView(context: NSViewRepresentableContext<ProgressIndicator>) -> NSProgressIndicator {
TheNSView()
}
func updateNSView(_ nsView: NSProgressIndicator, context: NSViewRepresentableContext<ProgressIndicator>) {
@MojtabaHs
MojtabaHs / SomeKindOfBool.swift
Last active August 27, 2024 09:52
Decode logical `Bool` into a real `Bool` with this simple Property Wrapper.
// MARK: - Wrapper
@propertyWrapper
struct SomeKindOfBool: Decodable {
var wrappedValue: Bool
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
if let stringifiedValue = try? container.decode(String.self) {
switch stringifiedValue.lowercased() {
case "false", "no", "0", "n", "f": wrappedValue = false
@MojtabaHs
MojtabaHs / UIViewForSwiftUI.swift
Last active April 18, 2023 10:33
This is a simple file you can use to bring any UIKit UIView in to the SwiftUI. Fully customizable.
import SwiftUI
protocol UIViewRepresentableHelper: UIViewRepresentable {
var configuration: (UIViewType) -> () { get set }
}
@available(iOS 13.0, *)
extension UIViewRepresentableHelper {
func makeUIView(context: UIViewRepresentableContext<Self>) -> UIViewType {
let uiView = UIViewType()
@MojtabaHs
MojtabaHs / SO.txt
Last active August 13, 2019 05:45
Socket new question data example
{
"action": "1-questions-newest-tag-ios",
"data": "{"id":"57471635","body":"<div class=\"question-summary\" id=\"question-summary-57471635\">\r\n <div class=\"statscontainer\">\r\n <div class=\"stats\">\r\n <div class=\"vote\">\r\n <div class=\"votes\">\r\n <span class=\"vote-count-post \"><strong>0</strong></span>\r\n <div class=\"viewcount\">votes</div>\r\n </div>\r\n </div>\r\n <div class=\"status unanswered\">\r\n <strong>0</strong>answers\r\n </div>\r\n </div>\r\n <div class=\"views \" title=\"1 view\">\r\n 1 view\r\n</div>\r\n </div>\r\n <div class=\"summary\">\r\n <h3><a href=\"/questions/57471635/firebase-crashlytics-not-uploading-dysm-automatically\" class=\"question-hyperlink\">Firebase crashlytics not uploading dysm automatically</a></h3>\r\n <div class=\"excerpt\">\r\n I'm having problem when migrating to firebase crashlytics from fabric with the automatic upload of dysm. Ever since i migrated to firebase the automatic upload isn't working.\n\nI have already tried ...\r\n </div>\r\n <div class=\"t