Skip to content

Instantly share code, notes, and snippets.

View anoop4real's full-sized avatar

anoop4real anoop4real

View GitHub Profile
@nic004
nic004 / dictionaryEncodable.swift
Created February 2, 2018 05:05
Encodable struct to dictionary
protocol DictionaryEncodable: Encodable {}
extension DictionaryEncodable {
func dictionary() -> [String: Any]? {
let encoder = JSONEncoder()
encoder.dateEncodingStrategy = .millisecondsSince1970
guard let json = try? encoder.encode(self),
let dict = try? JSONSerialization.jsonObject(with: json, options: []) as? [String: Any] else {
return nil
}

KOTLIN -My Learnings

Now Kotlin is officially announced for Android, I thought of getting started and below is my learnings, as an iOS developer, I am writing a comparison also whereever required.

@anoop4real
anoop4real / ApplicationLogger.swift
Last active June 29, 2021 08:28
A simple logger class, which logs message to a file which can later be sent as an attachment etc for debugging.
//
// Applogger.swift
// MyCatalogue
//
// Created by anoopm on 20/08/16.
// Copyright © 2016 anoopm. All rights reserved.
//
import Foundation
@anoop4real
anoop4real / CoreDataManager.swift
Created December 8, 2016 14:35
CoredataStack iOS10 & <iOS10
import Foundation
import CoreData
class CoreDataManager {
// MARK: - Core Data stack
static let sharedInstance = CoreDataManager()
private lazy var applicationDocumentsDirectory: URL = {
// The directory the application uses to store the Core Data store file. This code uses a directory named in the application's documents Application Support directory.
let urls = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
@gragera
gragera / gist:fab8a2eaa11dc63b9b9f
Last active September 3, 2018 13:15
Using swift generics for easier storyboard ViewController instantiation
import UIKit
extension UIStoryboard {
func instantiate<T>(identifier: String, asClass: T.Type) -> T {
return instantiateViewControllerWithIdentifier(identifier) as! T
}
func instantiate<T>(identifier: String) -> T {
return instantiateViewControllerWithIdentifier(identifier) as! T
@igordeoliveirasa
igordeoliveirasa / gist:78a310f0348fcad9b270
Created March 26, 2015 01:41
iOS Loading Overlay View - SWIFT
//
// LoadingOverlay.swift
// app
//
// Created by Igor de Oliveira Sa on 25/03/15.
// Copyright (c) 2015 Igor de Oliveira Sa. All rights reserved.
//
// Usage:
//
// # Show Overlay
@MartinMoizard
MartinMoizard / gist:6537467
Created September 12, 2013 13:37
Category on UIViewController: recursive function to present a modal View Controller anywhere in the application. Example: [self.window.rootViewController presentViewControllerFromVisibleViewController:myViewController]; Works with application using only UINavigationController and modal views. Can be enhanced to handle UITabBarController or other…
- (void)presentViewControllerFromVisibleViewController:(UIViewController *)viewControllerToPresent
{
if ([self isKindOfClass:[UINavigationController class]]) {
UINavigationController *navController = (UINavigationController *)self;
[navController.topViewController presentViewControllerFromVisibleViewController:viewControllerToPresent];
} else if (self.presentedViewController) {
[self.presentedViewController presentViewControllerFromVisibleViewController:viewControllerToPresent];
} else {
[self presentModalViewController:viewControllerToPresent animated:YES];
}