Skip to content

Instantly share code, notes, and snippets.

View nhathm's full-sized avatar
🌴
On vacation

Hoàng Minh Nhật nhathm

🌴
On vacation
View GitHub Profile
import Foundation
struct Student {
let firstName : String
let lastName : String
}
extension Student : Hashable {
static func == (lhs: Student, rhs: Student) -> Bool {
return lhs.firstName == rhs.firstName && lhs.lastName == rhs.lastName
@nhathm
nhathm / Swift-ArraySetDictionary.swift
Last active March 13, 2019 09:29
Swift - Array, Set, Dictionary
import Foundation
import UIKit
// Arrays are ordered collections of values.
// Sets are unordered collections of unique values.
// Dictionaries are unordered collections of key-value associations.
(print("\n=== ARRAY SECTION ===\n"))
// Create empty array of strings
var stringArray = [String]()
@nhathm
nhathm / docker-compose.yml
Created May 3, 2018 15:31 — forked from boiyama/docker-compose.yml
docker-compose.yml configuring GitLab with Container Registry, Pages, CI, Mattermost (enabled WebRTC), and some other options
version: '2'
services:
gitlab:
container_name: gitlab
image: gitlab/gitlab-ce:latest
restart: always
environment:
GITLAB_OMNIBUS_CONFIG: |
## GitLab configuration settings
##! Check out the latest version of this file to know about the different
@nhathm
nhathm / EscapingClosureServerConnection.Swift
Created April 25, 2017 06:43
Sample function connect to server need to be escaping
//: Playground - noun: a place where people can play
// nhathm01247@gmail.com
import Foundation
import UIKit
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
class Worker: NSObject {
@nhathm
nhathm / EscapingClosureSample.Swift
Created April 25, 2017 06:19
Sample closure escaping defination
func getDataFromServer(url: String, completion: @escaping (String?) -> ()) {
//
}
getDataFromServer(url: "http://0.0.0.0:8888/test") { (response) in
//
}
@nhathm
nhathm / GetDataServerNonEscaping.swift
Created April 24, 2017 07:37
Sample about get data from server, this case will be failed because not using @escaping
//: Playground - noun: a place where people can play
// nhathm01247@gmail.com
import Foundation
import UIKit
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
class ServerConnection: NSObject {
@nhathm
nhathm / SwiftClosure-ClosureAsParameters.Swift
Created April 10, 2017 10:28
SwiftClosure-Closure and function as Parameters
//: Playground - noun: a place where people can play
// nhathm01247@gmail.com
import Foundation
// Requirement: write a function take Int, Int, Int and a function that sum first two Int params and then sub the third Int.
// Do it function way
// Declare a function
func add(_ a: Int, _ b: Int) -> Int {
@nhathm
nhathm / SwiftClosure.swift
Created April 10, 2017 10:27
Swift Closure
//: Playground - noun: a place where people can play
// nhathm01247@gmail.com
import Foundation
/** DECLARE A CLOSURE **/
// Declare a variable to hold a closure
var add: (Int, Int) -> Int
@nhathm
nhathm / SwiftClosure-ShorthandClosure.swift
Last active November 6, 2018 07:41
Swift closure - Shorthand Closure
// Declare a variable to hold a closure
var add: (Int, Int) -> Int
/** SHORTHAND SYNTAX **/
// Not need return keyword when only have single return statement
add = {(a: Int, b: Int) -> Int in
a + b
}
add(1, 1)
@nhathm
nhathm / SwiftClosure-DeclareClosure.swift
Created April 7, 2017 08:01
Swift closure - Declare a closure
import Foundation
// Declare a variable to hold a closure
var add: (Int, Int) -> Int
// Assign a closure to a variable
add = { (a: Int, b: Int) -> Int in
return a + b
}