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
struct Car { | |
private var maxSpeed: Int = 10 | |
mutating func increaseLimit() { | |
maxSpeed += 10 | |
} | |
} | |
struct VehicleManager: ~Copyable { |
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
struct SpecialMessage: ~Copyable { | |
private var transmitterId: String | |
private var cipher: String | |
init(transmitterId: String, cipher: String) { | |
self.transmitterId = transmitterId | |
self.cipher = cipher | |
} | |
//one time decryption |
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 Foundation | |
import Synchronization | |
final class SafeDictionary { | |
static let shared = SafeDictionary() | |
private init() {} | |
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
// | |
// ContentView.swift | |
// ActorSample | |
// | |
// Created by Daniyal Yousuf | |
// | |
import SwiftUI | |
//no need to use nslock or dispatchqueue or other locking as we would do in case of a class |
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
// | |
// ContentView.swift | |
// SendableProtocol | |
// | |
// Created by Daniyal Yousuf | |
// | |
import SwiftUI | |
//thread safe class before being passed to an Actor |
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
protocol CarComponent: AnyObject { | |
var name: String { get } | |
func getPrice() -> Double | |
func displayDetails() | |
} | |
final class Part: CarComponent { | |
let name: String | |
private let price: Double | |
init(name: String, price: Double) { |
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
//if vs switch expressions //Swift 5.9 | |
enum Status { | |
case Pass | |
case Fail | |
case Merit | |
} | |
let result = if (Int.random(in: 0...100)) > 50 { Status.Pass } else { Status.Fail } |
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
struct PulsationView: View { | |
// MARK: - PROPERTIES | |
@State private var animation: Double = 0.0 | |
// MARK: - BODY | |
var gradientColor = LinearGradient(gradient: Gradient(colors: [.green, .yellow]), | |
startPoint: .top, | |
endPoint: .bottom) |
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 Foundation | |
///////Points to Remember | |
//1 - serial - only 1 thread | |
//2 - concurrent - multiple threads | |
//3 - async tasks - tasks can be submitted to either a serial queue or a concurrent queue. | |
//4- sync tasks - tasks can be submitted to either a serial queue or a concurrent queue. | |
//5 - If sync tasks are submitted to either a serial queue or a concurrent, only 1 task will execute at a time because of its synchronous nature. | |
//6 - if async tasks are submitted to a concurrent queue, multiple tasks will execute at a time because of their asynchronous nature. But we can limit the number of tasks to be executed using DispatchSemaphore |
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
protocol FruitCart { | |
var price: Double? { get } | |
func checkPrice() | |
} | |
class FruitExpenses { | |
var fruit: FruitCart? | |
func checkPrice(fruit: FruitCart) { | |
self.fruit = fruit | |
fruit.checkPrice() |
NewerOlder