Skip to content

Instantly share code, notes, and snippets.

View dimohamdy's full-sized avatar
🏠
Working from home

Dimo Hamdy dimohamdy

🏠
Working from home
View GitHub Profile
@dimohamdy
dimohamdy / imageautoLayout
Last active November 23, 2015 18:14
UIImageView aspect fill
This preserves aspect, fills it up, and then clips overflows:
self.viewTitleImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.viewTitleImageView setClipsToBounds:YES];
@dimohamdy
dimohamdy / Label Font
Last active January 22, 2017 10:00
Change Font name Without change font size
UILabel.appearance().defaultFont = UIFont.systemFont(ofSize: 15/*Any Value*/, weight: UIFontWeightThin)
extension UILabel{
dynamic var defaultFont: UIFont? {
get { return self.font }
set {
let sizeOfOldFont = self.font.pointSize
let fontNameOfNewFont = newValue?.fontName
self.font = UIFont(name: fontNameOfNewFont!, size: sizeOfOldFont)
}
@dimohamdy
dimohamdy / Array IndexOutOfBoundsException
Created January 23, 2017 13:55
handle IndexOutOfBoundsException using try catch Swift 3
enum ArrayError: Error {
case OutOfBounds(min: Int, max: Int)
}
extension Array {
mutating func set(index:Int, value: Element) throws {
guard self.indices.contains(index) else {
@dimohamdy
dimohamdy / strong password
Created May 30, 2017 23:59
check if password is strong using swift
/*
check if the password lenght more than or equal 8
and have lowercase , uppercase ,decimalDigits and special characters like !@#$%^&*()_-+ is optional
Why i not use regular expression ?
Because it's difficult to support reserved characters in regular expression syntax.
*/
func isValidated(_ password: String) -> Bool {
var lowerCaseLetter: Bool = false
@dimohamdy
dimohamdy / KeyPath.swift
Last active August 24, 2024 07:17
Accessing Dictionaries with Key Paths
/*
Thanks for @olebegemann
code of keypath from this link
https://oleb.net/blog/2017/01/dictionary-key-paths/
*/
struct KeyPath {
var segments: [String]
var isEmpty: Bool { return segments.isEmpty }
@dimohamdy
dimohamdy / iconVersioning.sh
Created December 6, 2017 23:16
add Version to icon Xcode 9
#!/bin/sh
export PATH=/opt/local/bin/:/opt/local/sbin:$PATH:/usr/local/bin:
convertPath=`which convert`
gsPath=`which gs`
if [[ ! -f ${convertPath} || -z ${convertPath} ]]; then
convertValidation=true;
else
convertValidation=false;
@dimohamdy
dimohamdy / Remove Realm
Created December 27, 2018 12:24
Remove realm to work with watchos
pod cache clean Realm
pod cache clean RealmSwift
pod deintegrate || rm -rf Pods
pod install --verbose
rm -rf ~/Library/Developer/Xcode/DerivedData
@dimohamdy
dimohamdy / RetainCycle.swift
Last active January 2, 2019 15:44
Check Retain Cycle in ViewController
//I get this code from Arek Holko artival https://holko.pl/2017/06/26/checking-uiviewcontroller-deallocation/
import UIKit
extension UIViewController {
public func dch_checkDeallocation(afterDelay delay: TimeInterval = 2.0) {
let rootParentViewController = dch_rootParentViewController
// We don’t check `isBeingDismissed` simply on this view controller because it’s common
// to wrap a view controller in another view controller (e.g. in UINavigationController)
// and present the wrapping view controller instead.
@dimohamdy
dimohamdy / Swizzling.swift
Last active January 2, 2019 15:44
Generic function to exchange function
let swizzling: (AnyClass, Selector, Selector) -> Void = { forClass, originalSelector, swizzledSelector in
guard
let originalMethod = class_getInstanceMethod(forClass, originalSelector),
let swizzledMethod = class_getInstanceMethod(forClass, swizzledSelector)
else { return }
method_exchangeImplementations(originalMethod, swizzledMethod)
}
import UIKit
extension UIViewController {
static let classInit: Void = {
let originalSelector = #selector(viewDidDisappear)
let swizzledSelector = #selector(swizzled_viewDidDisappear)
swizzling(UIViewController.self, originalSelector, swizzledSelector)
}()