Posts

SubString in Swift

  extension String {     func index (from: Int ) -> Index {         return self . index ( startIndex , offsetBy: from)     }     func substring (from: Int ) -> String {         let fromIndex = index (from: from)         return String ( self [fromIndex ... ])     }     func substring (to: Int ) -> String {         let toIndex = index (from: to)         return String ( self [ ..< toIndex])     }     func substring (with r: Range < Int >) -> String {         let startIndex = index (from: r. lowerBound )         let endIndex = index (from: r. upperBound )         return String ( self [startIndex ..< endIndex])     }          func subString (from index: Int , count: Int ) -> String...

PUSH Notification

Image
  APNS APNs  Overview.  Apple  Push Notification service ( APNs ) is the centerpiece of the remote notifications feature. It is a robust, secure, and highly efficient service for app developers to propagate information to iOS (and, indirectly, watchOS), tvOS, and macOS devices Device Token APNS generates a unique token/id for a apple device. This can be used while sending notification. Push Payload Size When using the HTTP/2 based APNS provider API, the maximum size for your JSON dictionary is 4KB. For legacy APIs, the payload size is smaller. For regular remote notifications, the maximum size is  4KB  (4096 bytes) For Voice over Internet Protocol (VoIP) notifications, the maximum size is  5KB  (5120 bytes) Payload Sample:  { "aps" : { "alert" : { "title" : "New Podcast Available" , "subtitle" : "Antonio Leiva – Clean Architecture" , "body" : "This episode we talk about Clean Architecture...

In-App Purchase

Create In-App purchase product Before you refer this, please visit itunesconnect and create in-app purchase product under your app. You will get the product identifier which we are going to use in this code snippet.  If you already have done then ignore this.   Import Statements      import StoreKit      Protocols      SKProductsRequestDelegate , SKPaymentTransactionObserver Get product info & price      func getInAppPrice (for identifier:  String ) {         if SKPaymentQueue . canMakePayments () {             let productsRequest = SKProductsRequest (productIdentifiers: [ identifier ])             productsRequest. delegate = self             productsRequest. start ()         } else {             print ( "User cannot make payments due to parental...

Add Shadow

  func addShadowToView ( _ view: UIView )     {         view. layer . shadowColor =  UIColor . gray . cgColor         view. layer . shadowOpacity = 0.4         view. layer . shadowRadius = 4         view. layer . shadowOffset = CGSize (width: 2 , height: 2 )     }

Enum

import UIKit class ViewController : UIViewController {          enum DocumentStatus : String , CaseIterable {         case PENDING = "Pending"         case APPROVED = "Approved"         case REJECTED = "Rejected"         case OVERDUED = "Overdued"     }          override func viewDidLoad () {         super . viewDidLoad ()                  let allEnumCases: [ DocumentStatus ] = DocumentStatus . allCases         let allEnumCasesAsString: [ String ] = DocumentStatus . allCases . map { $0. rawValue }                  let indexOfDocumentStatusEnum: Int ? = DocumentStatus . allCases . firstIndex (of: DocumentStatus . APPROVED )                  let indexOfDocume...

NotificationCenter

  Ref. Link https://youtu.be/srqiDnLEocA class ViewController : UIViewController {          override func viewDidLoad () {         super . viewDidLoad ()                  NotificationCenter . default . addObserver ( self , selector:                #selector ( notificationMethodCall ), name: . noti1 , object: nil )           // Fire a notification         NotificationCenter . default . post (name: . noti1 , object: nil )              }     @objc func notificationMethodCall () {         //Notification will be called     } } //MARK: Extenstion test extension Notification . Name {     static let noti1 = Notification . Name ( "Noti" )      }