Posts

Download Image from URL

  import UIKit import Foundation let imgCache = NSCache < NSString , AnyObject >() class Utility : NSObject {     static func getImageFromURlString ( _ urlStr: String , completion: @escaping ( UIImage ?)-> Void )  {         if let cachedImg = imgCache . object (forKey: NSString (string: urlStr)) as ? UIImage {             completion(cachedImg)             return         }                  let url = URL (string: urlStr)         if let url = url {             DispatchQueue . global (qos: . background ). async {                 URLSession . shared . dataTask (with: url) { (data, res, err) in                     if let dataNew = data, let img = UI...

Tutorial Videos & Links

  Protocol Oriented Programming https://www.appcoda.com/protocol-oriented-programming/ Silent notification https://medium.com/@m.imadali10/ios-silent-push-notifications-84009d57794c Closure VS function type https://youtu.be/fVF_tNcIhfc https://medium.com/swift-india/functional-swift-closures-67459b812d0 Protocol example https://youtu.be/DBWu6TnhLeY https://youtu.be/PVRL2wAKNZw https://medium.com/better-programming/swift-why-you-should-avoid-using-default-implementations-in-protocols-eeffddbed46d Notification centre https://youtu.be/srqiDnLEocA Local Notification https://medium.com/quick-code/local-notifications-with-swift-4-b32e7ad93c2 Bi-weekly Notification https://stackoverflow.com/questions/46070648/trigger-uilocalnotification-for-every-14-days-fortnightly-swift Classes & Structures https://youtu.be/ObIxxHy8yY8 If-let, guard, force-unwrapping, optional chaining https://youtu.be/ZL8BFK8bVjk Map, Filter, Reduce https://youtu.be/OujkoTKEVj8 Concurrency & Threading https:/...

Closures

Ref. Link https://youtu.be/fVF_tNcIhfc https://medium.com/swift-india/functional-swift-closures-67459b812d0 import UIKit class ViewController : UIViewController {     //This is a closure which doesn't require any parameter and no return type     var closure_1 : () -> Void = {         print ( "closure_1 called" )     }          //This is a closure which requires Int as a parameter and no return type     var closure_2 : ( Int ) -> Void = { intValue in         print (intValue)     }          //This is a closure which requires Int as a parameter and returns sq of that number     var closure_3 : ( Int ) -> Int = { intValue in         return intValue * intValue     }          //This closure will add two Int and return new Int     var addTwoNumbers : ( Int , Int...

GCD + NSOperationQueue

Image
GCD + NSOperationQueue https://www.appcoda.com/grand-central-dispatch/ https://www.appcoda.com/ios-concurrency/ Sample Codes   //MARK: GCD & NSOPERATIONQUEUE class MultiThreadingTest {     func method () {         let queue = DispatchQueue (label: "dD" )         queue. async {                      }         DispatchQueue . global (). async {                      }         DispatchQueue . main . async {                      }         OperationQueue (). addOperation {             Operation (). completionBlock = {                              }         }  ...

Map, Filter, Reduce

  func getArray (arr:[ Int ]) -> (map:[ Int ], filtered:[ Int ], sorted:[ Int ], reduce: Int ) {         let map_arr = arr. map { (obj) -> Int in             return obj * 2         }                  let filter_arr = arr. filter { (obj) -> Bool in             return (obj % 2 == 0 ) ? true : false         }                  let sort_arr = arr. sorted { (obj1, obj2) -> Bool in             return obj1 < obj2         }                  let reduce_arr = arr. reduce ( 0 ) { (obj1, obj2) -> Int in             obj1 + obj2         }                  return (...

Generics

Generic & Mutating (diff in Any) https://youtu.be/fB8_4GaS5Bg https://youtu.be/J0SBrYzTqfg class Stack < T > {     var arr : [ T ] = []     func push ( _ item: T ) {         arr . append (item)     }     func remove (at index: Int ) {         arr . remove (at: index)     } } let stack_1 = Stack < Int >() stack_1. push ( 5 ) stack_1. remove (at: 0 )

Protocol - Delegate

  protocol HandleCallbackProtocal {     func callback1 ()     func callback2 () } class ProtocolClass {     var delegate : HandleCallbackProtocal ?          func call1 () {         delegate ?. callback1 ()     } } class ClassP : HandleCallbackProtocal {     func callback1 () {              }          func callback2 () {              }          init () {         let obj = ProtocolClass ()         obj. delegate = self                  obj. call1 ()     } } Ref. Links https://youtu.be/DBWu6TnhLeY https://youtu.be/PVRL2wAKNZw Swift: Why You Should Avoid Using Default Implementations in Protocols https://medium.com/better-programming/swift-why-you-should-avoid-using-d...