<?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 Sami on Medium]]></title>
        <description><![CDATA[Stories by Sami on Medium]]></description>
        <link>https://medium.com/@imas145?source=rss-d59fa2ffa31b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Sami on Medium</title>
            <link>https://medium.com/@imas145?source=rss-d59fa2ffa31b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 12:30:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@imas145/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[Detecting metal objects with an iPhone]]></title>
            <link>https://medium.com/@imas145/detecting-metal-objects-with-an-iphone-be0a8068a50c?source=rss-d59fa2ffa31b------2</link>
            <guid isPermaLink="false">https://medium.com/p/be0a8068a50c</guid>
            <category><![CDATA[physics]]></category>
            <category><![CDATA[iphone]]></category>
            <category><![CDATA[apps]]></category>
            <category><![CDATA[science]]></category>
            <category><![CDATA[data-visualization]]></category>
            <dc:creator><![CDATA[Sami]]></dc:creator>
            <pubDate>Fri, 13 Jul 2018 10:23:56 GMT</pubDate>
            <atom:updated>2018-07-15T06:01:32.771Z</atom:updated>
            <content:encoded><![CDATA[<p>Yes, this is me shamelessly promoting my new app, <a href="https://itunes.apple.com/us/app/sensors-view-and-record/id1411448316?l=fi&amp;ls=1&amp;mt=8">Sensors</a>, but whatever.</p><h3>Detecting stuff</h3><p>Your iPhone has a built-in <a href="https://en.wikipedia.org/wiki/Magnetometer">magnetometer</a>, and if you have an app for reading the data coming off of it (cough, cough), you can in theory detect anything that changes the surrounding magnetic field. <a href="https://en.wikipedia.org/wiki/Ferromagnetism">Ferromagnets</a> are one such thing. They are basically what people mean when they say magnets. They can be (<a href="https://en.wikipedia.org/wiki/Curie_temperature">semi</a>)permanently magnetized, after which they significantly strengthen the surrounding magnetic field. Iron is one common type of ferromagnetic.</p><p>I wanted to try if you could detect metal objects with just your iPhone, and it turns out you can. In this example, I used my Sensors app to record the magnetometer while moving my phone over an iron nail (with some coating). Here’s the graph of the strength of the magnetic flux with respect to time:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HriTFVvpUiuMaMIXP5odpg.png" /><figcaption>A graph of B(t), where B (magnetic flux strength) is in microteslas</figcaption></figure><p>You can see a fairly clear change in the magnetic field (well, flux strength), indicating that nail I moved the phone over! It’s not a big difference, but it’s still there. What I haven’t tested yet is does it work for looking metal inside a wall or something similar. I move my phone pretty close to the nail, and the change was in the order of 10s of microteslas — not that much. You might also be able to detect non-ferromagnetic materials, such as aluminium, but their effects on a magnetic field are less significant and therefore harder to detect.</p><p>Another phenomenon that causes a change in the magnetic field is electricity. Specifically, electricity moving through a conducting wire creates a magnetic field around the wire, which should be detectable. And, spoiler alert, it is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ev2SR2m0evssFSf2VNlnmQ.png" /></figure><p>Again, not a very significant change, but a change regardless. What should be noted is some of the effect is caused by the metals inside the wire, but not all. As you might have noticed, measuring things handheld with a phone isn’t exactly the most scientific way.</p><h3>Conclusion</h3><p>There you have it. Metal and electricity detection with your iPhone, with some caveats. Should this replace any specialized equipment? Of course not. Can it work in a hurry when you don’t have anything else or you’re just curious about your surroundings? Sure.</p><p><em>If you’re trying this yourself with </em><a href="https://itunes.apple.com/us/app/sensors-view-and-record/id1411448316?l=fi&amp;ls=1&amp;mt=8"><em>Sensors</em></a><em> and you’re just seeing a straight zero line, make sure you’ve selected uncalibrated in the calibration options.</em></p><h3>Bonus: walking around the house</h3><p>Depending on who you are, it might be fun to walk around your house and measure different devices and appliances to see how strong of a magnetic field they produce. It’s super easy to notice with a realtime graph and won’t take more than a few minutes, so give it a go if you’re at all interested. Here’s an example of what a Sonos Play:5 looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HBSsnpyfXA35owRTDqMOpA.png" /><figcaption>Now that’s detectable! Notice the y-axis, where reaching over 2 teslas. It looks like the flux strength changed faster than my set sampling frequency could nicely handle, hence the jagged graph.</figcaption></figure><p>Finally, here’s a video of my fridge to demonstrate what it would look like right in the app, without recording and graphing later on:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F1XY5PKkz3y0%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D1XY5PKkz3y0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F1XY5PKkz3y0%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d85bde4e99388b2a0bb4b89a6d4a5d2/href">https://medium.com/media/9d85bde4e99388b2a0bb4b89a6d4a5d2/href</a></iframe><p><em>If you’re worried about this strange magnetic stuff in your house, don’t be: it’s not harmful.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be0a8068a50c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Memory Graph Debugger in Xcode 9]]></title>
            <link>https://medium.com/@imas145/using-memory-graph-debugger-in-xcode-9-a50aa9d0243f?source=rss-d59fa2ffa31b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a50aa9d0243f</guid>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[xcode]]></category>
            <dc:creator><![CDATA[Sami]]></dc:creator>
            <pubDate>Sun, 22 Oct 2017 13:49:06 GMT</pubDate>
            <atom:updated>2017-10-22T15:03:09.806Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve never really took the time to properly learn how to use Instruments. Sure, I know how to use Time Profiler and find leaks but I have a feeling there’s a lot of untapped potential there.</p><p>When Xcode 9 launched with the Memory Graph Debugger, I was really excited. Maybe I could keep on being lazy and not learn Instruments. And so far, it has worked. I can use the memory gauge in Xcode to identify when a possible leak occurs and then use the Memory Graph Debugger to identify it.</p><p>I’ve recently published <a href="https://itunes.apple.com/us/app/subs-manage-subscriptions/id1298572434?l=fi&amp;ls=1&amp;mt=8">an app called Subs on the App Store</a>. It’s for managing all your subscriptions in an easy way. When working on the next version that would enable using Touch ID and Face ID, I tested the lock screen by repeatedly closing and unlocking the app. I noticed that the memory usage kept growing on each unlock.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7XRXNmqwRWh0DRESnnoNIA.png" /><figcaption>Something’s clearly wrong here. The memory shouldn&#39;t grow as the data itself doesn’t change. This is an indication that there’s a memory leak somewhere. And no Instruments!</figcaption></figure><p>Tapping the little graph icon next to the view debugger loads the Memory Graph Debugger.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ubZVeXjwhpb74XgTWDEB_w.png" /><figcaption>The Memory Graph Debugger</figcaption></figure><p>Scrolling through the heap memory on the left, I noticed something that shouldn’t be there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*BgdTSuUf7qX00NzibEPEnQ.png" /><figcaption>Wait. 5 instances of the LockScreenViewController and PageViewController? 25 instances of SubscriptionViewController?</figcaption></figure><p>There should be only one instance of the PageViewController, yet there’re five of them. Additionally, there should be only one ViewController and in this case only five SubscriptionViewControllers. Why were these additional instances created? And more precisely, why weren’t the previous ones being purged?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d56e8af71d295ca58ba8248f471ec631/href">https://medium.com/media/d56e8af71d295ca58ba8248f471ec631/href</a></iframe><p>This is the basic code that displays the lock screen if needed. It replaces the root view controller, so why are the previous view controllers kept in memory?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EhbLW4e6BkU0i_leTi7ooA.png" /><figcaption>Look at all those references</figcaption></figure><p>Clicking on one of the PageViewControllers, its memory graph is shown. It basically shows all the object that reference this particular PageViewController. You can see some expected references, but there’s one that caught my eye: why is the SubscriptionsViewController referencing the PageViewController as it should go the other way around. This turned out to be the culprit. Instead of the PageViewController referencing all the SubscriptionViewControllers, there was an inverse reference as well that kept the PageViewController in memory and in turn all the SubscriptionViewControllers. Clicking on the arrow connecting the two, you can see the type of reference, which in this case was strong.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bo44Sb_AY5GKV2zrc_GBRA.png" /><figcaption>Whoops, a strong reference</figcaption></figure><p>Since it’s a strong reference, it alone is enough to keep all of them in memory. So why is there a strong reference? Because I put it there (a rookie mistake for a rookie)</p><p>In some cases, the app needs to switch pages by actions that occur within a SubscriptionViewController. Instead of playing with notifications or delegates (which I probably should’ve), I just added a property to the SubscriptionViewController that contained the page view controller.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7e13104958f115d5fabf0ce0827bb3a/href">https://medium.com/media/d7e13104958f115d5fabf0ce0827bb3a/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0071fa975a6f86036cdcfb409021ae01/href">https://medium.com/media/0071fa975a6f86036cdcfb409021ae01/href</a></iframe><p>Luckily, the solution is very simple: just make the reference weak:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/192daddcc030ac58f0386cb20ac93b40/href">https://medium.com/media/192daddcc030ac58f0386cb20ac93b40/href</a></iframe><p>But finding this without the handy Memory Graph Debugger in Xcode 9, I’m not sure how I would’ve found it out. I’m sure Instruments could’ve told me this but I wouldn’t have known where to look.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a50aa9d0243f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>