Skip to content

Instantly share code, notes, and snippets.

Avatar

Muhammad Fahied fahied

View GitHub Profile
@fahied
fahied / modal-view.md
Created Jul 28, 2020 — forked from barbietunnie/modal-view.md
Swift Modal View Controller with transparent background
View modal-view.md

You can do it like this:

In your main view controller:

func showModal() {
    let modalViewController = ModalViewController()
    modalViewController.modalPresentationStyle = .OverCurrentContext
    presentViewController(modalViewController, animated: true, completion: nil)
}
@fahied
fahied / UINavigationController+Extension.swift
Created May 4, 2020
Filter ViewControllers in a NavigationController by a Protocol
View UINavigationController+Extension.swift
// Important Protocol is marked @objc and conform to AnyObject
@objc protocol Hostable: AnyObject { }
extension UINavigationController {
func viewControllers(conforming: Protocol) -> [UIViewController]? {
return viewControllers.filter { $0.conforms(to: conforming) }
}
func popToFirstViewController(conforming: Protocol, animated: Bool) {
@fahied
fahied / findsymbol.command
Created Mar 20, 2020
find Symbols/API usage in a framework
View findsymbol.command
cd mapp.app //in Product folder under Xcode
nm myapp | grep UIWeb
for framework in Frameworks/*.framework; do
fname=$(basename $framework .framework)
echo $fname
nm $framework/$fname | grep UIWeb
done
@fahied
fahied / UserDefault.swift
Created Feb 16, 2020
Reduce Boiler Plate code for UserDefault using PropertyWrapper
View UserDefault.swift
// Strongly Typed key
struct Key: RawRepresentable {
let rawValue: String
}
extension Key: ExpressibleByStringLiteral {
init(stringLiteral: String) {
rawValue = stringLiteral
}
@fahied
fahied / autotrack.swift
Last active Dec 17, 2019
Auto Track Analytics iOS
View autotrack.swift
@objc class AutoTrackedViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
tracker.trackScreen(name: Self.screenName, className: Self.className)
addTrackingTarget()
}
override func viewDidLoad() {
View iOS Swift - Cancellable Task with GCD.md

iOS Swift - Cancellable Task with GCD

#iOSBySheldon

I think most of you guys know GCD pretty well. Basically, GCD is a high level API to handle multi-threading operations. We use GCD almost on daily basis to switch thread and execute codes like:

DispatchQueue.main.async { //execute some codes here } 
//switch to main queue and execute codes asynchronously

DispatchQueue.main.sync { //execute some codes here } 
//switch to main queue and execute codes synchronously
@fahied
fahied / symbolicateiOS.md
Last active Dec 15, 2019
Symbolicate iOS crash manually
View symbolicateiOS.md

Step 1: Use the following command in Terminal to find the dSYM on your Mac which build the app

mdfind "com_apple_xcode_dsym_uuids == 12345678-90AB-CDEF-1234-567890ABCDEF"

The string "12345678-90AB-CDEF-1234-567890ABCDEF" is the UUID string from the crash report reformatted to uppercase and 8-4-4-4-12 groups.

Step 2: Symobolicate Crash Report. Excute the following line before symbolicating

@fahied
fahied / AssetExtractor.swift
Created Apr 11, 2019
Get URL from Xcode asset catalogs
View AssetExtractor.swift
import UIKit
//It basically just gets image from assets, saves its data to disk and return file URL.
class AssetExtractor {
static func createLocalUrl(forImageNamed name: String) -> URL? {
let fileManager = FileManager.default
let cacheDirectory = fileManager.urls(for: .cachesDirectory, in: .userDomainMask)[0]
let url = cacheDirectory.appendingPathComponent("\(name).png")
@fahied
fahied / alert.swift
Created Apr 10, 2019
UIWindow Alert
View alert.swift
func showAlert(message: String) {
let alert = UIAlertController(title: "Link", message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
switch action.style{
case .default:
print("default")
case .cancel:
print("cancel")
View MultiLineButton.swift
import UIKit
class MultiLineButton: UIButton {
// MARK: - Init
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.commonInit()
You can’t perform that action at this time.