Skip to content

Instantly share code, notes, and snippets.

View devahmedshendy's full-sized avatar

Ahmed Shendy devahmedshendy

  • Egypt
View GitHub Profile
//
// TrimmingExample.swift
//
// Created by Vasilis Akoinoglou on 13/5/24.
//
import SwiftUI
struct Line: Identifiable {
let id = UUID()
@devahmedshendy
devahmedshendy / image_as_text_foreground.swift
Last active April 25, 2024 10:56
SwiftUI View: add image as a foreground for Text view
struct ContentView: View {
private let imageUrl: String = "https://picsum.photos/seed/picsum/200/300"
var body: some View {
text
.overlay(
AsyncImage(url: .init(string: imageUrl)) { image in
image
.resizable()
.aspectRatio(contentMode: .fill)
@devahmedshendy
devahmedshendy / DynamicFunctions.swift
Created February 28, 2024 00:23 — forked from neonichu/DynamicFunctions.swift
Using dlopen / dlsym to call C functions from Swift
import Darwin
let handle = dlopen("/usr/lib/libc.dylib", RTLD_NOW)
let sym = dlsym(handle, "random")
let functionPointer = UnsafeMutablePointer<() -> CLong>(sym)
let result = functionPointer.memory()
println(result)
@devahmedshendy
devahmedshendy / README.md
Last active January 16, 2024 08:56
Core Data Fundamentals - CheatSheet (Simple)

Core Data Fundamentals - CheatSheet (Simple)

Here, I will save basic coredata information for anyone/me would like a quick refresh for these fundamentals from time to time.

What is Core Data

  • Core Data is not a database, but instead it manages an Object Graph.

Multithreading

  • NSManagedObject and NSManagedObjectContext in Core Data are not thread-safe.
  • Core Data avoids data race issues by operating on NSManagedObject instances and NSManagedObjectContext instances in a serial queue.
    This is why we need to place the operation code within the closures of perform or performAndWait.
@devahmedshendy
devahmedshendy / .gitignore
Created October 11, 2023 09:22
Gitignore for iOS Development
# Created by https://www.toptal.com/developers/gitignore/api/xcode,swift,macos
# Edit at https://www.toptal.com/developers/gitignore?templates=xcode,swift,macos
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r

SwiftRobot

Tell your Mac what to do, declaratively

What is SwiftRobot?

It is the declarative Layer for RobotKit. It provides several tasks of type RobotTask that helps client define their required tasks in declarative way.

Robot Tasks

  • MouseRobotTask: A Robot task for mouse capability
final class UnitsViewModel {
// MARK: - Public Members/Methods
let onLoadingMoreUnits = PassthroughSubject<Bool, Never>()
let onInitialResult = PassthroughSubject<[UnitDto], Never>()
let onError = PassthroughSubject<HighLevelError.Reason, Never>()
var moreUnitsToLoad: Bool {
unitsQueue.isNotEmpty
@devahmedshendy
devahmedshendy / DetailFlagImageView.swift
Created September 29, 2021 18:40
Custom ImageView for Country Flags, Each flag should be rounded maintaining its original width & height ratio. So we make subclass of ImageView to update ration constraint for current image, then subclass it to set rounded feature for the current ImageView
final class DetailFlagImageView: RatioConstrainedImageView {
//MARK: - Init Methods
override init(frame: CGRect) {
super.init(frame: frame)
initView()
}
@devahmedshendy
devahmedshendy / AndroidManifest.xml
Last active September 25, 2020 12:51
Hilt, The DI Library For Android – Part1: Getting To Know
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="learn.shendy.learnhilt">
<application
android:name=".LearnHiltApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
@devahmedshendy
devahmedshendy / MainActivity.kt
Last active August 31, 2020 11:08
USE CASE: Transition Background of Selected Item From Previous Selected Item (Sample: https://youtu.be/2c9Hjo211yE , Demo: https://youtu.be/xrGats2_rBc)
class MainActivity : AppCompatActivity() {
companion object {
private const val TAG = "MainActivity"
}
private lateinit var mBinding: ActivityMainBinding
private lateinit var mNamesAdapter: NamesAdapter
// MARK: Lifecycle Methods