<?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 Aline Kolczycki Borges on Medium]]></title>
        <description><![CDATA[Stories by Aline Kolczycki Borges on Medium]]></description>
        <link>https://medium.com/@alinekborges?source=rss-80a45bca1972------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*MgxEn4AigKK5tFu-f5NdFw.jpeg</url>
            <title>Stories by Aline Kolczycki Borges on Medium</title>
            <link>https://medium.com/@alinekborges?source=rss-80a45bca1972------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 14:24:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alinekborges/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[Tracking Screen Views in SwiftUI with a Custom ViewModifier]]></title>
            <link>https://medium.com/@alinekborges/tracking-screen-views-in-swiftui-with-a-custom-viewmodifier-7a52e8f00f89?source=rss-80a45bca1972------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a52e8f00f89</guid>
            <category><![CDATA[viewmodifier]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swiftui]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[analytics]]></category>
            <dc:creator><![CDATA[Aline Kolczycki Borges]]></dc:creator>
            <pubDate>Wed, 16 Apr 2025 13:44:56 GMT</pubDate>
            <atom:updated>2025-04-16T13:44:56.805Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*_b5MiJckjWVHWwkqsoxxwg.png" /></figure><p>When building an iOS app, screen view analytics can be incredibly helpful for understanding user behavior and improving UX. It helps you answer questions like:</p><ul><li>Which screens do users spend the most time on?</li><li>Are users discovering the features you think are important?</li><li>Where are users dropping off?</li></ul><p><strong>The Basic Approach</strong></p><p>Here’s a quick and simple way to log a screen view when a SwiftUI view appears. The analytics class here is represented by Static methods, but that can be adapted.</p><pre>struct SettingsView: View {<br>  var body: some View {<br>    ZStack {<br>      Text(&quot;Settings&quot;)<br>    }<br>    .onAppear {<br>      Analytics.screenView(&quot;Settings&quot;)<br>    }<br>  }<br>}</pre><p>This works fine, but once your app grows, adding this manually to every screen can get repetitive and error-prone. That’s where a reusable ViewModifier comes in.</p><p><strong>Custom ViewModifier</strong></p><p>To make screen view tracking consistent and more ergonomic, I created a custom ViewModifier. This made it easy to add analytics events to every important view with only one line of code.</p><p>This implementation is using a String to identify each view, but it could be easily changed to an enum if that is the preference.</p><pre>struct SettingsView: View {<br>  var body: some View {<br>    ZStack {<br>      Text(&quot;Settings&quot;)<br>    }<br>    .screenViewEvent(&quot;SettingsView&quot;)<br>  }<br>}</pre><p>Under the hood, this is the implementation of the View Modifier.</p><pre>struct ScreenViewAnalyticsModifier: ViewModifier {<br>  let screen: String<br>  let extraParameters: [String: String]?<br><br>  func body(content: Content) -&gt; some View {<br>    content.onAppear {<br>      Analytics.screenView(screen, extraParameters: extraParameters)<br>    }<br>  }<br>}<br><br>extension View {<br>  func screenViewEvent(_ screen: String, extraParameters: [String: String]? = nil) -&gt; some View {<br>    self.modifier(ScreenViewAnalyticsModifier(screen: screen, extraParameters: extraParameters))<br>  }<br>}</pre><p><strong>Make it even cleaner</strong></p><p>Honestly, why pass the string ( SettingsView) if most of the times the screen name is just exactly the same as the struct/file name? We can take advantage of that and make it even simpler to use:</p><pre>struct SettingsView: View {<br>  var body: some View {<br>    ZStack {<br>      Text(&quot;Settings&quot;)<br>    }<br>    .screenViewEvent()<br>  }<br>}</pre><p>But how to get exactly the file name? If you print #file anywhere in the app, you will get the full path of the current file</p><p>/Users/alineborges/.../ios/Sources/Folder/SettingsView.swift</p><p>There are many different ways of extracting the class name from this, but this is the implementation I&#39;m using</p><pre>extension String {<br>  var className: String {<br>    let lastPathComponent = (self as NSString).lastPathComponent<br><br>    guard let viewNameComponent = lastPathComponent.components(separatedBy: &quot;.&quot;).first else {<br>      return &quot;unknown&quot;<br>    }<br><br>    return viewNameComponent<br>  }</pre><p>Then we can make a small change to the ViewModifier</p><pre>struct ScreenViewAnalyticsModifier: ViewModifier {<br>  let screen: String<br>  let extraParameters: [String: String]?<br><br>  func body(content: Content) -&gt; some View {<br>    content.onAppear {<br>      Analytics.screenView(screen, extraParameters: extraParameters)<br>    }<br>  }<br>}<br><br>extension View {<br>  func screenViewEvent(_ screen: String = #file, extraParameters: [String: String]? = nil) -&gt; some View {<br>    self.modifier(ScreenViewAnalyticsModifier(screen: screen.className, extraParameters: extraParameters))<br>  }<br>}</pre><p>Now, we can easily add analytics everywhere without even thinking about it! The downside is that, if you want to align the Screen Name with the Android app, for example, the classes would need to have exactly the same name. But there is always the fallback to the string (or enum) if you want to a better control of the event name.</p><p><strong>Why This Is Better</strong></p><p>• ✅ <strong>Consistency</strong> — All screen view logging goes through one place.</p><p>• 🧼 <strong>Cleaner Views</strong> — Keeps analytics logic out of your main UI code.</p><ul><li>🔍 <strong>Flexibility</strong> — You can easily pass contextual info with extra parameters.</li></ul><p><strong>Final Code</strong></p><pre>//AnalyticsModifier.swift<br><br>import Foundation<br>import SwiftUI<br><br>struct ScreenViewAnalyticsModifier: ViewModifier {<br><br>  let screen: String<br>  let extraParameters: [String: String]?<br><br>  func body(content: Content) -&gt; some View {<br>    content.onAppear {<br>      Analytics.screenView(screen.className, extraParameters: extraParameters)<br>    }<br>  }<br>}<br><br>extension View {<br>  func screenViewEvent(_ screen: String = #file, <br>                       extraParameters: [String: String]? = nil) -&gt; some View {<br>    self.modifier(ScreenViewAnalyticsModifier(screen: screen, <br>                                              extraParameters: extraParameters))<br>  }<br>}<br><br>extension String {<br>  var className: String {<br>    let lastPathComponent = (self as NSString).lastPathComponent<br><br>    guard let viewNameComponent = lastPathComponent.components(separatedBy: &quot;.&quot;).first else {<br>      return &quot;unknown&quot;<br>    }<br><br>    return viewNameComponent<br>  }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a52e8f00f89" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[URLSession tampering with AVPlayer]]></title>
            <link>https://medium.com/@alinekborges/urlsession-tampering-with-avplayer-03bc8f41156c?source=rss-80a45bca1972------2</link>
            <guid isPermaLink="false">https://medium.com/p/03bc8f41156c</guid>
            <category><![CDATA[hls]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[urlsessions]]></category>
            <category><![CDATA[avplayer]]></category>
            <dc:creator><![CDATA[Aline Kolczycki Borges]]></dc:creator>
            <pubDate>Thu, 08 Aug 2024 20:26:00 GMT</pubDate>
            <atom:updated>2024-08-08T20:27:52.321Z</atom:updated>
            <content:encoded><![CDATA[<p>AVPlayer is a versatile media playback framework developed by Apple, designed to handle the seamless playback of audio and video content on iOS and macOS devices. Leveraging advanced features like adaptive streaming, precise control over playback, and support for a wide range of media formats, AVPlayer provides developers with a powerful tool to integrate high-quality multimedia experiences into their applications.</p><p>However, AVPlayer also has limitations, particularly in its customization options. If you need to implement features like certificate pinning, mTLS (mutual TLS), authentication, or any modifications to the URL session, you are in for a ride.</p><p>At Harbor, we prioritize secure connections to cameras by implementing certificate pinning and mutual TLS for all local connections. Normally, we achieve this by implementing URLSession delegate and responding to the <a href="https://developer.apple.com/documentation/foundation/urlauthenticationchallenge">URLAuthenticationChallenge</a> . With AVPlayer, that is just not possible</p><h3><strong>The problem</strong></h3><ul><li>AVPlayer does have a delegate called AVAssetResourceLoaderDelegate</li><li>It includes a function resourceLoader(_:shouldWaitForResponse to: AuthChallenge)</li><li>However, the ResourceLoaderDelegate is not called if you use http or https urls. You need to change to a custom scheme for any of the delegate functions to be called (<a href="https://stackoverflow.com/questions/57408355/avassetresourceloaderdelegate-methods-not-called">StackOverflow</a>). So switching to something like custom://baseurl/video.mp4 is the only way to make it work.</li><li>If we change the url to a custom scheme, now AVPlayer won&#39;t do any of the video loading we usually get for free. By going this route, you need to implement all of the data downloading, content information requests by yourself. <a href="https://jaredsinclair.com/2016/09/03/implementing-avassetresourceload.html">Here is a really great example of this usage</a>. This works for .mp3 or .mp4 or normal video streaming.</li><li>However, this <strong>does not work for HLS videos</strong> (<a href="https://stackoverflow.com/questions/39962882/video-streaming-fails-when-using-avassetresourceloader">StackOverflow</a> and <a href="https://developer.apple.com/forums/thread/113063">Apple Forum</a>).</li></ul><h3>The solution</h3><p>Using a reverse Proxy Server to control the responses to requests using our custom URLSession but still letting AVPLayer handle everything else.</p><p>This was the solution proposed for offline caching using HLS. This <a href="https://github.com/garynewby/HLS-video-offline-caching/tree/main?tab=readme-ov-file">github</a> has a good explanation of how it is done. In summary, it spins up a local reverse proxy server. It substitutes every .ts in the playlist file to this custom proxy server. This custom server fetches the Data requested (using a URLSession we can play with) and responds to the AVPlayer original requests. An updated repository by <a href="https://github.com/garynewby/HLS-video-offline-caching/tree/main?tab=readme-ov-file">Gary Newby</a> using a different cache library.</p><p>Since our use case did not need caching, just tampering with the URLSession, I proposed this github with my solution build on top of theirs.</p><p>Using the CustomHLSService , you can pass your own URLSession with the delegates needed for implementing response to AuthChallenges. If you need to customize a bit more the requests, implementing the HLSService protocol allow for further customization.</p><p>To use it, instantiate the proxy with the server you want to use. It can be either the provided service with a custom URLSession or a entire custom Service.</p><pre> let service = CustomHSLService(urlSession: URLSession.shared)<br> self.proxy = HLSVideoProxy(server: webServer, service: service)</pre><p>To set it up, create the AVPlayer item, reverse proxy the URL and start the service</p><pre>func setup() {<br>  guard let url = URL(string: testVideoURL) else {<br>    print(&quot;Invalid URL&quot;)<br>    return<br>  }<br><br>  guard let videoURL = proxy.reverseProxyURL(from: url) else {<br>    print(&quot;Invalid url format&quot;)<br>    return<br>  }<br><br>  let playerItem = AVPlayerItem(url: videoURL)<br>  self.player.replaceCurrentItem(with: playerItem)<br>  self.proxy.start()<br>}</pre><p>Full code in <a href="https://github.com/alinekborges/HLS-AVPlayer-URLSession">Github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=03bc8f41156c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Parallax Header with just constraints!]]></title>
            <link>https://medium.com/@alinekborges/parallax-header-with-just-constraints-c3df8a9244fc?source=rss-80a45bca1972------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3df8a9244fc</guid>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[parallax]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[constraints]]></category>
            <dc:creator><![CDATA[Aline Kolczycki Borges]]></dc:creator>
            <pubDate>Mon, 25 Feb 2019 01:16:28 GMT</pubDate>
            <atom:updated>2019-02-25T19:23:24.534Z</atom:updated>
            <content:encoded><![CDATA[<p>So, you want the best possible experience for your user. It’s been very usual now for apps to use a large image as a header to create a nice visual element, while giving context to what’s being displayed. But you don’t want to have just a blend image, you want that awesome header with Parallax Effect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/428/1*7qAAyKqttkiNdxfo5FIqJw.gif" /></figure><p>It does look kind of hard to implement, right? It will probably involve a lot of code. But no, actually not. If your layout is an UIScrollView, you can do it just tweaking the constraints you probably already have, zero code. If it’s a UITableView, you can implement the same logic (but you will need a little bit of code, unfortunately).</p><p>{ <em>Disclaimer:</em> if you do view code, just do the exact same constraints in your code. It should work exactly the same way }</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/428/1*KCNcHuhGBG3eyvQxDPTU8w.gif" /></figure><p>We are going to start from a layout using scroll view. To save time, you can find the base project <a href="https://github.com/alinekborges/ios-parallax-constraints/tree/START_HERE">here</a>. (Please note it&#39;s the START_HERE branch). This is a base layout with a vertical scroll view. The scroll view uses the size of the text to calculate how much it needs to scroll vertically.</p><p>The view hierarchy goes as follow:</p><pre>&gt;BaseView<br> &gt;UIScrollView<br>  &gt;ContentView<br>   &gt;UIImageView<br>   &gt;DescriptionView</pre><p>The DescriptionView is just a container view to the help simplifying the content layout. It includes the profile picture, name and the whole description long label.</p><p>The constraints in the header image right now are as following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/370/1*_Lx-NS-lrQXYcWHipwVojw.png" /></figure><p>As the header image is pinned to the top of the whole ContentView, the image simply scrolls with the image. This is not the behaviour we want if we want the parallax effect.</p><h4><strong>{ Before we start }</strong></h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F5w2OH5cRGXVD2%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F5w2OH5cRGXVD2%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F5w2OH5cRGXVD2%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="403" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f185bf8038b8a6346e6222787bdaa12/href">https://medium.com/media/8f185bf8038b8a6346e6222787bdaa12/href</a></iframe><p>The one thing that makes it possible for this to work is the ScaleAspectFill mode, together with clipsToBounds=true in the UIImageView. Why?</p><p>ScaleAspectFill mode will not resize the image as the height shrinks. It will actually clip the borders and center the image in the middle. Look again at the .gif of the parallax effect. The actual effect is clipping the top and bottom of the image and recenter the image! As simple as that.</p><p>So, don&#39;t forget to set your header UIImageView with the following settings:</p><ul><li>Content mode = ScaleAspectFill</li><li>clipsToBounds = true</li></ul><h3><strong>{ Playing with Constraints }</strong></h3><h4><strong>{ Step 1 }</strong></h4><p>The first thing we need to do is to <strong>delete</strong> the top constraint to the superview. We will change that to a <strong>top constraint</strong> in relation to the BaseView. That means our header image is now pinned to the static view now, and will now just scroll with the content.</p><p>What to do:</p><ul><li><strong>Delete </strong>header image top constraint</li><li><strong>Add </strong>top constraint in relation to base view</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*i2KSYGV2Xxd8ycvU2T_oFg.gif" /></figure><h4><strong>{ Step 2 }</strong></h4><p>So, before, we had a fixed height of 320 for the header image. Now, as it scrolls, the actual image height will be smaller (and eventually zero, as the image is scrolled outside of the page). We need to change that, but still keeping a starting height for the image.</p><p>What to do:</p><ul><li><strong>Add</strong> a top constraint for the profile view to the top, with a constant of that image size (320)</li><li><strong>Delete</strong> the height constraint from the header image</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/1*x7IgOqO61qNyeOjcExs1IQ.gif" /></figure><p>By doing that, keeping in mind the image is now pinned to a fixed top position, the height of the image is now defined by the position of that profile view, that starts with a 320 offset from the top.</p><h4>{ Step 3 }</h4><p>If you run now, it works. Cool! But there is a log telling you there is a conflicting constraint. Why?</p><p>As I mentioned before, the height is now defined by the position of that ProfileView. What happens when that is scrolled outside of the window? Can we have a negative height? Nope! The system is trying to figure out which one of those constraints you want and which constraint can be broken.</p><p>It&#39;s simple to fix that. Just tell the system which one of those constraints you want to be broken before the others. That is done by changing the priority. We should change the priority of the constraint that <strong>pins the header view to the top.</strong> That way, when it&#39;s supposed to be scrolled out of the window, it will. But when it&#39;s supposed to be showing, that constraint will be possible again and the system will use that to calculate the layout.</p><p>What to do:</p><ul><li>Change the <strong>priority</strong> of the constraint that pins the header to the top to <strong>900</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/1*v728Q_2CApaokQqjX38M6A.gif" /></figure><h4>{ Final result }</h4><p>That&#39;s it! Now you have an awesome parallax header for your image! Here is the final result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/428/1*7qAAyKqttkiNdxfo5FIqJw.gif" /><figcaption>Final result</figcaption></figure><p>Some things you might want to do think about to make this even better:</p><ul><li>Instead of using a fixed 320 height, how could you make it proportional to the screen (for example, a 3:2 proportion)?</li><li>What if you want to animate the navigation bar alpha, so it shows only when the image is collapsed? (this may need some coding)</li><li>To simplify, I did not mention safe area. How could we make dealing with that better?</li></ul><p>And that&#39;s it! You just made a parallax header with just constraints! Never underestimate their power, we can do more with constraints than we might think.</p><p>You can download the final project <a href="https://github.com/alinekborges/ios-parallax-constraints">here</a>.</p><p><a href="https://github.com/alinekborges">alinekborges - Overview</a></p><figure><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_image"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f2IVAl0TbsfES9cFGYr40g.png" /></a></figure><p>📝 Read this story later in <a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_read_later_text">Journal</a>.</p><p>🗞 Wake up every Sunday morning to the week’s most noteworthy Tech stories, opinions, and news waiting in your inbox: <a href="https://usejournal.com/newsletter/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_text">Get the noteworthy newsletter &gt;</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3df8a9244fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>