<?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 Swagat Mishra on Medium]]></title>
        <description><![CDATA[Stories by Swagat Mishra on Medium]]></description>
        <link>https://medium.com/@swagatm13?source=rss-d14aa945fa19------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*VlEXN71wUq_e7Nxd</url>
            <title>Stories by Swagat Mishra on Medium</title>
            <link>https://medium.com/@swagatm13?source=rss-d14aa945fa19------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 03:58:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@swagatm13/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[Generic Badge for SwiftUI view]]></title>
            <link>https://medium.com/@swagatm13/generic-badge-for-swiftui-view-29f9f266ba64?source=rss-d14aa945fa19------2</link>
            <guid isPermaLink="false">https://medium.com/p/29f9f266ba64</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[viewmodifier]]></category>
            <dc:creator><![CDATA[Swagat Mishra]]></dc:creator>
            <pubDate>Sun, 05 Jan 2025 07:18:07 GMT</pubDate>
            <atom:updated>2025-01-06T16:59:08.069Z</atom:updated>
            <content:encoded><![CDATA[<p>SwiftUI provides an in-built badge modifier that can be used to display fresh content on your views like new messages, notification counts etc. However, the modifier is limited to displaying numeric values only and cannot be used for any generic content if needed. Let’s build that.</p><p>First, let’s create a configuration struct to capture any specific values for the custom badge view.</p><pre>struct BadgeConfiguration {<br>  var padding: EdgeInsets = .init()<br>  var foregroundColor: Color = .primary<br>  /// Add any other configuration values here as needed.<br>}</pre><p>Now let’s create the view modifier by passing in the configuration and a generic view to be used as the badge itself.</p><pre>struct BadgeModifier&lt;Badge: View&gt;: ViewModifier {<br>  let configuration: BadgeConfiguration<br>  var badge: (() -&gt; Badge)?<br>  func body(content: Content) -&gt; some View {<br>    content<br>      .overlay(alignment: .topTrailing) {<br>        badge?()<br>          .padding(configuration.padding)<br>          .foregroundStyle(configuration.foregroundColor)<br>      }<br>  }<br>}</pre><p>Finally, let’s create a view extension to make the above modifier use easy and convenient.</p><pre>extension View {<br>  func badge&lt;Badge: View&gt;(configuration: BadgeConfiguration = .init(), badge: (() -&gt; Badge)?) -&gt; some View {<br>    modifier(BadgeModifier(configuration: configuration, badge: badge))<br>  }<br>}</pre><p>We are all done. This can now be used across any view as below:</p><pre>var contentView: some View {<br>  customImageView<br>    .badge(configuration: .init()) {<br>      // Pass custom view here.<br>      Image(systemName: &quot;camera)<br>    }<br>}</pre><p>Hope this helps. Have fun!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29f9f266ba64" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Extracting Exif from Photos Picker Selection — SwiftUI]]></title>
            <link>https://medium.com/@swagatm13/extracting-exif-from-photos-picker-selection-swiftui-9c05de2fa046?source=rss-d14aa945fa19------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c05de2fa046</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[photos]]></category>
            <category><![CDATA[imagepicker]]></category>
            <category><![CDATA[exif]]></category>
            <category><![CDATA[swiftui]]></category>
            <dc:creator><![CDATA[Swagat Mishra]]></dc:creator>
            <pubDate>Thu, 19 Dec 2024 23:28:24 GMT</pubDate>
            <atom:updated>2024-12-19T23:28:24.493Z</atom:updated>
            <content:encoded><![CDATA[<h3>Extracting Exif from Photos Picker Selection — SwiftUI</h3><p><em>Some ways to fetch and extract metadata information from image items selected from swiftUI photos picker.</em></p><p>If you are working on a photos application and need to access the metadata of the asset, requesting information like GPS data, creation timestamp, software and camera information etc, iOS photos library provides an easy way of accessing this by requesting the imageData from the photos library. Add the following to the code where we need to extract the metadata.</p><p>Let’s begin by creating a PHImageRequestOptions object. This is used to configure information like which version of an asset to fetch (if original asset was edited), if the request is synchronous, etc.</p><pre>let options = PHImageRequestOptions()<br>options.isSynchronous = true<br>options.isNetworkAccessAllowed = true<br>options.version = .current<br>options.deliveryMode = .highQualityFormat<br>options.resizeMode = .none</pre><p>Now we can request an PHImageManager to retrieve the asset.</p><pre>PHImageManager<br>  .default()<br>  .requestImageDataAndOrientation(for: asset, options: options) { data, uti, orientation, info in<br>        guard let data else { return }<br>        // Use binary data as needed.<br>      }</pre><p>The returned Data object would carry the asset itself along with all information and metadata about the same.</p><p><strong>Things to Look out For</strong></p><p>PHImageManager also shares another API method that can be requested to fetch the image asset. While this does provide the additional flexibility of returning the asset in a custom size and compressed, the resulting image does lose out on a lot of it’s metadata values.</p><pre>PHImageManager<br>  .default()<br>  .requestImage(<br>        for: asset,<br>        targetSize: .maxSize,<br>        contentMode: .aspectFit,<br>        options: options) { result, _ in<br>          image = result<br>          // Returned image can have some exif information but not all.<br>      }</pre><p>Picking a method depends on the specific requirements and application needs.</p><p><strong>Limitations</strong></p><p>While the above methods are quick and efficient in returning the asset, its image and metadata together, it does fail in cases when the user has not provided full-access to photos library. For these conditions, the metadata retrieval would need to be done in a different way which I would in a different article soon.</p><p>Hope this helps. Have fun!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c05de2fa046" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PhoneNumberTextField for SwiftUI]]></title>
            <link>https://medium.com/@swagatm13/phonenumbertextfield-for-swiftui-1415c54d742e?source=rss-d14aa945fa19------2</link>
            <guid isPermaLink="false">https://medium.com/p/1415c54d742e</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[textfield]]></category>
            <category><![CDATA[phone-number-validation]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[uikit]]></category>
            <dc:creator><![CDATA[Swagat Mishra]]></dc:creator>
            <pubDate>Thu, 19 Dec 2024 23:04:49 GMT</pubDate>
            <atom:updated>2024-12-19T23:04:49.127Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Using </em><a href="https://github.com/marmelroy/PhoneNumberKit"><em>PhoneNumberKit</em></a></p><p><a href="https://github.com/marmelroy/PhoneNumberKit">PhoneNumberKit</a> is a great API for displaying and validating international phone numbers and used across iOS applications. However the API currently lacks support for SwiftUI and the available version of the PhoneNumberTextField is only present for UIKit. This article will implement a UIViewRepresentable to extend the view to be used across SwiftUI applications as well. Let’s begin.</p><p>A simple implementation of the above would require us to create a custom view passing the API’s version of the textfield in it’s makeUIView method. The extended view can now use any custom configurations that need to be passed on.</p><pre>import PhoneNumberKit<br><br>struct CustomSwiftUIPhoneNumberTextField: UIViewRepresentable {<br>// Pass in a binding string to capture the input.<br>  @Binding var text: String<br><br>// Return PhoneNumberKit.PhoneNumberTextField as the return view.<br>  func makeUIView(context: Context) -&gt; PhoneNumberTextField {<br>    let phoneNumberTextField = PhoneNumberTextField()<br>    phoneNumberTextField.translatesAutoresizingMaskIntoConstraints = false<br>/*<br>Configure any additional parameters.<br>    phoneNumberTextField.tintColor = .white<br>    phoneNumberTextField.withExamplePlaceholder = true<br>    phoneNumberTextField.withFlag = true<br>    phoneNumberTextField.delegate = context.coordinator<br>    phoneNumberTextField.textContentType = .telephoneNumber<br>    phoneNumberTextField.keyboardType = .phonePad<br>*/<br>    return phoneNumberTextField<br>  }<br><br>  func updateUIView(_ uiView: PhoneNumberTextField, context: Context) {<br>    uiView.text = text<br>    uiView.textContentType = .telephoneNumber<br>  }<br><br>  func makeCoordinator() -&gt; Coordinator {<br>    Coordinator(self)<br>  }<br><br>// Need to configure a co-ordinator to capture UIKit delegate implementation.<br>  class Coordinator: NSObject, UITextFieldDelegate {<br>    var parent: PHXPhoneNumberTextField<br><br>    init(_ parent: PHXPhoneNumberTextField) {<br>      self.parent = parent<br>    }<br><br>    func textFieldDidChangeSelection(_ textField: UITextField) {<br>      if let phoneNumberTextField = textField as? PhoneNumberTextField {<br>        parent.text = phoneNumberTextField.text ?? &quot;&quot;<br>      }<br>    }<br>  }<br>}</pre><p>Hope this helps. Have fun!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1415c54d742e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Device Fingerprinting on SwiftUI]]></title>
            <link>https://medium.com/@swagatm13/device-fingerprinting-on-swiftui-e2226d9feb6e?source=rss-d14aa945fa19------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2226d9feb6e</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[fingerprint]]></category>
            <category><![CDATA[fraud]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Swagat Mishra]]></dc:creator>
            <pubDate>Mon, 16 Dec 2024 07:35:31 GMT</pubDate>
            <atom:updated>2024-12-19T21:52:24.960Z</atom:updated>
            <content:encoded><![CDATA[<p>Protecting against fradulent attacks is a very important aspect of building robust and secure applications that will be useful to the end-user. While Apple has a strong policy against fingerprinting and what information can or cannot be allowed through fingerprint, there are many frameworks that provide useful fraud protection mechanisms. One such framework that we will explore in this tutorial is <a href="https://dev.fingerprint.com/">FingerprintiOS</a>.</p><p>Fingerprint uses browser and device fingerprinting along with advanced server techniques, like statistical ID generation and machine learning, to create a unique visitor ID such as xPFysGV25VxZcGQUxVIt. This ID stays the same over time, even if the device’s settings or software changes or if cookies are deleted or unavailable.</p><p>Utitlizing Fingerprint for iOS apps involves a very simple few steps to get going.</p><p>Add the following to your package.swift file:</p><pre>// Package.swift<br>let package = Package(<br>  // ...<br>  dependencies: [<br>    .package(url: &quot;https://github.com/fingerprintjs/fingerprintjs-pro-ios&quot;, from: &quot;2.0.0&quot;)<br>  ]<br>  // ...<br>)</pre><p>Or if using cocoa pods, add the following to your podfile:</p><pre>#Podfile<br>pod &#39;FingerprintPro&#39;, &#39;~&gt; 2.0&#39;</pre><p>Once enabled, add the following to your SwifUI file:</p><pre>class FingerPrintManager {<br>    let configuration = Configuration(apiKey: &quot;&lt;Your_API_Key_here&gt;&quot;)<br>    lazy var client = FingerprintProFactory.getInstance(configuration)<br>    <br>    func getVisitorId() async {<br>        do {<br>            let visitorId = try await client.getVisitorId()<br>            print(visitorId)<br>        } catch {<br>            print(error.localizedDescription)<br>        }<br>    }<br>}<br></pre><p>Finally call the getVisitorId function in the swiftui view .onAppear:</p><pre>.onAppear {<br>  Task {<br>    await FingerPrintManager().getVisitorId()<br>  }<br>}</pre><p>You will see a fingerprint info like OV1s5gzheIjIM0aV9sio printed on the console. This information can be sent to the application servers to identify users and prevent fraud.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2226d9feb6e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Constraints made simple — iOS UIKit]]></title>
            <link>https://medium.com/@swagatm13/constraints-made-simple-ios-uikit-e7f12f72cf46?source=rss-d14aa945fa19------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7f12f72cf46</guid>
            <category><![CDATA[nslayoutconstraint]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[uikit]]></category>
            <dc:creator><![CDATA[Swagat Mishra]]></dc:creator>
            <pubDate>Sun, 08 Dec 2024 08:09:19 GMT</pubDate>
            <atom:updated>2024-12-08T08:09:19.326Z</atom:updated>
            <content:encoded><![CDATA[<h3>Constraints made simple — iOS UIKit</h3><p>With the advent of SwiftUI and it’s drag-and-drop interface, a lot of the new apps are leveraging the powerful new tool. However, majority of iOS applications still use UIKit for managing and handling their UI. SwiftUI still lacks a lot of the intricacies of UIKit which is a whole different chapter. In this article, we will explore how we can make UI designing and positioning even easier with UIKit.</p><p>Consider a simple use-case where we want a button in the center of the screen. Using NSLayoutConstraint would require us to specify something like:</p><pre>NSLayoutConstraint.activate([<br>  loginButton.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 32),<br>  loginButton.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -32),<br>  loginButton.heightAnchor.constraint(equalToConstant: 50),<br>  loginButton.centerYAnchor.constraint(equalTo: view.centerYAnchor)<br>])</pre><p>Additionally, the below setting must be configured for each view otherwise the constraints won’t work.</p><pre>loginButton.translatesAutoresizingMaskIntoConstraints = false</pre><p>Imagine having multiple UI elements on each page and the number of lines required to set for each. The time and effort to design and debug is tiresome. Nevermind if we need to edit any specific constraint parameters like it’s priority or dynamically adjusting them, it becomes extremely complex. Can we make it simpler????</p><p>With only a few utility methods and extension on NSLayoutConstraints, the above code can be much simpler to look at and debug. Imagine the above code of setting the constraints being simplified like below:</p><pre>let loginConstraints = <br>  loginButton.anchor(<br>    leading: view.leadingAnchor, <br>    trailing: view.trailingAnchor,<br>    centerY: view.centerYAnchor,<br>    leadingConstant: 32,<br>    trailingConstant: 32,<br>    heightConstant: 50<br>  )<br>NSLayoutConstraints.activate(loginConstraints)</pre><p>The function anchor(_) takes all specific constraints and abstracts the implementation of applying translatesAutoresizingMaskIntoConstraints, setting each constraint and return for any adjustments later on. This also allows edits to any parameter possible for each constraint including their priority, system-spacing and others. Here’s the full implementation of the function.</p><pre>    @discardableResult func anchor(<br>        leading: NSLayoutXAxisAnchor? = nil,<br>        top: NSLayoutYAxisAnchor? = nil,<br>        trailing: NSLayoutXAxisAnchor? = nil,<br>        bottom: NSLayoutYAxisAnchor? = nil,<br>        centerX: NSLayoutXAxisAnchor? = nil,<br>        centerY: NSLayoutYAxisAnchor? = nil,<br>        width: NSLayoutDimension? = nil,<br>        height: NSLayoutDimension? = nil,<br>        leadingConstant: CGFloat = 0.0,<br>        topConstant: CGFloat = 0.0,<br>        trailingConstant: CGFloat = 0.0,<br>        bottomConstant: CGFloat = 0.0,<br>        centerXConstant: CGFloat = 0.0,<br>        centerYConstant: CGFloat = 0.0,<br>        widthConstant: CGFloat = 0.0,<br>        heightConstant: CGFloat = 0.0,<br>        leadingMultiplier: CGFloat? = nil,<br>        topMultipler: CGFloat? = nil,<br>        trailingMutiplier: CGFloat? = nil,<br>        bottomMultiplier: CGFloat? = nil,<br>        centerXMultiplier: CGFloat? = nil,<br>        centerYMultiplier: CGFloat? = nil,<br>        widthMultiplier: CGFloat = 1.0,<br>        heightMultiplier: CGFloat = 1.0,<br>        leadingPriority: UILayoutPriority = .required,<br>        topPriority: UILayoutPriority = .required,<br>        trailingPriority: UILayoutPriority = .required,<br>        bottomPriority: UILayoutPriority = .required,<br>        centerXPriority: UILayoutPriority = .required,<br>        centerYPriority: UILayoutPriority = .required,<br>        widthPriority: UILayoutPriority = .required,<br>        heightPriority: UILayoutPriority = .required,<br>        leadingRelation: ConstraintRelation = .equalTo,<br>        topRelation: ConstraintRelation = .equalTo,<br>        trailingRelation: ConstraintRelation = .equalTo,<br>        bottomRelation: ConstraintRelation = .equalTo,<br>        centerXRelation: ConstraintRelation = .equalTo,<br>        centerYRelation: ConstraintRelation = .equalTo,<br>        widthRelation: ConstraintRelation = .equalTo,<br>        heightRelation: ConstraintRelation = .equalTo,<br>        leadingIdentifier: String? = nil,<br>        topIdentifier: String? = nil,<br>        trailingIdentifier: String? = nil,<br>        bottomIdentifier: String? = nil,<br>        centerXIdentifier: String? = nil,<br>        centerYIdentifier: String? = nil,<br>        widthIdentifier: String? = nil,<br>        heightIdentifier: String? = nil<br>    ) -&gt; [NSLayoutConstraint] {<br>        translatesAutoresizingMaskIntoConstraints = false<br>        var constraints: [NSLayoutConstraint] = []<br>        <br>        constraints.append(<br>            contentsOf:<br>                anchorMargins(<br>                    leading: leading,<br>                    top: top,<br>                    trailing: trailing,<br>                    bottom: bottom,<br>                    leadingConstant: leadingConstant,<br>                    topConstant: topConstant,<br>                    trailingConstant: trailingConstant,<br>                    bottomConstant: bottomConstant,<br>                    leadingPriority: leadingPriority,<br>                    topPriority: topPriority,<br>                    trailingPriority: trailingPriority,<br>                    bottomPriority: bottomPriority,<br>                    leadingRelation: leadingRelation,<br>                    topRelation: topRelation,<br>                    trailingRelation: trailingRelation,<br>                    bottomRelation: bottomRelation,<br>                    leadingIdentifier: leadingIdentifier,<br>                    topIdentifier: topIdentifier,<br>                    trailingIdentifier: trailingIdentifier,<br>                    bottomIdentifier: bottomIdentifier<br>                )<br>        )<br>        <br>        constraints.append(<br>            contentsOf:<br>                anchorDimension(<br>                width: width,<br>                height: height,<br>                widthMultiplier: widthMultiplier,<br>                heightMultiplier: heightMultiplier,<br>                widthConstant: widthConstant,<br>                heightConstant: heightConstant,<br>                widthPriority: widthPriority,<br>                heightPriority: heightPriority,<br>                widthRelation: widthRelation,<br>                heightRelation: heightRelation,<br>                widthIdentifier: widthIdentifier,<br>                heightIdentifier: heightIdentifier<br>            )<br>        )<br>        <br>        constraints.append(<br>            contentsOf:<br>                anchorAxis(<br>                    centerX: centerX,<br>                    centerY: centerY,<br>                    centerXConstant: centerXConstant,<br>                    centerYConstant: centerYConstant,<br>                    centerXPriority: centerXPriority,<br>                    centerYPriority: centerYPriority,<br>                    centerXRelation: centerXRelation,<br>                    centerYRelation: centerYRelation,<br>                    centerXIdentifier: centerXIdentifier,<br>                    centerYIdentifier: centerYIdentifier<br>                )<br>        )<br>        <br>        return constraints<br>    }</pre><p>Check out the full project on github: <a href="https://github.com/swagat0405/Constraintify.git">https://github.com/swagat0405/Constraintify.git</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7f12f72cf46" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>