Created
October 8, 2020 20:03
-
-
Save IhwanID/48aacf3d1fe9fd8df7014b9988c45146 to your computer and use it in GitHub Desktop.
Tokopedia Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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