Skip to content

Instantly share code, notes, and snippets.

View almaleh's full-sized avatar
💭
Indexing...

Besher Al Maleh almaleh

💭
Indexing...
View GitHub Profile
DispatchQueue.global().async {
print("Generic global queue")
}
DispatchQueue.global(qos: .userInteractive).async {
print("We're on a global concurrent queue!")
}
URLSession.shared.dataTask(with: url) { data, response, error in
if let data = data {
DispatchQueue.main.async { // UI work
self.label.text = String(data: data, encoding: .utf8)
}
}
}
class ViewController: UIViewController {
let concurrent = DispatchQueue(label: "com.besher.concurrent", attributes: .concurrent)
let isolation = DispatchQueue(label: "com.besher.isolation", attributes: .concurrent)
private var _array = [1,2,3,4,5]
var threadSafeArray: [Int] {
get {
return isolation.sync {
_array
}
class ViewController: UIViewController {
let concurrent = DispatchQueue(label: "com.besher.concurrent", attributes: .concurrent)
var array = [1,2,3,4,5]
override func viewDidLoad() {
for _ in 0...1 {
race()
}
}
// add this after the last async statement,
// still inside starterQueue.async
backgroundQueue.sync {}
enum Color: String {
case blue = "🔵"
case white = "⚪️"
}
func output(color: Color, times: Int) {
for _ in 1...times {
print(color.rawValue)
}
}
func processImage(data: Data) -> UIImage? {
guard let image = UIImage(data: data) else { return nil }
// calling an expensive function
let processedImage = upscaleAndFilter(image: image)
return processedImage
}
ACTION = build
AD_HOC_CODE_SIGNING_ALLOWED = NO
ALTERNATE_GROUP = staff
ALTERNATE_MODE = u+w,go-w,a+rX
ALTERNATE_OWNER = grantdavis
ALWAYS_SEARCH_USER_PATHS = NO
ALWAYS_USE_SEPARATE_HEADERMAPS = YES
APPLE_INTERNAL_DEVELOPER_DIR = /AppleInternal/Developer
APPLE_INTERNAL_DIR = /AppleInternal
APPLE_INTERNAL_DOCUMENTATION_DIR = /AppleInternal/Documentation
func setupAnimator() {
let context = (view: self.view,
navigationItem: self.navigationItem,
parent: self.parent
)
let anim = UIViewPropertyAnimator(duration: 2.0, curve: .linear) {
context.view?.backgroundColor = .red
context.navigationItem.rightBarButtonItems?.removeAll()