<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sahibuddin Ahmed on Medium]]></title>
        <description><![CDATA[Stories by Sahibuddin Ahmed on Medium]]></description>
        <link>https://medium.com/@sahibuddin?source=rss-98a807434d5c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*3NP_kJ9HFtPnEnCt.jpg</url>
            <title>Stories by Sahibuddin Ahmed on Medium</title>
            <link>https://medium.com/@sahibuddin?source=rss-98a807434d5c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 04:59:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sahibuddin/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[An Overview of Class, Structure, Enum, and Actor in Swift]]></title>
            <link>https://medium.com/@sahibuddin/an-overview-of-class-structure-enum-and-actor-in-swift-8aeed415cce6?source=rss-98a807434d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8aeed415cce6</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Sahibuddin Ahmed]]></dc:creator>
            <pubDate>Fri, 04 Aug 2023 13:54:30 GMT</pubDate>
            <atom:updated>2023-08-04T13:54:30.830Z</atom:updated>
            <content:encoded><![CDATA[<p>Swift is a powerful and modern programming language developed by Apple for iOS, macOS, watchOS, and tvOS app development. It provides developers with a range of language constructs to build robust and efficient code. Among these constructs are Class, Structure, Enum, and more recently introduced, Actor. Each of these types plays a crucial role in shaping the architecture and functionality of Swift applications. In this article, we will explore these types, their differences, and their best use cases.</p><h3>1. Class:</h3><p>In Swift, a Class is a reference type that allows developers to create objects with properties and methods. It supports inheritance, enabling the creation of subclasses that can inherit and extend the functionality of the parent class. Some key features of classes include:</p><ul><li>Reference Semantics: When you assign a class instance to a variable or pass it as an argument, you are dealing with references rather than creating a new copy. Changes made to one reference will affect all other references pointing to the same instance.</li><li>Inheritance: Classes can be inherited, allowing for code reuse and hierarchical organization of data and behavior.</li><li>Deinitializer: Classes can define a deinitializer (deinit) to perform cleanup tasks before an instance is deallocated from memory.</li></ul><pre>class Person {<br>    var name: String<br>    var age: Int<br><br>    init(name: String, age: Int) {<br>        self.name = name<br>        self.age = age<br>    }<br><br>    func sayHello() {<br>        print(&quot;Hello, my name is \(name) and I am \(age) years old.&quot;)<br>    }<br>}<br><br>// Creating instances of the Person class<br>let person1 = Person(name: &quot;John&quot;, age: 30)<br>let person2 = person1 // person2 is now referring to the same object as person1<br><br>person1.sayHello() // Output: &quot;Hello, my name is John and I am 30 years old.&quot;<br>person2.sayHello() // Output: &quot;Hello, my name is John and I am 30 years old.&quot;<br><br>// Modifying the properties of person1<br>person1.name = &quot;Jane&quot;<br>person1.sayHello() // Output: &quot;Hello, my name is Jane and I am 30 years old.&quot;<br><br>// As person2 points to the same object as person1, it reflects the change<br>person2.sayHello() // Output: &quot;Hello, my name is Jane and I am 30 years old.&quot;</pre><p><strong>Classes</strong> are well-suited for scenarios that require complex object hierarchies, shared data models, or when reference semantics are essential.</p><h3>2. Structure:</h3><p>A Structure, commonly referred to as a “struct,” is a value type in Swift. Unlike classes, structs are copied when assigned to variables or passed as arguments. Each copy is entirely independent of others, making them suitable for managing small pieces of data or modeling lightweight objects. Key features of structs include:</p><ul><li>Value Semantics: Whenever you assign a struct instance to a new variable or pass it as a function argument, a copy of the struct is created. Changes made to the copy will not affect the original instance.</li><li>No Inheritance: Unlike classes, structs do not support inheritance, which means you cannot create subclasses or derive new types from them.</li><li>Automatic Memberwise Initializer: Swift generates a default initializer (constructor) for structs, known as the memberwise initializer, which allows you to initialize its properties conveniently.</li></ul><pre>struct Point {<br>    var x: Int<br>    var y: Int<br>}<br><br>// Creating instances of the Point struct<br>var point1 = Point(x: 10, y: 20)<br>var point2 = point1 // point2 is now a copy of point1<br><br>point1.x = 30<br>print(point1) // Output: &quot;Point(x: 30, y: 20)&quot;<br>print(point2) // Output: &quot;Point(x: 10, y: 20)&quot;</pre><p><strong>Structs</strong> are ideal for small data structures, immutable objects, and situations where copy-on-write behavior can offer performance benefits.</p><h3>3. Enum:</h3><p>An Enum (enumeration) in Swift is a distinct type that defines a group of related values. Enums can have associated values, making them more versatile than traditional enumerations found in other programming languages. Some essential characteristics of enums include:</p><ul><li>Associated Values: Each case of an enum can hold different types of associated values, allowing you to model complex data structures elegantly.</li><li>Raw Values: Enums can be assigned raw values of a specific type, such as integers or strings, which can be used for serialization and other purposes.</li><li>Pattern Matching: Swift’s powerful pattern matching capabilities work seamlessly with enums, enabling developers to handle different cases and associated values effectively.</li></ul><pre>enum Direction {<br>    case north<br>    case south<br>    case east<br>    case west<br>}<br><br>// Using enums in a switch statement<br>let direction = Direction.north<br><br>switch direction {<br>case .north:<br>    print(&quot;Heading North&quot;)<br>case .south:<br>    print(&quot;Heading South&quot;)<br>case .east:<br>    print(&quot;Heading East&quot;)<br>case .west:<br>    print(&quot;Heading West&quot;)<br>}<br><br>// Output: &quot;Heading North&quot;</pre><p><strong>Enums</strong> with associated values:</p><pre>enum Result {<br>    case success(message: String)<br>    case failure(error: String)<br>}<br><br>let successResult = Result.success(message: &quot;Data fetched successfully.&quot;)<br>let failureResult = Result.failure(error: &quot;Network error occurred.&quot;)<br><br>switch successResult {<br>case .success(let message):<br>    print(&quot;Success: \(message)&quot;)<br>case .failure(let error):<br>    print(&quot;Failure: \(error)&quot;)<br>}<br><br>// Output: &quot;Success: Data fetched successfully.&quot;</pre><p><strong>Enums</strong> are valuable when modeling a finite set of related possibilities or states in your code. They can be used to represent choices, states, error conditions, and more.</p><h3>4. Actor:</h3><p>Introduced in Swift 5.5, an Actor is a new type that addresses the challenges of concurrent programming. Concurrency allows multiple tasks to execute simultaneously, but it can lead to race conditions and other bugs if not managed correctly. Actors provide a structured approach to concurrent programming, ensuring that only one piece of code can access the actor’s state at a time, thereby preventing data races. Key features of Actors include:</p><ul><li>Isolation: An actor encapsulates its mutable state and operations, ensuring that access to that state occurs serially.</li><li>Asynchronous Messaging: To interact with an actor’s state, you send it asynchronous messages. The actor processes the messages one at a time, maintaining consistency and safety.</li></ul><pre>actor Counter {<br>    private var count = 0<br><br>    func increment() {<br>        count += 1<br>    }<br><br>    func getCount() -&gt; Int {<br>        return count<br>    }<br>}<br><br>// Creating an instance of the Counter actor<br>let counter = Counter()<br><br>// Accessing the actor&#39;s state asynchronously using `await`<br>Task {<br>    await counter.increment()<br>    await counter.increment()<br>    let count = await counter.getCount()<br>    print(&quot;Count: \(count)&quot;) // Output: &quot;Count: 2&quot;<br>}</pre><p>In the above example, the actor Counter encapsulates its mutable state (count) and ensures that access to it is serially managed by using await. The asynchronous code block within the Task is executed concurrently, but the actor guarantees that only one piece of code can access the Counter state at a time, preventing data races.</p><p><strong>Actors</strong> are beneficial when dealing with concurrent code and can be used to manage shared resources, maintain application state, or synchronize access to data across multiple tasks.</p><p>In conclusion, understanding the differences and best use cases of Class, Structure, Enum, and Actor is crucial for writing efficient, maintainable, and scalable Swift code. Each type serves specific purposes and offers different memory management and concurrency characteristics, allowing developers to make informed decisions about which one to use in different scenarios. By leveraging these language constructs effectively, developers can build robust and performant applications for various Apple platforms.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8aeed415cce6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unleashing the Power of PDFKit in iOS]]></title>
            <link>https://medium.com/@sahibuddin/unleashing-the-power-of-pdfkit-in-ios-59eadda13ec5?source=rss-98a807434d5c------2</link>
            <guid isPermaLink="false">https://medium.com/p/59eadda13ec5</guid>
            <category><![CDATA[pdfkit]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Sahibuddin Ahmed]]></dc:creator>
            <pubDate>Fri, 04 Aug 2023 04:08:48 GMT</pubDate>
            <atom:updated>2023-08-04T04:14:17.211Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>What is PDFKit?</strong></p><p>PDFKit is a framework provided by Apple for iOS, macOS, and other Apple platforms. It is designed to give developers access to powerful PDF rendering, annotation, and text extraction capabilities. With PDFKit, developers can effortlessly display and interact with PDF documents, whether it’s viewing, searching, or adding annotations.</p><p><strong>Features and Functionalities of PDFKit</strong></p><ol><li>PDF Rendering: PDFKit enables high-quality rendering of PDF documents, ensuring crisp and clear display of text, images, and other graphical elements. Developers can present PDFs using either standard views or customize the display as per the app’s design.</li><li>Text Extraction: Extracting text from PDF files is a common requirement in many applications. PDFKit makes this task simple and efficient, enabling developers to extract text from specific pages or the entire document.</li><li>Annotations: PDFKit supports various types of annotations, such as text highlights, notes, comments, and more. Users can create, edit, and delete annotations, providing a versatile document interaction experience.</li><li>Search Functionality: Users can easily search for specific text within a PDF document using the built-in search functionality offered by PDFKit. This enhances document navigation and improves the overall user experience.</li><li>Thumbnail Generation: PDFKit allows developers to generate thumbnails of PDF pages, which can be used for previews or in document navigation features.</li><li>Printing Support: Printing PDF documents directly from your iOS application is made possible with PDFKit, making it easy for users to get hard copies of their documents.</li></ol><p><strong>Implementing PDFKit in Your iOS App</strong></p><p>Now, let’s walk through the steps to integrate PDFKit into your iOS application:</p><p>Step 1: Setting Up the Project Create a new iOS project in Xcode or open an existing one. Ensure that the deployment target is set to iOS 11 or later, as PDFKit is available from iOS 11 onwards.</p><p>Step 2: Import PDFKit Framework Import the PDFKit framework into your project. You can do this by clicking on the project file, selecting the target, and then navigating to the “Frameworks, Libraries, and Embedded Content” section. Click the ‘+’ button, search for ‘PDFKit,’ and add it to the project.</p><p>Step 3: Displaying a PDF To display a PDF in your app, you’ll need a PDFView. In Interface Builder, add a UIView to your ViewController and change its class to PDFView. Alternatively, you can create a PDFView programmatically in your ViewController’s code.</p><p><strong>Load the PDF from a local file</strong></p><pre>import PDFKit<br><br>class ViewController: UIViewController {<br>    @IBOutlet weak var pdfView: PDFView!<br><br>    override func viewDidLoad() {<br>        super.viewDidLoad()<br><br>        // Load the PDF from a local file<br>        if let pdfURL = Bundle.main.url(/service/forresource: &quot;example&quot;, withExtension: &quot;pdf&quot;) {<br>            if let pdfDocument = PDFDocument(url: pdfURL) {<br>                pdfView.document = pdfDocument<br>            }<br>        }<br>    }<br>}</pre><p><strong>Load the PDF from a Remote URL</strong></p><pre>import UIKit<br>import PDFKit<br><br>class ViewController: UIViewController {<br>    @IBOutlet weak var pdfView: PDFView!<br><br>    override func viewDidLoad() {<br>        super.viewDidLoad()<br>        <br>        // Replace &quot;your_remote_pdf_url&quot; with the actual URL of the remote PDF file.<br>        guard let url = URL(string: &quot;your_remote_pdf_url&quot;) else {<br>            print(&quot;Invalid URL for the remote PDF file.&quot;)<br>            return<br>        }<br>        <br>        // Perform a network request to download the PDF data.<br>        URLSession.shared.dataTask(with: url) { (data, response, error) in<br>            guard let data = data, error == nil else {<br>                print(&quot;Error downloading the PDF: \(error?.localizedDescription ?? &quot;Unknown error&quot;)&quot;)<br>                return<br>            }<br>            <br>            // Initialize the PDFDocument with the downloaded data on the main thread.<br>            DispatchQueue.main.async {<br>                if let pdfDocument = PDFDocument(data: data) {<br>                    self.pdfView.document = pdfDocument<br>                    self.pdfView.autoScales = true // Auto-scales the PDF to fit the view<br>                } else {<br>                    print(&quot;Failed to create PDFDocument from the downloaded data.&quot;)<br>                }<br>            }<br>        }.resume()<br>    }<br>}</pre><p>Step 4: Additional Functionality Once you have a PDFView in your app, you can explore other functionalities like text extraction, annotation support, and search features. Check Apple’s official documentation for detailed information on each feature.</p><p>Conclusion</p><p>PDFKit is a powerful framework that enables iOS developers to work with PDF documents seamlessly. From rendering to text extraction and annotations, PDFKit offers a wide range of functionalities to enhance your app’s document management capabilities. With the step-by-step guide provided in this article, you can quickly integrate PDFKit into your iOS application and provide a delightful experience for users dealing with PDF documents. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59eadda13ec5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>