Skip to content

Instantly share code, notes, and snippets.

View ihak's full-sized avatar
🦅
Working

Hassan Ahmed Khan ihak

🦅
Working
View GitHub Profile
@ihak
ihak / ProductBySKU.json
Last active March 20, 2017 15:18
Example json of productbysku api
{
"response_code": "200",
"response_status": "success",
"response_message": "",
"id": "67",
"sku": "MH01",
"name": "Chaz Kangeroo Hoodie",
"type": "configurable",
"regular_price": "52",
"discounted_price": "0",
// 1.
// Instantiate a view object
let view = UIView()
// 2.
// Set translatesAutoresizingMaskIntoConstraints property to false to
// explicitly applying constraints to the view
// 1.
// Instantiate a view object
let view = UIView()
// 2.
// Set translatesAutoresizingMaskIntoConstraints property to false to
// explicitly applying constraints to the view
view.translatesAutoresizingMaskIntoConstraints = false
// 1. Instantiate a label and a textfield
let firstNameLabel = UILabel()
firstNameLabel.text = "First"
firstNameLabel.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(firstNameLabel)
let firstNameTextField = UITextField()
firstNameTextField.borderStyle = .roundedRect
// Method that returns a single row of a chessboard
func getRow(of length: Int, for rowNo: Int) -> UIView {
let containerView = UIView()
var previousTile: UIView?
for i in 0...length {
// Instantiate a tile view and add it to container
let tile = UIView()
tile.translatesAutoresizingMaskIntoConstraints = false
// Method that returns a single row of a chessboard
func getRow(of length: Int, for rowNo: Int) -> UIView {
let containerView = UIView()
var previousTile: UIView?
for i in 0...length {
// Instantiate a tile view and add it to container
let tile = UIView()
tile.translatesAutoresizingMaskIntoConstraints = false
// 1. Instantiate the UILayoutGuide instance and give it an identifier
// Note: 'UI' prefix in identifier is fixed for guides created by UIKit.
let guide = UILayoutGuide()
guide.identifier = "layoutguide"
// 2. Add the guide to the view just like we add a subview
// to its parent view.
self.view.addLayoutGuide(guide)
// Pinning with the top layout guide
topView.topAnchor.constraint(equalTo: self.topLayoutGuide.bottomAnchor).isActive = true
// Pinning with the bottom layout guide
bottomView.bottomAnchor.constraint(equalTo: self.bottomLayoutGuide.topAnchor).isActive = true
// 1. Instantiate 3 buttons, set their titles and set
// translatesAutoresizingMaskIntoConstraints property to false.
// Also add them to the superview.
let saveButton = UIButton(type: .roundedRect)
saveButton.setTitle("Save", for: .normal)
saveButton.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(saveButton)
let revertButton = UIButton(type: .roundedRect)
// 1. Instantiate 3 buttons, set their titles and set
// translatesAutoresizingMaskIntoConstraints property to false.
// Also add them to the superview.
let saveButton = UIButton(type: .roundedRect)
saveButton.setTitle("Save", for: .normal)
saveButton.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(saveButton)
let revertButton = UIButton(type: .roundedRect)