Skip to content

Instantly share code, notes, and snippets.

View novinfard's full-sized avatar

Soheil Novinfard novinfard

View GitHub Profile
@novinfard
novinfard / flipImageRTL-UIKit.swift
Created June 28, 2021 23:24
[Flip the image for RTL in UIKit]
class ViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
imageView.image = UIImage(systemName: "pencil.circle.fill")?.imageFlippedForRightToLeftLayoutDirection()
}
}
@novinfard
novinfard / forceRTL-SwiftUI.swift
Created June 28, 2021 21:50
[Force RTL in SwiftUI]
final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
func scene(_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions) {
let contentView = ContentView().environment(\.layoutDirection, .rightToLeft)
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: contentView)
self.window = window
@novinfard
novinfard / forceRTL-UIKit.swift
Created June 28, 2021 21:39
[Force RTL in UIKit]
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Force all UIKit views to RTL
UIView.appearance().semanticContentAttribute = .forceRightToLeft
return true
}
}
@novinfard
novinfard / trackableScrollView.swift
Created June 27, 2021 12:46
[Trackable ScrollView in SwiftUI]
//
// TrackableScrollView.swift
// Lions
//
// Created by Soheil Novinfard on 22/04/2021.
// Copyright © 2021 David Rodriguez Luque. All rights reserved.
//
import SwiftUI
@novinfard
novinfard / usersInLottery.json
Last active June 20, 2021 19:12
[List of the users participated in Lottery in SimpleLottery App]
{
"lotteryList": [
{
"userId": 10,
"void": false
},
{
"userId": 22,
"void": false
},
@novinfard
novinfard / userList.json
Created June 20, 2021 18:45
[User List in SimpleLottery App]
{
"items": [
{
"userId": 10,
"name": "Jack Alexy",
"username": "JAlex",
"regDate": "2020-10-19"
},
{
"userId": 22,
@novinfard
novinfard / CustomEnvironmentVariable.swift
Created June 19, 2021 10:50
[Custom Environment variable in SwiftUI]
// 1. Create the key with a default value
private struct CaptionColorKey: EnvironmentKey {
static let defaultValue = Color(.secondarySystemBackground)
}
// 2. Extend the environment with our property
extension EnvironmentValues {
var captionBackgroundColor: Color {
get { self[CaptionColorKey.self] }
set { self[CaptionColorKey.self] = newValue }
@novinfard
novinfard / ConvertToBinaryTreeSuitableForInput.swift
Last active April 29, 2021 21:04
[Convert Binary tree input in AlgoExpert to tree input value]
class Program {
class BST {
var value: Int
var left: BST?
var right: BST?
init(value: Int) {
self.value = value
}
}
@novinfard
novinfard / debugSwiftUIType.swift
Created April 26, 2021 20:25
[Debug SwiftUI view type]
extension View {
func debug() -> Self {
print(Mirror(re􏰁ecting: self).subjectType)
return self
}
}
@novinfard
novinfard / urlImage.swift
Created April 21, 2021 17:58
URLImage Example
// Package is available at
// https://github.com/dmytro-anokhin/url-image
import URLImage
struct URLOptionalImage: View {
var imageUrlString: String?
var body: some View {
if let urlString = imageUrlString,
let url = URL(string: urlString) {
URLImage(url: url) { image in