Skip to content

Instantly share code, notes, and snippets.

@IhwanID
Created October 8, 2020 20:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IhwanID/48aacf3d1fe9fd8df7014b9988c45146 to your computer and use it in GitHub Desktop.
Save IhwanID/48aacf3d1fe9fd8df7014b9988c45146 to your computer and use it in GitHub Desktop.
Tokopedia Playground
import UIKit
import PlaygroundSupport
//let view2 = UIView()
//view2.alpha = 0.5
let parrentView = UIView(frame: CGRect(x: 0, y: 0, width: 80, height: 80))
parrentView.backgroundColor = .red
let childView = UIView(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
childView.backgroundColor = .blue
childView.translatesAutoresizingMaskIntoConstraints = false
parrentView.addSubview(childView)
NSLayoutConstraint.activate([
childView.bottomAnchor.constraint(equalTo: parrentView.bottomAnchor, constant: 0),
childView.trailingAnchor.constraint(equalTo: parrentView.trailingAnchor, constant: 0),
childView.widthAnchor.constraint(equalToConstant: 40),
childView.heightAnchor.constraint(equalToConstant: 40),
])
//parrentView.addSubview(childView)
//childView.frame = CGRect(x: 20, y: 20, width: 40, height: 40)
//childView.backgroundColor = .cyan
//parrentView.addSubview(childView)
func printNumber()-> String{
var temp: [Int] = []
var numberValidator: Int?
for i in stride(from: 20, to: 0, by: -1){
if let num = numberValidator, num != 0{
temp.append(num)
numberValidator = nil
}else if i % 5 == 0{
numberValidator = i
}else{
continue
}
}
return temp.map(String.init).joined(separator: ",")
}
print(printNumber())
func printTokopedia(){
for i in 0..<3{
print("\(i) => Tokopedia")
}
}
func printAcademy(){
for i in 0..<3{
print("\(i) => Academy")
}
}
func globalQueueTest(){
let globalQueu = DispatchQueue.global()
globalQueu.sync {
printTokopedia()
}
globalQueu.sync {
printAcademy()
}
}
globalQueueTest()
PlaygroundPage.current.liveView = parrentView
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment