Skip to content

Instantly share code, notes, and snippets.

View nurtugan's full-sized avatar
🏠
Working from home

Nurtugan Nuraly nurtugan

🏠
Working from home
View GitHub Profile
@nurtugan
nurtugan / PrettyPrint.swift
Created May 29, 2020 05:34
Pretty Print Swift Dictionary
print(String(data: try! JSONSerialization.data(withJSONObject: json, options: .prettyPrinted), encoding: .utf8 )!)
@nurtugan
nurtugan / ObjectMapper.swift
Created June 19, 2020 08:29
Example of mocking json with ObjectMapper
guard let path = Bundle.main.path(forResource: "ScheduleMock", ofType: "json") else {
return
}
do {
let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe)
let schedule = try Mapper<TakeawayScheduleModel>().map(JSONString: data.string)
print(schedule.title)
} catch {
print(error.localizedDescription)
assertionFailure()
@nurtugan
nurtugan / Auto Layout by Tutorials.swift
Last active August 7, 2020 15:22
Useful code snippets from Auto Layout by Tutorials book
// Chapter 1: Introducing Auto Layout
// Chapter 2: Construct Auto Layout with the Interface Builder
// 1
override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
view.addSubview(contactPreviewView)
contactPreviewView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([ // this line of code more performant than activating each constraint individually
contactPreviewView.widthAnchor.constraint(equalToConstant: 150),
contactPreviewView.heightAnchor.constraint(equalToConstant: 150),