<?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 Abhishek shakya on Medium]]></title>
        <description><![CDATA[Stories by Abhishek shakya on Medium]]></description>
        <link>https://medium.com/@abhishakya44?source=rss-1157f61b6753------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2fMbI6Dw1yGwrlm268w8Ag.jpeg</url>
            <title>Stories by Abhishek shakya on Medium</title>
            <link>https://medium.com/@abhishakya44?source=rss-1157f61b6753------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 01:09:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abhishakya44/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[Design Custom Notification Center]]></title>
            <link>https://medium.com/@abhishakya44/design-custom-notification-center-520e1bb9efee?source=rss-1157f61b6753------2</link>
            <guid isPermaLink="false">https://medium.com/p/520e1bb9efee</guid>
            <dc:creator><![CDATA[Abhishek shakya]]></dc:creator>
            <pubDate>Sun, 21 Apr 2024 20:05:55 GMT</pubDate>
            <atom:updated>2024-04-21T20:05:55.520Z</atom:updated>
            <content:encoded><![CDATA[<pre>struct NotificationName: Hashable {<br>    let rawValue: String<br>}<br>// Extension to add predefined notification names<br>extension NotificationName {<br>    static let testNotification = NotificationName(rawValue: &quot;TestNotification&quot;)<br>    // Add other notifications as needed<br>}<br><br>class CustomNotification {<br>    let name: NotificationName<br>    let userInfo: [AnyHashable: Any]?<br>    init(name: NotificationName, userInfo: [AnyHashable: Any]?) {<br>        self.name = name<br>        self.userInfo = userInfo<br>    }<br>}<br><br><br>import Foundation<br>class CustomNotificationCenter {<br>    static let shared = CustomNotificationCenter()<br>    <br>    private struct ObserverEntry {<br>        weak var observer: AnyObject?<br>        let method: (CustomNotification) -&gt; Void<br>    }<br>    private var observers = [NotificationName: [ObserverEntry]]()<br>    private let queue = DispatchQueue(label: &quot;com.custom.notificationCenter.queue&quot;, attributes: .concurrent)<br>    private init() {}<br>    func addObserver(_ observer: AnyObject, method: @escaping (CustomNotification) -&gt; Void, name: NotificationName) {<br>        let entry = ObserverEntry(observer: observer, method: method)<br>        queue.async(flags: .barrier) {<br>            self.observers[name]?.append(entry) ?? (self.observers[name] = [entry])<br>        }<br>    }<br>    func removeObserver(_ observer: AnyObject, name: NotificationName) {<br>        queue.async(flags: .barrier) {<br>            self.observers[name]?.removeAll { $0.observer === observer || $0.observer == nil }<br>        }<br>    }<br>    func post(name: NotificationName, userInfo: [AnyHashable: Any]? = nil) {<br>        let notification = CustomNotification(name: name, userInfo: userInfo)<br>        queue.sync {<br>            guard let entries = self.observers[name] else { return }<br>            entries.forEach { entry in<br>                if let observer = entry.observer {<br>                    entry.method(notification)<br>                }<br>            }<br>        }<br>    }<br>}<br><br><br>Uses:<br>class TestClass: NSObject {<br>    func receiveNotification(_ notification: CustomNotification) {<br>        if let userInfo = notification.userInfo {<br>            print(&quot;Received notification with info: \(userInfo)&quot;)<br>        } else {<br>            print(&quot;Received notification&quot;)<br>        }<br>    }<br>}<br>let testObject = TestClass()<br>CustomNotificationCenter.shared.addObserver(testObject, method: testObject.receiveNotification, name: .testNotification)<br>CustomNotificationCenter.shared.post(name: .testNotification, userInfo: [&quot;Key&quot;: &quot;Value&quot;])<br>CustomNotificationCenter.shared.removeObserver(testObject, name: .testNotification)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=520e1bb9efee" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>