Skip to content

Instantly share code, notes, and snippets.

View agoiabel's full-sized avatar

Agoi Abel Adeyemi agoiabel

View GitHub Profile
@agoiabel
agoiabel / autolayout_using_nslayoutconstraint.swift
Last active February 9, 2018 12:53
autolayout_using_nslayoutconstraint.swift
let horizontalConstraint = NSLayoutConstraint(
item: newView,
attribute: NSLayoutAttribute.centerX,
relatedBy: NSLayoutRelation.equal,
toItem: view,
attribute: NSLayoutAttribute.centerX,
multiplier: 1.0,
constant: 0
)
let horizontalConstraint = newView.centerXAnchor.constraint(equalTo: view.centerXAnchor)
view.addConstraints([horizontalConstraint])
newView.setContentCompressionResistancePriority(.defaultHigh, for: .vertical)
newView.setContentHuggingPriority(.defaultLow, for: .horizontal)
//Old way of using var
var myAge = 27; //this can change
var myGender = "Male"; //this cannot change
//To express the above in the new way
let myAge = 27; //I use let because my age will always change
const myGender = "Male";
//Person.js module/class
const Person = {
name: 'Abel'
};
export default Person
//utility module/class
export const baseData = 10;
export const baseUrl = 'agoiabeladeyemi.com';
//We can import the Person class like below:
import Person from './Person';
//We can even give it a different name like below
import Pers from './Person';
//notice the {}
import { baseData } from './Utility';
import { baseUrl } from './Utility';
//we can even use alias like below
import { baseData as SomethingElse } from './Utility';
class Person {
//The constructor will be called first
constructor () {
this.name = 'Abel';
}
printMyName() {
console.dir(this.name);
}
class Human {
constructor () {
this.gender = 'Male';
}
printGender() {
console.dir(this.gender);
}
}
//The extends keyword means