<?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 Jordan Guggenheim on Medium]]></title>
        <description><![CDATA[Stories by Jordan Guggenheim on Medium]]></description>
        <link>https://medium.com/@jgugges?source=rss-c2d39b07119d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*InqfyiazV50B9MpWGUO0Ag.jpeg</url>
            <title>Stories by Jordan Guggenheim on Medium</title>
            <link>https://medium.com/@jgugges?source=rss-c2d39b07119d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 07:18:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jgugges/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[iOS Scroll Performance Tutorial]]></title>
            <link>https://tech.okcupid.com/ios-scroll-performance-tutorial-e4aac86866b3?source=rss-c2d39b07119d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4aac86866b3</guid>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Jordan Guggenheim]]></dc:creator>
            <pubDate>Fri, 16 Jun 2017 15:02:48 GMT</pubDate>
            <atom:updated>2021-12-12T05:47:32.832Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OtmzVM0aUxUeEoBvvkKCbw.jpeg" /></figure><p>At OkCupid, 30% of iPhone users have a device that we consider to be underpowered. This makes it extremely important that we code our app to perform optimally across <em>all</em> devices.</p><p>We monitor our user retention by device model and there have been times when poorly optimized features have caused users on older devices to have up to 7% lower retention. It reaffirms to us that the fit and finish of an app really matters!</p><p>Also, with the release of new iPads with 120hz displays, the bar has been raised to deliver ultra high performance scrolling experiences.</p><h3>This tutorial</h3><p>This tutorial will go in depth on how to successfully debug CPU bottlenecks using Apple’s Time Profiler, walking through an example project plagued with scrolling performance issues. ☠️ ☠️ ☠️</p><p>The goal is that by the time you’re done, you will have a much better understanding of how to spot deficiencies in your own app. I will also share a few optimization techniques that we employ here at OkCupid.</p><p><strong>It’s important to remember the following:</strong></p><ul><li>The practice of optimizing your app can sometimes be a tradeoff between writing simplistic or performant code. The key to success is striking the balance.</li></ul><p>For example, <a href="https://github.com/texturegroup/texture">AsyncDisplayKit / Texture</a> is a remarkably powerful framework for performant layouts, but do you know how to write Objective C++? Can you troubleshoot it if you encounter a showstopper bug? What if an iOS upgrade breaks an integration?</p><p>You should exhaust all options within the Apple APIs before adding an external dependency.</p><ul><li>Profile early and often. The earlier you catch a performance regression, the easier the code will be to refactor.</li><li>To see performance issues, you <em>must</em> profile on an actual device, not the simulator.</li></ul><h3>Underpowered Devices</h3><p>OkCupid’s current list of underpowered devices includes the iPhone 5 family and the iPhone 6+ (3x rendering strains the CPU). You will get the most out of this tutorial if you have one of these devices handy, but you can still follow along with a newer phone. I have created a layout that will make even the best devices drop frames.</p><h3>Getting Started</h3><p><a href="https://github.com/OkCupid/iOS-Scrolling-Performance">Clone the git repo located here</a> and open the sample project. In the project’s target, set your team under the “Signing” section. You will notice when you run it that the app is already fully optimized for 60 fps scrolling. However, you can trigger the app’s performance issues by setting kIsOptimized = false on Line 9 in the AppDelegate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qTlmVYoxPPvo87vj.png" /></figure><p>Go ahead and do that and then rerun the project. Notice the difference on your phone as you scroll? The scrolling will appear choppy as it drops frames trying to render the content. Hit stop in Xcode.</p><p>Navigate to OKConversationMessageClient Line 30 and replace “emojis” with “mixedCharacters” like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IgnP_TnC03DQnHdf.png" /></figure><p>You will see much less stuttering when you rerun the app.</p><p>If you change “mixedCharacters” to “alphabet” you will see completely smooth scrolling on even the oldest devices.</p><h3>Important Lesson #1:</h3><p>Consider many different scenarios when you’re testing your app for performance.</p><p>In the sample app, short one line messages like “hey” will generate a lot more cells on screen than paragraph long messages. This means that all those cells must layout on the main thread in quick succession. Even worse than cells instantiating one after another is multiple cells coming on screen at the same time.</p><p>Beyond the quantity of cells, think about what variations of content are likely.</p><p>Let’s look at text rendering for example. Do you use complicated attributed text with link highlighting? How about supporting languages such as Arabic, Hebrew or Mandarin? Will your text contain emojis? (probably, since it’s 2017… 🙈). All of these factors impact the drawing performance of UILabel, <a href="https://github.com/TTTAttributedLabel/TTTAttributedLabel">TTTAttributedLabel</a> (which is a fantastic and performant open source framework) and UITextView.</p><p>With that in mind, let’s switch OKConversationMessageClient Line 30 back to “emojis”. But this time instead of running the app, let’s profile it and identify the non-performant code!</p><h3>Time Profiler</h3><p>Time Profiler is a very helpful instrument that samples the phone’s CPU a thousand times per second. Each sample is a recording of a backtrace, which is a summary of what the CPU was executing and how it got there.</p><p>It then symbolicates the backtrace and displays how many times each symbol (method) occurred and the “time” it spent running on the phone’s CPU.</p><p>The reason that “time” is in quotes is because the milliseconds number that is shown to you is actually calculated as:<br> (count of symbol’s occurrence in the samples) <strong>x</strong> (time between samples).</p><p><strong>So in other words… Time Profiler is NOT measuring the time a method spends running. Instead it is capturing either long running methods or fast running methods that are firing multiple times.</strong></p><p>But regardless of this limitation, the profiler provides valuable insight on which lines in your code are consuming the CPU and therefore the phone’s battery as well. I highly recommend you check out these resources below if you’re interested in going in depth on the inner workings of Apple’s Time Profiler:</p><p><a href="https://developer.apple.com/videos/play/wwdc2016/418/">Time Profiler at WWDC 16</a></p><p><a href="https://developer.apple.com/library/content/documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/Instrument-TimeProfiler.html">Time Profiler User Guide</a></p><p><a href="https://code.facebook.com/posts/456535491190613/delivering-high-scroll-performance/">Facebook built a tool</a> that can profile a device in the field and send the data to a server, but it is up to you to send and receive the data and afterwards symbolicate it. For our purposes, Apple’s Time Profiler is exactly what we want.</p><p><strong>So let’s try it out!</strong></p><p>In Xcode hold down the “Run” button and select Profile.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*y5xL7Di0vE6gycbt.png" /></figure><p>Xcode will immediately begin building and when that completes the Instruments window will open. Select “Time Profiler” and hit OK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RAO2KVCfVxJQ9wLX.png" /></figure><p>When the profiler opens, hit the red record button and the app will launch. Once launched, scroll down and watch as the Time Profiler records the data. After you have scrolled for 5–10 seconds hit the stop button.</p><p>Your profiler should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*n-0lxE_6UZdwyTWK.jpg" /></figure><p><strong>Annotations:</strong></p><ol><li>This is the graph of the CPU usage over time. You can highlight sections of the graph and the details section below will filter on just the traces that occurred over the highlighted period. You can also pinch to zoom for more granular highlighting.</li><li>These three buttons at the top toggle how you view CPU usage, which can be particularly helpful for narrowing down issues.</li><li>The detail section displays the backtraces broken out by thread. Remember, the time is calculated as the (count of samples) <strong>x</strong> (time between samples).</li><li>The call tree options provide meaningful ways of grouping and filtering the data.</li><li>The process search bar allows you to filter the trace on symbol or process names.</li><li>The heaviest stack trace shows the trace that occurred the most in the samples.</li></ol><p>Now that we have our recording, highlight the portion of the graph that occurred when you scrolled through the messages. This will filter out the heavy costs associated with launching the app, setting up the view controller and animating the cells.</p><p><strong>Take a look at the heaviest stack trace.</strong></p><p>You will see a lot of symbols that you do not recognize, but as you scroll down you will notice [UILabel drawTextInRect:] ... Bingo! As our initial swapping of &quot;alphabet&quot; and &quot;emoji&quot; conversations showed us, the UILabel drawing is extremely expensive. What you can see here is that it is accounting for 31.6% of all symbols sampled in the highlighted results. <strong>Note</strong>: Your own trace will have different % numbers due to the randomization of the string value in the message objects, and your iOS version, device model, how fast you scrolled etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G8tfoa6O4Ckbx-Wh.png" /></figure><p>For now, let’s comment out the setting of the attributed string in OKMessageCell Line 79 and rerun the time profiler to prove that we have correctly identified the issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mlsaXOLacBBFXv4b.png" /></figure><p>If we are right, [UILabel drawTextInRect:] should no longer be the heaviest stack trace in the results. It will also remove a lot of noise from the trace to see if anything else can be optimized.</p><p>Go through the same motions as before… In Xcode hit profile, select Time Profiler, hit record, when the app launches scroll through the messages for a few seconds and then hit stop.</p><p>Great news! [UILabel drawTextInRect:] is no longer the heaviest stack trace. Instead... our OKMessageCell.layoutCell() now comes up in the heaviest stack trace recording 28.6% of all symbols in the highlighted results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*X8ge9CDtrvkJ7rvU.png" /></figure><p>But that symbol is comprised of multiple components:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2vTxuWd_YXcQP_hv.png" /></figure><p><strong>Note:</strong> You may see [UILabel _intrinsicSizeWithinSize:] as the heaviest stack, but again that depends on a variety of factors. In the screenshot above, it is apparent that UIImageView is doing a lot of work. This may be due to our use of stretchable images with cap insets or even the tint we are applying for incoming or outgoing bubble color.</p><p>A super handy trick to cut through the noise is to use the “Involves Symbol” search function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DX59Q0VHK4NOXFJu.png" /></figure><p>It takes a little bit of guesswork to map the private Apple APIs to functions called in your app, but it’s not rocket science either!</p><p>If you type in “tint” you get this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FAIXh1TMrbqoFXSX.png" /></figure><p>If you type in “resizable” you get this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GtpRADUS7RXgylQS.png" /></figure><p>While not foolproof at determining if setting the tint is our culprit, the 51 ms of the trace for [UIView setTintColor] vs 1 ms trace for _setContentStetchForImage gives us the confidence to try and fix the tint first.</p><p>Reviewing the other nodes in the OKMessageCell.layoutCell() tree shows that instantiating images, sizing labels ([UILabel _intrinsicSizeWithinSize:]) and creating attributed strings ([NSConcreteAttributedString initWithString:attributes:]) all incur costs on the main thread as well.</p><p>Let’s profile the app one last time. When it launches, rotate the display. Notice the app hang for a few seconds before the rotation completes.</p><p>Stop the profiler and highlight the spike that occurred while rotating. You will see the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZASztNnHLyhQs5Ke.png" /></figure><h3>Important Lesson #2:</h3><p>UICollectionViewDelegate calls sizeForItemAtIndexPath for <strong>every</strong> cell when reloadData or a rotation occurs. It&#39;s needed to calculate the content size of the collection view. Make sure you are doing as little as you can in this function.</p><p>Also, note that sizeForItemAtIndexPath is called inside an animation block on rotation. This can lead to unintended consequences. In our case, the transform called in OKMessageCell.configureBubbleImageView(with: OKMessage) is animatable and on rotation it completely blocks the main thread.</p><p>In the screenshot above, if you double click on [UIView setTransform:] it will take you to the part of the code being sampled. Remember, all the &quot;1598x&quot; is telling us is that is the number of times that symbol showed up in the highlighted samples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ul7EtPX83fnPCrDL.png" /></figure><h3>Performance Fixes</h3><p>So now has come the time to fix our performance issues. For those of you following along in the sample project, search for instances of the kIsOptimized bool and note how it enables or disables performance improvements.</p><p>First, you can see in OKConversationAssetFactory and OKConversationSizingFactory that kIsOptimized is preventing the use of our caching layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*V1BTwQoGyx8KRgiR.png" /></figure><p>Also, note that in OKConversationAssetFactory we set both the tint color and the transform on the image itself instead of applying it on the main thread at the view level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*V7UD7_GkrXPD-zV6.png" /></figure><p>Also in OKConversationAssetFactory we create an image representation of the message&#39;s attributed string in the label size that we will feed in from the OKConversationSizingFactory</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*a52q4wicieQd8NIE.png" /></figure><h3>Important Lesson #3:</h3><p>Apple’s Safari app uses a similar text rendering technique to our caching of the attributed string as an image. When a user is scrolling, a cached lower quality image of the content is displayed on screen. This aides with scroll performance. When the user finishes scrolling, that cached image is swapped out for a higher quality, interactive view.</p><p>If you take a look at OKConversationViewController Line 287 you will see the code where we listen for a scroll to stop and swap out our image rendering with the tappable text field.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*a_ykJZI1IGU4fSKc.png" /></figure><h3>Bringing it all together</h3><p>All the caching changes are great and all… but they will be effectively useless at solving our performance issues if we don’t generate the attributed strings, images and sizes on a background thread.</p><p>For your own app, this should be done after an API call returns JSON, but before you update your collection view’s data source. See OKConversationViewController Line 163 for how the sample app performs the caching.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VkU-b6jEnLFLnwfY.png" /></figure><h3>Important Lesson #4:</h3><p>iPhone CPUs have multiple cores, but the main thread (or any thread for that matter) can only execute on one core at a time. If you instead perform multiple tasks simultaneously on background threads the work will happen twice as fast on a 2 core CPU, but the CPU % will be twice as high. This sounds bad for battery life right?</p><p>Actually not so! The ability for a CPU to finish work completely and enter a low power mode is better for the phone’s battery than executing the same operations on one core over a longer period of time.</p><h3>Let’s talk about the elephant in the room…</h3><p>I am not using Autolayout constraints in the view classes. Don’t get me wrong. Autolayout constraints are amazing in many ways. Let’s go over the pros/cons:</p><p><strong>Pros</strong></p><ul><li>Constraints can figure out highly complicated layouts where there are multiple views that influence the position of views around them.</li><li>Constraints can be constructed quickly on nibs that not only keeps your class code clean, but provides you with a visual editor to see how the layout will work. This includes size class niceties as well.</li><li>Constraints can communicate with view classes that have an intrinsic size, sparing you code for sizeThatFits: logic.</li><li>Constraints are easy to read and support by members of your team.</li></ul><p><strong>Cons</strong></p><ul><li>Constraints in nibs cannot be copied to another nib in your app.</li><li>Constraints in nibs are hard to track in Git if changes are made.</li><li>Constraints perform all intrinsic size calculations ( sizeThatFits) on the main thread each time the cell comes on screen.</li><li>Constraints require outlets, which can add a lot of code to your class, not only as outlet properties, but also anywhere you manipulate them. Take a look at OKMessageCell and you will see that the operation to switch from messageLabel to messageLabelImageView is easily done just by setting one frame to .zero and the other to the cached label frame.</li><li>Constraints if not done explicitly add CPU overhead to calculate. For example:</li><li>✅ view.trailing == constant</li><li>❌ view.trailing &lt;= otherView.leading</li></ul><p>A few notes on nibs specifically…</p><ul><li>Nibs add to the compile time of an app.</li><li>Nibs cannot be worked on by two developers at the same time without causing messy diffs in Git.</li></ul><h3>In summary</h3><p>Well I hope you learned something new from this tutorial! To summarize the main points, always remember:</p><ul><li>Test your app on older devices.</li><li>Time Profile early and often.</li><li>Only add external dependencies as a last resort.</li><li>When testing app performance, always consider many different scenarios.</li><li>Cache on a background thread to improve performance and battery life.</li><li>UICollectionView sizeThatFits is called for every cell, make sure your sizing logic is as minimal and optimized as possible.</li><li>Constraints can often be a performance bottleneck if used improperly.</li></ul><p><strong>OkCupid is hiring for iOS! </strong><a href="https://www.okcupid.com/careers"><strong>Click here to learn more</strong></a><strong>.</strong></p><p><em>Originally published at </em><a href="https://tech.okcupid.com/ios-performance-tutorial-from-okcupid"><em>https://tech.okcupid.com</em></a><em> on June 16, 2017.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4aac86866b3" width="1" height="1" alt=""><hr><p><a href="https://tech.okcupid.com/ios-scroll-performance-tutorial-e4aac86866b3">iOS Scroll Performance Tutorial</a> was originally published in <a href="https://tech.okcupid.com/">OkCupid Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a spring loaded menu using UIScrollView and View Controller Containment]]></title>
            <link>https://medium.com/@jgugges/create-a-spring-loaded-menu-using-uiscrollview-and-view-controller-containment-ad95916b8708?source=rss-c2d39b07119d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad95916b8708</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Jordan Guggenheim]]></dc:creator>
            <pubDate>Fri, 28 Aug 2015 19:48:41 GMT</pubDate>
            <atom:updated>2015-08-28T19:48:41.638Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FmMO22hZwkjc%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DmMO22hZwkjc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FmMO22hZwkjc%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d2ecf75a5c988046098372919914c8e1/href">https://medium.com/media/d2ecf75a5c988046098372919914c8e1/href</a></iframe><h3>Create a spring loaded menu using UIScrollView and View Controller Containment</h3><p><strong>Step 1: Create a new “Single View Application” project</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*t8hppqSllbTPeAngWwbW5A.png" /></figure><p><strong>Step 2: Background Image</strong><br>Drag a UIImageView onto the main view controller and assign a background image. Pin all edges to the frame.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YeOf576VhfzJSpOAHlCTWQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eClaBz6F0Bg168ME6ec8uQ.png" /><figcaption>Fish background provided by <a href="https://interfacelift.com/wallpaper/details/2919/orange_in_aqua.html">https://interfacelift.com/wallpaper/details/2919/orange_in_aqua.html</a></figcaption></figure><p><strong>Step 3: UIScrollView</strong><br>Drag a scroll view onto the view controller and also constrain all of its edges to the frame. Remember to set the background to clear.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ib7xlQH9t3qETfcBjEMpZg.png" /></figure><p><strong>Step 4: Contained View Controller</strong><br>Now drag a container view <strong>inside the scroll view </strong>and constrain all edges as well as equal width/height to its superview:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*viuPCC1Ri_76x8gnyn5b8w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*IlInSY46YSzS8TQKTZ4xng.png" /></figure><p>Our project should now look like the below. Note the View hierarchy with the container view as a subview of the scroll view:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l2SxcaRktRkhK6g3HGNiZw.png" /></figure><p>On the new contained view controller, add a Visual Effect View with blur as a background view and add auto-layout constraints to all edges of the superview. Run your project and play around by dragging up and down on your detailed VC. Notice that you get the spring loaded response for free with UIScrollView:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FZ1Zcau_vSkQ%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZ1Zcau_vSkQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FZ1Zcau_vSkQ%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/caba9e6f2f0249c52147c655b30d946d/href">https://medium.com/media/caba9e6f2f0249c52147c655b30d946d/href</a></iframe><p><strong>Step 5: Scroll View Setup Method</strong><br>On the main view controller, Ctrl+drag to create an outlet for the scrollview. Now you can add a setupScrollView method where you will setup some basic properties for the scroll view and also assign the view controller as the scroll view delegate. This will be necessary for the method that we will implement next. All code is included in the git page link at the bottom.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7LFbQDeeqgavXamXJYvC5Q.png" /></figure><pre><strong>Explanation of scroll view properties</strong></pre><pre><strong>// In the next section we will implement a delegate method to show and hide the contained view controller in the scrollview.</strong><br>self.scrollView.delegate = self;</pre><pre><strong>// We disable paging to allow the scrollview to move freely and not &quot;stick&quot; to the next page.<br></strong>self.scrollView.pagingEnabled = NO;</pre><pre><strong>// We hide the vertical scroll indicator because we do not want our end user to realize we are using a scroll view.</strong><br>self.scrollView.showsVerticalScrollIndicator = NO;</pre><pre><strong>// This property allows the scroll view to &quot;spring&quot; up and down when we reach the end of the content.</strong><br>self.scrollView.alwaysBounceVertical = YES;</pre><pre><strong>// This prevents the scroll view from moving horizontally</strong><br>self.scrollView.alwaysBounceHorizontal = NO;</pre><pre><strong>// This creates a buffer area on top of the scroll view&#39;s contents (our contained view controller) and expands the content area without changing the size of the subview  </strong><br>self.scrollView.contentInset = UIEdgeInsetsMake(500,0,0,0);</pre><p>If you run the project now, notice the contentInset property moved our contained view controller down the page and allows us to move it around with a touch gesture:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FBfCMCKXfco4%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DBfCMCKXfco4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FBfCMCKXfco4%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f0c48b09673906b390f6d13ceb87b1c/href">https://medium.com/media/1f0c48b09673906b390f6d13ceb87b1c/href</a></iframe><p><strong>Step 6: Scroll View Delegate Method Animations</strong><br>Since we assigned our main view controller as the delegate of the scroll view we can access a super cool method named scrollViewWillEndDragging. This method gives us velocity and target content offset which we can manipulate to say “ok, if the view finishes dragging somewhere in between point A and B move it to point A or B depending on which direction it was headed”.</p><p><strong>A few notes:</strong><br>Velocity is either positive (moving up toward the top of the scroll view) or negative. BUT, it can also be zero if the user isn’t moving the scroll view anymore when they let go of their finger.</p><p>The dispatch_after logic is necessary otherwise the animations will move at the pace of the velocity calculated by the scroll view. Instead, we want to control the speed of the animation. This does not have to be used outside of the delegate method.</p><p>We use content inset in the setup, but content offset in the manipulation due to this important distinction: Content inset creates a buffer area on top of the scroll view’s contents (our contained view controller) and expands the content area without changing the size of the subview. Whereas, content offset defines the upper left corner of the scroll view’s bounds. In other words, it defines the point in the content that is visible at the top left of the scroll view.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mk1NOOHweFqsxu-djZkWmw.png" /></figure><p>Here is how it looks now. Although touches any where on the screen will move our contained view controller. In the next section, we will address that issue.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F0W9q0yCs57k%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D0W9q0yCs57k&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F0W9q0yCs57k%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5807e4a64a8130aaba7362f6d1e7a76/href">https://medium.com/media/b5807e4a64a8130aaba7362f6d1e7a76/href</a></iframe><p><strong>Step 7: Subclass UIScrollView Point Inside</strong><br>Right now, you will notice that no matter where you touch on the screen, the contained view controller will move. This is because we set our scroll view to take up the entire size of our main view controller, so any touch on the screen is registered by the scroll view. To enable functionality that only moves our contained view controller when the touch is inside the container, we need to subclass UIScrollView. Start by create an iOS class for UIScrollView and title it ScrollViewPassThrough. Next in the .m file, override the method for point inside. The logic below iterates through all of the scroll views subviews (aka our container view) and then converts the point from a scroll view coordinate to a coordinate within the sub view’s plane. Only if the point is inside that plane will it return YES and prevent the scroll view from moving otherwise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jy6VPn_Pu1aEjfxUV8EoXA.png" /></figure><p>That’s it for the basics! You can also add a UITouchGestureRecognizer to pop the container up and down when tapped. To see all the code for this tutorial, please checkout the github project here:</p><h3><a href="https://github.com/gugges/UIScrollView-Container-With-Animation-Tutorial">https://github.com/gugges/UIScrollView-Container-With-Animation-Tutorial</a></h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad95916b8708" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Draw a randomized star field in Objective-C]]></title>
            <link>https://medium.com/@jgugges/draw-a-randomized-star-field-in-objective-c-cdce097f175b?source=rss-c2d39b07119d------2</link>
            <guid isPermaLink="false">https://medium.com/p/cdce097f175b</guid>
            <dc:creator><![CDATA[Jordan Guggenheim]]></dc:creator>
            <pubDate>Fri, 28 Aug 2015 15:36:13 GMT</pubDate>
            <atom:updated>2015-08-28T20:44:46.612Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*zS9l0VRIxzCYGYwgkL2BQw.png" /></figure><p>The below tutorial will show you how to create a star field, but in the abstract the code can be used in any situation where you need to create repeating images. Whether that’s blades of grass, clouds or simply background textures for your app.</p><p>Note: This guide uses Xcode, Paintcode and Photoshop</p><h3>Gradient Background</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/223/1*UuKtN1tEW1yUKlm8apSW_Q.png" /></figure><p>A night sky must begin with the background. For this tutorial, I generated a gradient that most accurately represented to me a natural dusk scene. You can find the link to the Github project containing the gradient code along with the rest of the project code at the bottom of the blog.</p><h3>Drawing the stars</h3><p>To build a diverse star field you must first design your template stars. For my star field, I decided on four different types of stars. Two large size five-pointed stars, one medium size six pointed star and one baby 9 pointed star. To create the stars in Paintcode is as simple as creating a new canvas, laying down a frame and then using the star tool to draw the stars to your spec. You can specify the number of points, the angle between points and of course the size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7DgNr_nO6m4BSAINPys4mw.png" /></figure><h3>Randomizing the star field</h3><p>This is by far the trickiest and in my opinion most exciting part of the tutorial. To randomize the star field, first begin by making a new class that is a subclass of UIView. Import the header file from your template class that you imported from Paintcode.</p><p><strong>Here is the plan:</strong></p><ol><li>In the <strong>-(void) drawRect:(CGRect)rect</strong> method we are going to call methods that draw two sets of stars. The big stars and medium stars will be few and far between. The baby stars will populate the background and cover most of the sky.</li><li>In the <strong>-(void) drawBigStars</strong> method we will need to randomize both the location (X,Y) and rotation (°) of our stars as we draw them. Also, it will look awkward if two stars overlap so we must write logic to prevent overlapping stars.</li><li>In the <strong>-(void) drawLittleStars</strong> method we also need to randomize location (X,Y) and rotation(°) but since the stars are so tiny, we do not need to worry about whether or not they overlap.</li><li>Both methods will draw the stars from the top of the screen down. The lower they go the more they will fade out into the “horizon”.</li><li>After we perfect the star patterns, we will add a Milky Way overlay and a moon.</li></ol><p><strong>Setup</strong></p><p>Start by creating a private property for our NSMutableArray that will hold all the star frames. This is what we will use to check for intersecting stars. In the <strong>-(void)drawRect:(CGRect)rect </strong>method, instantiate the array and add the methods for <strong>-(void)drawBigStars</strong> and <strong>-(void)drawLittleStars:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/1*0nw7tHfibHBYJ90KJ-cs2A.png" /></figure><p><strong>Big Stars</strong></p><p>To create rows of stars we will use a for loop and keep track of the current’s star coordinate to determine if the position is off the screen. If the coordinates are off screen we must start a new row. Also, remember we need to randomize the rotation and to some extent randomize which stars we draw. We can use the variable rowCount for precision when determining what to do on the current row. Finally, we want the star’s color to fade out, so we need to adjust alpha. To keep track of all of this in our For loop, define the following method variables:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*Bx10QphemQY1cdSYS9dFog.png" /></figure><p>In the for loop, the i will represent the number of attempts to draw stars (an attempt will fail if there is an overlap). Start by creating a CGRect for the first star drawn. Also assign the star color with alpha component, rotation and the farthest right X value, which will allow us to determine if the star rect will be off screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*3b54VVBR4WdOHC-r0gxWsA.png" /></figure><p>Next we need logic to determine if the star X coordinate is off screen and if so move it to the start of the next row. If the Y coordinate is off screen, we will start back at the top of the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*oDxnk8hD46jILQdUlBjyaw.png" /></figure><p>Note that every other row we reduce alpha by 5%. This will give us the fade out we are looking for without it being too sudden. Also, we can use <strong>arc4random_uniform </strong>+ <strong>a static number</strong> to randomize our new Y coordinate, while still ensuring that it moves a minimum distance.</p><p>If the coordinates are not off the screen, we still want to further randomize the X and Y values to give the stars a more staggered appearance, as opposed to having a bunch of stars in a straight row. After we set the frame, we advance the X coordinate for the next star in the row.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*41-6Zkk1QPX1MaIAdB7Uvg.png" /></figure><p>In the bottom half of the screenshot, we begin by validating if the current starFrame intersects a CGRect from our NSMutable array. The method that runs the check is below. If it passes that check, the following if statements above are tailored to only drawBiggerStars in the first row, but only if the i value is divisible by 2. This further spreads out the stars by not drawing them every time we advance the X axis position. This section is a lot of tweaking and running your app to finesse how the randomized star pattern gets generated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/345/1*CFzTh0Q0jPCDCOgXP-Qnaw.png" /></figure><p>Ok, so let’s assign this custom UIView class to a UIView on our storyboard and run the app. I pinned leading, top and trailing to the superview and set height to 300 points. Our star field now should look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*WIRyUBtNiAZ0lW-fpM5H8g.png" /></figure><p><strong>Little Stars</strong></p><p>The little stars are built in exactly the same fashion, but the X and Y increments are adjusted to place the stars much closer together and also to have them fade more subtlety, since we are drawing many more of them and wouldn’t want to reduce the alpha as often. All code is attached at the bottom, but once we add the little stars, the sky will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*-YWmNK1Do8IpGba2EJ4q1g.png" /></figure><h3>Designing the Milky Way</h3><p>The above sky is a great start, but there are subtle finishes we can add to give it a more realistic feel. To add a milky way, start by finding an <strong>awesome</strong> picture of the night sky on the web. I highly recommend <a href="http://interfacelift.com/">Interfacelift.com</a>. I ended up picking this one from photographer Jonathan Besler:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*htjh7NAWJweu00lU9W6_Fw.jpeg" /></figure><p>Next, in Adobe Photoshop I lasso the Milky Way section like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2W5E151movEUUZ4SxjChbA.png" /></figure><p>I then “Copy as Layer” and hide the rest so I can start manipulating the image. I also rotate the image to be more horizontal, which will better fit the star field we created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r74fz2c-SyOZq4jPxj6kgw.png" /></figure><p>Note: Before editing the image, duplicate the layer so you have a backup in case you screw it up.</p><p>The next step is to use the magic wand tool to select the area around the image. Use a feather of ~30 and hit delete once to fade the edges of our object.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WC51R6XnP1eUKo5eJlyXEA.png" /></figure><p>After, select an eraser with 0% Hardness and 10% opacity to start making the layer transparent. Start with the darker parts of the image and squiggle the mouse in small circles to make the transparency imperfect and give the image depth. I avoided erasing the whitest spot in the bottom right. Here is what I went with at first:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t6aE-9P7WM5e1MR894ObJQ.png" /></figure><p>I then stretch the image to fit the canvas, played with the rotation and further erased parts of the image and lowered the opacity of the entire layer to 90%:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GfBjhu0i3qT01sRQUYwmkg.png" /></figure><p>Next save the image for web as a PNG and import it to your XCode project. Add a UIImageView on top of your star field UIView and set the alpha to 0.35.</p><p>Run your project and it will now look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*9xXOlnfQnYhhw74jyyU3ig.png" /></figure><p>That’s it for this demo! Feel free to take a look at the same code.</p><h3><a href="https://github.com/gugges/Night-Sky-Tutorial/">https://github.com/gugges/Night-Sky-Tutorial/</a></h3><p>Also, here is a screenshot for a weather app that I am building that incorporates the work done in this tutorial.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*-U2hZ7uxyjoQDt-gm257nw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cdce097f175b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Beginners Guide to LLDB in Xcode]]></title>
            <link>https://medium.com/@jgugges/a-beginners-guide-to-lldb-in-xcode-1f16b5eeead1?source=rss-c2d39b07119d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f16b5eeead1</guid>
            <dc:creator><![CDATA[Jordan Guggenheim]]></dc:creator>
            <pubDate>Tue, 14 Jul 2015 18:18:09 GMT</pubDate>
            <atom:updated>2015-08-29T16:43:36.119Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*WHqD-w56t-tEaCQiB6ABzg.gif" /></figure><p>Learn how to debug your Xcode projects<br>Explore advanced LLDB Breakpoints<br>Keep your code free of NSLogs</p><p>Often times, programmers will add NSLogging to their projects to capture the current outputs of variables or formulas used throughout their app.</p><pre>NSLog(@&quot;%@&quot;,self.titleString);</pre><pre>NSLog(@&quot;%f&quot;,(self.weatherSlider.value-self.weatherHourOffset)/24);</pre><p><strong>Pretty soon your code and the subsequent LLDB output are a mess, </strong>littered<strong> </strong>with NSLog statements buried across multiple classes. <strong>Fear not,</strong> Xcode gives us powerful tools for monitoring and debugging our projects without crappin’ up our code or the console output.</p><h3>Breakpoints</h3><p>Breakpoints are created by single left-clicking on the row count in the left margin of your Xcode window. They appear as blue flags and will pause your application at that exact line in the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*C_hIeyVlCR5S503OT2gpZg.png" /><figcaption>Breakpoint on row 181</figcaption></figure><p>When you run your application in the iOS Simulator or through your phone, the breakpoint with only trigger and pause your application if the code at the breakpoint is executed. In the above example, if the self.hourSlider.value is less than 2400, the breakpoint will not trigger.</p><h4>Basic Commands</h4><p>When your breakpoint does trigger, Xcode comes into focus with the breakpoint highlighted in green. You can then enter commands into the debug console in the bottom right of the screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x5Sj0pB8QHW4kmWBida5Yw.png" /></figure><p>Here is a quick guide of basic commands:</p><pre><strong>p</strong> = print  // This will take the arguments given and print the output using the compiler language and store it in its own variable for use in the debugger (designated by a $n)                                </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/1*e6e0xx4IarMcMJWhLyOwFQ.png" /><figcaption>The output from row #2 is stored in variable $1. The variable is then used on row #3 to represent 8 + 3</figcaption></figure><p>You can even use the p command to reassign variables and properties in your project! Just use the = operator. You can then see the updated value immediately, <strong>but the app will only update when you hit the play button |&gt; in the debug console.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*XqoUB2kxo3epbxHnU8wodA.png" /></figure><pre><strong>po</strong> = print object  // This will print the object&#39;s description method. It does not store a variable. </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*cZ5bwfNzbujegTTULZ299w.png" /><figcaption>Note that po shows all the properties and memory address of the object. p simply shows the memory address and stores the variable</figcaption></figure><p><strong>Note: The lldb debugger obeys scope, so you will only have access to local variables in the method or class properties. You do have the ability to call other methods in the class like the below.</strong></p><pre>p [self updateGradient]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*zXC2hPiP0WY6AIEZ1mOPnA.gif" /></figure><h3>Breakpoints Advanced</h3><p>Now that we have the basics down, let’s look at the really useful advanced features of breakpoints.</p><h4>Exception Breakpoint</h4><p>The most useful of which in my opinion is the “Exception Breakpoint”. Navigate to the breakpoint section on the left hand side and click the + button on the bottom and select</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/328/1*nQaOV-oLumXTL4iufVlkLg.png" /></figure><p>This breakpoint once added will insert a breakpoint extremely close to the location in code that causes an exception such as “Index out of bounds”. See the before and after screenshots below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*d3oBfsmyRPA5DBRCk_r0eQ.png" /><figcaption>No exception breakpoint</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*t9x3dxttdJDpfkLKGTRaJw.png" /><figcaption>Exception breakpoint</figcaption></figure><h4>Breakpoint Conditions</h4><p>Start by right-clicking and editing any breakpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*71ENRJZTY7WFZJsniqfOhQ.png" /></figure><p>In the prompt that opens you can enter conditions for variables in the scope of the breakpoint. For example, you could design a breakpoint to only fire in a For loop when i == 16.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*r1Xz2kQie0-jWKrcJZKkMA.png" /></figure><h4>Breakpoint Actions</h4><p>If you select the Add Action button there are a wide variety of additional configurations. In the example below, I add an NSLog for the current military time when i == 16 in my for loop. I then hit the + sign and also added a sound to play when that is hit so I can keep my eyes on the app instead of the debug console. Finally, I check the box at the bottom for “Automatically continue after evaluating actions”. This will prevent the breakpoint from pausing the application, but still log the messages configured for that breakpoint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*xCt654UaCpKdzLKV57dbow.png" /></figure><h4>Breakpoint Collaboration</h4><p>Now that you can make super awesome breakpoints, you want the ability to share these breakpoints with your project team members. Yet, when you Git Add/Commit/Push, your teammates don’t see your breakpoints. Say what?!?</p><p>To share your breakpoints with teammates, simply right-click on the breakpoint and hit share.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*WO1LYwCqJfSh47bXVYsGeA.png" /></figure><p>Shared breakpoints will be displayed as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*4VPp5fZSxPzIiVGUFex-Jg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f16b5eeead1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[VIMprove your life]]></title>
            <link>https://medium.com/@jgugges/vimprove-your-life-a9e1c747413b?source=rss-c2d39b07119d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9e1c747413b</guid>
            <dc:creator><![CDATA[Jordan Guggenheim]]></dc:creator>
            <pubDate>Tue, 16 Jun 2015 03:41:54 GMT</pubDate>
            <atom:updated>2015-06-16T13:07:11.171Z</atom:updated>
            <content:encoded><![CDATA[<h3>A beginners guide to VIM and its integration with Xcode</h3><h4>Be faster</h4><p>Being abstract is something profoundly different from being vague… The purpose of abstraction is not to be vague, but to create a new semantic level in which one can be absolutely precise. — Edsger Dijkstra</p><p>Abstraction is different than vagueness and to code fast is different than to code hastily. The below tutorial will show you the basics of VIM and how to integrate it with Apple XCode. It will also give you the edge to become a faster programmer without sacrificing your accuracy.</p><h4>History</h4><p>In 1976, Bill Joy wrote Vi in C for Unix. The program served as a visual mode for the line editor ex and naturally Vi is short for visual. Before visual text editors, users could not scroll or move the cursor when editing text. Instead they had to rely on commands to <strong>%l</strong> (list all text) or <strong>a</strong> (append text). Here is an example with the outputs from ed in <strong>bold</strong>.</p><pre>a<br>ed is the standard Unix text editor.<br>This is line number two.<br>.<br>2i<br>  <br>.<br>%l<br><strong>ed is the standard Unix text editor$.</strong><br><strong>$</strong><br><strong>This is line number two$.</strong><br>3s/two/three/<br>%l<br><strong>ed is the standard Unix text editor$.</strong><br><strong>$</strong><br><strong>This is line number three$.</strong><br>w text<br><strong>65</strong><br>q</pre><p>The user first hits <strong>a</strong> to append text.<br>Then the user entered two lines of text.<br>The <strong>.</strong> terminates the text entry.<br>The <strong>2i</strong> command inserts the following blank line in row 2 terminated by the second <strong>.</strong></p><p>The user then enters <strong>%l</strong> to have ed list all the text currently in the file. The <strong>$ </strong>represent line breaks or the end of a row to easily highlight extra spaces.<br>Oh no! A mistake! “This is line number two” is on line three.<br>The user then enters <strong>3s/two/three </strong>where 3 is the line, s means substitute string two for string three.<br>Ah, that’s better.<br>The user then uses <strong>w</strong> to write the text. Ed returns <strong>65</strong> which is the number of characters written.<br>The user then quits the application with <strong>q.</strong></p><h4>Using VIM</h4><p>VIM “Vi Improved” is a natural evolution of the original Vi and adds many features including new editing commands and syntax highlighting (different colors for different code types).</p><pre><strong>VIM reduced down to its most basic form has three modes</strong></pre><pre><strong>Insert mode </strong>— Entering text. (press <strong>i)</strong><br><strong>Command mode</strong> — Moving around/executing commands. (press <strong>Esc</strong>)<br><strong>Last-line mode</strong> — How to save and/or quit VIM. (press <strong>:</strong> in command mode)</pre><p>In terminal, type VIM <em>filename</em> to open a file in the VIM editor. By default, the editor will open in command mode.</p><pre><strong>Here are the basic move commands</strong></pre><pre><strong>h</strong> moves the cursor one character to the left.<br><strong>j</strong> moves the cursor down one line.<br><strong>k</strong> moves the cursor up one line.<br><strong>l</strong> moves the cursor one character to the right.<br><strong>0</strong> moves the cursor to the beginning of the line.<br><strong>$</strong> moves the cursor to the end of the line.<br><strong>w</strong> move forward one word.<br><strong>b</strong> move backward one word.<br><strong>G</strong> move to the end of the file.<br><strong>gg</strong> move to the beginning of the file.<br><strong>`.</strong> move to the last edit.</pre><pre><strong>v</strong> will enter select mode, where you can highlight text from the cursor using the arrow keys or commands listed above.<br><strong>V</strong> will highlight the line on the cursor.</pre><pre><strong>Pro tip: </strong>You can put a number before any command to repeat the command. To move 6 words forward type <strong>6w</strong></pre><p>Pretty neat, right?</p><pre><strong>Here are the basic edit commands. Note that the commands are run from the point of the cursor.</strong></pre><pre><strong>x </strong>will delete the character.<strong><br>dw</strong> will delete a word.<br><strong>d0</strong> will delete to the beginning of a line.<br><strong>d$</strong> will delete to the end of a line.<br><strong>dgg</strong> will delete to the beginning of the file.<br><strong>dG</strong> will delete to the end of the file.<br><strong>u</strong> will undo the last operation.<br><strong>Ctrl-r</strong> will redo the last undo.</pre><pre><strong>Pro tip:</strong> Again you can combine various commands. Notice that <strong>gg</strong> is the command to move to the top of the file, so <strong>dgg</strong> delete from the cursor to the top of the file</pre><pre><strong>Pro tip: </strong>The last thing you delete is stored in memory and can be pasted with <strong>p</strong></pre><p>VIM also makes it easy to search and replace text!</p><pre><strong>Here are the basic search/replace commands. </strong></pre><pre><strong>/<em>text</em></strong> will search forward for the word entered to the right of the <strong>/</strong><em>.<br></em>?<strong><em>text </em></strong>will search backward for the word entered to the right of the <strong>?</strong><em>.</em> </pre><pre><strong>Example:<br>/puppy</strong> will search for the next word matching puppy when the user hits enter.</pre><pre><strong>n </strong>will move the cursor to the next instance of the word from your last search.<br><strong>N </strong>will move the cursor to the previous instance of the word from from your last search.</pre><pre><strong>:%s/<em>text</em>/<em>replacement text</em>/g</strong> search through the entire document for <em>text</em> and replace it with <em>replacement text</em>.</pre><pre><strong>:%s/<em>text</em>/<em>replacement text</em>/gc</strong> search through the entire document and <em>confirm</em> before replacing text.</pre><h4>Integrating VIM in Xcode</h4><p>First, if you haven’t already, install the Alcatraz package manager for Xcode. It is a fantastic utility to install plugins to make your life easier in Xcode.</p><p>Here is the quick and easy terminal command to install Alcatraz:</p><pre>curl -fsSL <a href="https://raw.githubusercontent.com/supermarin/Alcatraz/master/Scripts/install.sh">https://raw.githubusercontent.com/supermarin/Alcatraz/master/Scripts/install.sh</a> | sh</pre><p><a href="http://alcatraz.io/">Alcatraz | The Package manager for Xcode</a></p><p>Once installed, quit and reopen Xcode. You will receive the below prompt. Hit Load Bundle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*OsLT46kbgdgTZpFTwWxMVw.png" /></figure><p>Select Window&gt;Package Manager</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/462/1*pOaxLfO29o4Nz2vuwUcvug.png" /></figure><p>Once in Package Manager install XVim and restart Xcode again. Xcode will then automatically default to VIM mode. You will notice a single row has been added above the debug console, which is where the cursor goes when the user exits insert mode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*9P7jh04i-xLfOFePScbPkw.png" /></figure><p>Additional information on VIM can be found on their GitHub page:</p><p><a href="https://github.com/XVimProject/XVim/blob/master/Documents/Users/FeatureList.md">XVimProject/XVim</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9e1c747413b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>