Skip to content

Instantly share code, notes, and snippets.

View yoni-g's full-sized avatar
🕵️‍♂️
debugging

Yonathan Goriachnick yoni-g

🕵️‍♂️
debugging
View GitHub Profile
@yoni-g
yoni-g / Coordinator.swift
Last active November 15, 2020 16:11
A coordinator implementation I use In my projects [Used for one main coordinator, you can change it to work with multiple coordinators]
import UIKit
protocol Coordinator {
var navigationController: UINavigationController? { get set }
// config funcs
func setNavControler(_ navCtrl: UINavigationController) -> Self
func start()
// display funcs
func show(view: AppScreen)
@yoni-g
yoni-g / MenuOption.swift
Last active July 27, 2020 06:55
How to present a popup menu in iOS?
//
// MenuOption.swift
//
struct MenuOption {
var title: String = ""
var image: UIImage
var action: (()->())
init(title: String, image: UIImage, action: @escaping (()->())) {
@yoni-g
yoni-g / AnalyticsManager.swift
Last active May 2, 2021 09:07
AnalyticsManager class to easily log and manage events in iOS apps
import FirebaseAnalytics
import Crashlytics
enum AnalyticsEvent {
case materialDetails(matName: String?, matNumber: String?)
case addMaterialInTab(tabName: String)
case tabPressed(tabName: String)
case sendOrder(agentCode: String?, customerNumber: String?, totalAmount: NSNumber?, userCurrency: String?, itemsQty: Int?)
case loggedUserInfo(customerNumber: String?, contactEmail: String?, userMobile: String?)
FeedItem postItem = new FeedItem();
postItem.ParentId = 'SOME_TEST_ID';
postItem.Type = 'TextPost';
postItem.Title = 'Hello World! ';
postItem.Body = 'This is my test';
insert postItem;
@yoni-g
yoni-g / CloseAfterDownload.js
Last active March 3, 2021 13:06
How to force close an opened download file (pdf) tab or page that opened by a link?
function openPage(url) {
window.setTimeout(function () {
openWindow(url);
} ,500);
}
function openWindow(url) {
var tab = window.open(url);
if (!url.location.pathname.includes('pdf')){
setTimeout(function () {
@yoni-g
yoni-g / closeAppElegantly.swift
Last active March 30, 2023 02:08
How to exit an iOS app without it looking like a crash? - Swift
func showMessageResetApp(){
let exitAppAlert = UIAlertController(title: "Restart is needed",
message: "We need to restart the app on your first login to the app.\n Please reopen the app after this.",
preferredStyle: .alert)
let resetApp = UIAlertAction(title: "Close Now", style: .destructive) {
(alert) -> Void in
// home button pressed programmatically - to thorw app to background
UIControl().sendAction(#selector(URLSessionTask.suspend), to: UIApplication.shared, for: nil)
// terminaing app in background