Skip to content

Instantly share code, notes, and snippets.

View anoop4real's full-sized avatar

anoop4real anoop4real

View GitHub Profile
@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)
@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 / SnippetCreateURLFromParameters.swift
Created March 25, 2017 14:37
Reusable snippet to construct webservice url request. Note this is taken from Playground
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 {
@anoop4real
anoop4real / NetworkDataManager.swift
Created April 26, 2017 18:41
Swift3:Simple Networkmanager
//
// NetworkDataManager.swift
//
// Created by anoopm on 17/05/16.
import UIKit
enum Result<T, Error> {
case success(T)
@anoop4real
anoop4real / CopyFolder.swift
Last active November 16, 2022 08:34
Swift3: Utility functions to copy a folder and its contents from resources to documents
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!
@anoop4real
anoop4real / StringExtension.swift
Created May 19, 2017 18:19
Swift 3 String to URLRequest extension
extension String{
func asURLRequest()->URLRequest?{
var urlRequest:URLRequest?
if self.isValidForUrl(){
if let url = URL(string: self){
urlRequest = URLRequest(url: url)
}
}else{
urlRequest = nil
@anoop4real
anoop4real / Frameworkslibs.md
Last active June 6, 2018 06:30
List of useful iOS frameworks/ libraries that I found

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.

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 *
@anoop4real
anoop4real / Singleton.swift
Last active November 8, 2017 06:33
A snippet for singleton
class <#Class#> {
// Private Init
private init() { }
// MARK: Shared Instance
private static let _shared = <#Class#>
// MARK: - Accessors
class func shared() -> <#Class#> {