UIEdgeInsetsInsetRect’ has been replaced by instance method ‘CGRect.inset(by:)

Swift 4.1


let container = CGRect(x: 0, y: 0, width: 50, height: 50)

let margin = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)

let content = UIEdgeInsetsInsetRect(container, margin)

Swift 4.2


let container = CGRect(x: 0, y: 0, width: 50, height: 50)

let margin = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)

let content = container.inset(by: margin)

Notification center in swift 4.1 And Swift 4.2

What is notification center :

NotificationCenter you can broadcast data from one part of your app to another part.

for example : you can post data from one viewcontroller and observer this data to another viewcontroller.

// Swift 4.1

NotificationCenter.default.addObserver(self,

  selector: #selector(yourMethod(_:)),

  name: Notification.Name.UIContentSizeCategoryDidChange,

  object: nil)

// Swift 4.2

NotificationCenter.default.addObserver(self,

  selector: #selector(yourMethod(_:)),

  name: UIContentSizeCategory.didChangeNotification,

  object: nil)

KeyboardWillShow And KeyboardWillHide Notification in swift 4.2

//Add Observer


  NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIApplication.keyboardWillShowNotification, object: nil)

        NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: UIApplication.keyboardWillHideNotification, object: nil)

  //Remove Observer  


        NotificationCenter.default.removeObserver(self, name: UIApplication.keyboardWillShowNotification, object: nil)

        NotificationCenter.default.removeObserver(self, name: UIApplication.keyboardWillHideNotification, object: nil)

 

How to get all key of class in swift

  

var propertiesCount: CUnsignedInt = 0

    let propertiesInClass = class_copyPropertyList(UIDatePicker.self, &propertiesCount)!

    var propertiesDictionary: NSMutableDictionary = [:]

    for i in 0..

              var property = propertiesInClass[Int(i)]

              let propertyName = NSString(cString: property_getName(property), encoding:    String.Encoding.utf8.rawValue)

              print(propertyName)

    }

 

Create Share app Group Directory Folder and Access All image from folder

Create Folder in Share App Group Directory


let image =  UIImage.(named : "imageName")

         let fileManager = FileManager.default

        let path = fileManager.containerURL(forSecurityApplicationGroupIdentifier: "group.companyName.appname")?.appendingPathComponent("FolderName")

        if !fileManager.fileExists(atPath: path!.path) {

            try! fileManager.createDirectory(atPath: path!.path, withIntermediateDirectories: true, attributes: nil)

        }

        let url = NSURL(string: path!.path)

        let imagePath = url!.appendingPathComponent(imageName)

        let urlString: String = imagePath!.absoluteString

        let imageData = image.jpegData(compressionQuality: 1.0)

        fileManager.createFile(atPath: urlString as String, contents: imageData, attributes: nil)

Access All Image From Share App group Folder


class GetAllImages: NSObject {

    static func loadImagesFromAlbum(folderName:String) -> (String,[String]){

        let fileManager = FileManager.default

        let path = fileManager.containerURL(forSecurityApplicationGroupIdentifier: "group.compnyname.appname")

        var theItems = [String]()

        var StaticUrl = String()

        if let dirPath = path?.path

        {

           let imageURL = URL(fileURLWithPath: dirPath).appendingPathComponent(folderName)

            StaticUrl = String(describing: imageURL)            

            do {

                theItems = try FileManager.default.contentsOfDirectory(atPath: imageURL.path)

                return (StaticUrl,theItems)

            } catch let error as NSError {

                print(error.localizedDescription)

                return (StaticUrl,theItems)

            }
        }

        return (StaticUrl,theItems)

    }
}