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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Applogger.swift | |
// MyCatalogue | |
// | |
// Created by anoopm on 20/08/16. | |
// Copyright © 2016 anoopm. All rights reserved. | |
// | |
import Foundation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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]; | |
} |