Skip to content

Instantly share code, notes, and snippets.

Ahmed Hamdy dimohamdy

Block or report user

Report or block dimohamdy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dimohamdy
dimohamdy / imageautoLayout
Last active Nov 23, 2015
UIImageView aspect fill
View imageautoLayout
This preserves aspect, fills it up, and then clips overflows:
self.viewTitleImageView.contentMode = UIViewContentModeScaleAspectFill;
[self.viewTitleImageView setClipsToBounds:YES];
@dimohamdy
dimohamdy / Label Font
Last active Jan 22, 2017
Change Font name Without change font size
View Label Font
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 Jan 23, 2017
handle IndexOutOfBoundsException using try catch Swift 3
View Array IndexOutOfBoundsException
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
check if password is strong using swift
View strong password
/*
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 Jun 1, 2017
Accessing Dictionaries with Key Paths
View KeyPath.swift
/*
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 Dec 6, 2017
add Version to icon Xcode 9
View iconVersioning.sh
#!/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 Dec 27, 2018
Remove realm to work with watchos
View Remove Realm
pod cache clean Realm
pod cache clean RealmSwift
pod deintegrate || rm -rf Pods
pod install --verbose
rm -rf ~/Library/Developer/Xcode/DerivedData
View UIViewController+RetainCycle.swift
import UIKit
extension UIViewController {
static let classInit: Void = {
let originalSelector = #selector(viewDidDisappear)
let swizzledSelector = #selector(swizzled_viewDidDisappear)
swizzling(UIViewController.self, originalSelector, swizzledSelector)
}()
View Appdelegate.swift
override init() {
super.init()
UIViewController.classInit
}
@dimohamdy
dimohamdy / Swizzling.swift
Last active Jan 2, 2019
Generic function to exchange function
View Swizzling.swift
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)
}
You can’t perform that action at this time.