This file contains 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 Dictionary { | |
var prettyPrintedJSON: String? { | |
do { | |
let data: Data = try JSONSerialization.data(withJSONObject: self, options: .prettyPrinted) | |
return String(data: data, encoding: .utf8) | |
} catch _ { | |
return nil | |
} | |
} | |
This file contains 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 Data { | |
func toString() -> String? { | |
let str = String(data: self, encoding: .utf8) | |
return str | |
} | |
func toDictionary() -> [String: Any]? { | |
do { | |
return try JSONSerialization.jsonObject(with: self, options: []) as? [String: Any] | |
} catch { |
This file contains 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
1. In capabilities need to turn on the iCloud and tick the iCloud Documnet in services. Choose the container and note | |
down its name. (because while setting up settings inside info.plist we. need to set the NSUbiquitousContainers key value | |
same as this name). | |
2. We need to define the iCloud Drive Container that we are going to use inside info.plist | |
<key>NSUbiquitousContainers</key> | |
<dict> | |
<key>this has to be same as selected containers name inside entitlement</key> | |
<dict> |
This file contains 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
To Do CRUD operation in Core Data, we need to do the following things: | |
1. Get reference of NSPersistentContainer. | |
eg. lazy var persistentContainer: NSPersistentContainer (inside Appdelegate) | |
2. Get context from persistentContainer | |
eg. let context = persistentContainer.viewContext (inside Appdelegate) | |
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext (inside ViewController) | |
3. Call fetch, save and delete over this context |
This file contains 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 UIView { | |
func addAutolayoutSubview(_ view: UIView){ | |
view.translatesAutoresizingMaskIntoConstraints = false | |
addSubview(view) | |
} | |
func apply<T:UIView>(_ view: T, completion:((T))->Void){ | |
completion(view) | |
} | |
} |
This file contains 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 RelatedItemsTableView: UITableView, UITableViewDelegate, UITableViewDataSource { | |
var items = [Items]() { | |
didSet{ | |
self.reloadData() | |
} | |
} | |
var headerTitles = [String]() { | |
didSet { | |
self.reloadSections(IndexSet.init(arrayLiteral: 0), with: .automatic) |