This file contains 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 SwiftUI | |
struct TestView: View { | |
var data = ["Test 1", "Test 2"] | |
var body: some View { | |
ScrollView(.horizontal) { | |
HStack{ | |
ForEach(data, id: \.self) { name in | |
Text(name) |
This file contains 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
extension Sequence { | |
func count(where predicate: (Element) throws -> Bool) rethrows -> Int { | |
try reduce(0) { try predicate($1) ? $0 + 1 : $0 } | |
} | |
} | |
let count = [1,23,4].count(where: { $0 > 2}) | |
print(count) |
This file contains 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 Foundation | |
let test = [1,2,3,4,1,2,2,5,20,2,1,7] | |
// 1- if order of items is important: | |
extension Sequence where Element: Hashable { | |
func unique() -> [Element] { | |
var seen: Set<Element> = [] | |
return filter { seen.insert($0).inserted } | |
} |
This file contains 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 XCTest | |
struct SynchronizedSemaphore<Value> { | |
private let mutex = DispatchSemaphore(value: 1) | |
private var _value: Value | |
init(_ value: Value) { | |
self._value = value | |
} | |
This file contains 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
// | |
// ViewController.swift | |
// Test | |
// | |
// Created by Wasim Alatrash on 1/28/20. | |
// Copyright © 2020 Wasim Alatrash. All rights reserved. | |
// | |
import UIKit | |
import SafariServices |
This file contains 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 Foundation | |
import XCTest | |
protocol Booked { | |
func isEqual(to other: Booked) -> Bool | |
} | |
extension Booked where Self: Equatable{ | |
func isEqual(to other: Booked) -> Bool { | |
if let other = other as? Self{ |
This file contains 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
// | |
// ViewController.swift | |
// ViewCropAndShadow | |
// | |
// Created by Wasim Alatrash on 5/22/18. | |
// Copyright © 2018 Wasim Alatrash. All rights reserved. | |
// | |
import UIKit |