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
| class <#Class#> { | |
| // Private Init | |
| private init() { } | |
| // MARK: Shared Instance | |
| private static let _shared = <#Class#> | |
| // MARK: - Accessors | |
| class func shared() -> <#Class#> { |
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
| let string = "This a string split using * and this is left." | |
| if let range = string.range(of: "*") { | |
| let lastPartIncludingDelimiter = string.substring(from: range.lowerBound) | |
| print(lastPartIncludingDelimiter) // print * and this is left. | |
| let lastPartExcludingDelimiter = string.substring(from: range.upperBound) | |
| print(lastPartExcludingDelimiter) // print and this is left. | |
| let firstPartIncludingDelimiter = string.substring(to: range.upperBound) | |
| print(firstPartIncludingDelimiter) // print This a string split using * |
CHARTS
COLLECTIONVIEW
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
| extension String{ | |
| func asURLRequest()->URLRequest?{ | |
| var urlRequest:URLRequest? | |
| if self.isValidForUrl(){ | |
| if let url = URL(string: self){ | |
| urlRequest = URLRequest(url: url) | |
| } | |
| }else{ | |
| urlRequest = 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
| func copyFolder(){ | |
| // Get the resource folder | |
| if let resourceMainPath = Bundle.main.resourcePath{ | |
| var isDirectory = ObjCBool(true) | |
| // Get the path of the folder to copy | |
| let originPath = (resourceMainPath as NSString).appendingPathComponent("NameOfFolder") | |
| // Get the destination path, here copying to Caches | |
| let destinationPath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first! |
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
| // | |
| // NetworkDataManager.swift | |
| // | |
| // Created by anoopm on 17/05/16. | |
| import UIKit | |
| enum Result<T, Error> { | |
| case success(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
| struct Constants { | |
| struct APIDetails { | |
| static let APIScheme = "https" | |
| static let APIHost = "restcountries.eu" | |
| static let APIPath = "/rest/v1/alpha/" | |
| } | |
| } | |
| private func createURLFromParameters(parameters: [String:Any], pathparam: String?) -> URL { |
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) |
NewerOlder