<?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 Eliot Han on Medium]]></title>
        <description><![CDATA[Stories by Eliot Han on Medium]]></description>
        <link>https://medium.com/@eliothan?source=rss-c5f190299597------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ZXf6TQBs-gn4TVOl.</url>
            <title>Stories by Eliot Han on Medium</title>
            <link>https://medium.com/@eliothan?source=rss-c5f190299597------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 14:18:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@eliothan/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[An Uncomfortable Essay on “Comfort Women” written on 7/19/2015]]></title>
            <link>https://medium.com/@eliothan/an-uncomfortable-essay-on-comfort-women-written-on-7-19-2015-990fefe7012d?source=rss-c5f190299597------2</link>
            <guid isPermaLink="false">https://medium.com/p/990fefe7012d</guid>
            <category><![CDATA[comfort-women]]></category>
            <category><![CDATA[korea]]></category>
            <category><![CDATA[foreign-policy]]></category>
            <category><![CDATA[social-issues]]></category>
            <category><![CDATA[japan]]></category>
            <dc:creator><![CDATA[Eliot Han]]></dc:creator>
            <pubDate>Sat, 06 Oct 2018 23:50:29 GMT</pubDate>
            <atom:updated>2020-01-31T23:49:29.089Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*z92wWr_Ie8JJoRmiAM9xdw.jpeg" /><figcaption>Former World War II “comfort woman” Yongsoo Lee, 89, of South Korea, stands by a statue of Haksoon Kim while looking at the “Comfort Women” monument after it was unveiled, Sept. 22, 2017, in San Francisco.</figcaption></figure><p>While going through my google drive, I dug up an old essay I wrote more than 3 years ago in high school. I read it again and wanted to share it as it still feels relevant. My writing is not that impressive (I spelled Hillary Clinton wrong) and to be honest, it hasn’t really improved since coming to college.</p><p>Here are some very recent and relevant articles:</p><ul><li><a href="https://www.history.com/news/comfort-women-japan-military-brothels-korea">The Brutal History of Japan&#39;s &#39;Comfort Women&#39;</a></li><li><a href="https://www.nytimes.com/2018/10/04/us/osaka-sf-comfort-women-statue.html">&#39;It Is Not Coming Down&#39;: San Francisco Defends &#39;Comfort Women&#39; Statue as Japan Protests</a></li></ul><p>Things that happened after 7/19/2015 not mentioned in the essay:</p><p><a href="https://www.nytimes.com/2015/12/29/world/asia/comfort-women-south-korea-japan.html">Japan and South Korea Settle Dispute Over Wartime &#39;Comfort Women&#39;</a></p><p><a href="https://www.usatoday.com/story/news/world/2017/12/28/south-korea-2015-comfort-women-reparations-deal-japan-flawed/986652001/">https://www.usatoday.com/story/news/world/2017/12/28/south-korea-2015-comfort-women-reparations-deal-japan-flawed/986652001/</a></p><p><a href="https://thediplomat.com/2018/01/the-japan-south-korea-comfort-women-agreement-survives-barely/">The Japan-South Korea &#39;Comfort Women&#39; Agreement Survives (Barely)</a></p><p>The essay:</p><p>At the age of 15, Lee Ok Seon was raped daily by more than 50 men. Kidnapped by the Japanese Army from her country of origin, Korea, Lee was thrown into a Japanese “comfort station” located in China. Her job, along with dozens of other young girls, was to “revitalize” the Japanese soldiers who would line up outside the small shack, waiting for their turns. Kim Bok Dong, another girl forced into the same sexual slavery as Lee, estimated that each soldier took around three minutes. Kim shudders as she recounts the dehumanizing and exhausting ordeal. “When it was over, I couldn’t even get up. It went on for such a long time. By the time the sun went down, I couldn’t use my lower body at all. After the first year, we were just like machines.”</p><p>Lee and Kim were both “comfort women”, women and girls forced into slavery by the Imperial Japanese Army in occupied territories during World War II. Mostly from Korea, approximately 200,000 young women — many of whom were prepubescent — were forced into servitude and exploited as sex slaves throughout Asia. Three quarters of the women did not survive the ordeal. The comfort women trade has been the largest known government sponsored human trafficking system in all of human history. However, this gross violation of human rights is mostly unknown to the West and has been left out of many textbooks, leaving the victims of the system as abstract entities, forgotten by the world. The cultures of the nations in which the majority of these women originated from have also made it socially unacceptable to discuss their past miseries, shaming many of the victims into silence and desolation.</p><p>Today, Lee and Kim are two of the few dozen surviving “comfort women”. Both close to 90 years old, their bodies are covered with scars and neither can see or hear properly due to repeated beatings. Repeated injections of the Syphilis treatment compound 606 as a result of sexually transmitted diseases have left both of them unable to have any biological children. However, despite their frail bodies, their resolve and determination have never been stronger. Together with ten other surviving comfort women who are seeking two million dollars each in a Californian court, Lee and Kim demand an official apology and compensation directly from the Japanese government. “Money is absolutely not the point,” Kim insists. “The point is that Japan admits to its war crimes and offers a sincere apology.” Yet, prominent figures of the conservative Japanese administration headed by Prime Minister Shinzo Abe have claimed that Japan had no involvement in kidnapping women and forcing them into sexual slavery; furthermore, Japanese authorities have denied the very existence of the comfort women system despite the living proof: the surviving victims.</p><p>In 1993, Yohei Kono, the Japanese chief cabinet secretary, had actually offered the comfort women an apology. However, in recent years, the Japanese government has retracted the statement and denied the existence of the comfort women system: lawmakers assert that the women were not slaves and were merely voluntary prostitutes, working to make money. Despite concurring testimonies from over sixty kidnapped victims who courageously shared their stories, many members of the Japanese government still deny that the system was state sponsored. And for those that acknowledge the system, like Toru Hashimoto, governor of Osaka, sex slavery was merely a “necessary component” of the war to keep discipline among the troops. Lee Ok Seon thinks this is mindless and terrible: “I cannot grasp how anyone can say such a thing. Whoever refuses to accept what the Japanese did back then is not a human being.” Japanese authorities also contend that the issue was settled after the government delivered an aid package worth $800 million to South Korea in 1965. However, what Kim Bok Dong seeks is not money or aid: “I can’t die without receiving an apology from the Japanese government.”</p><p>Former enemies can become strong allies as evidenced by the United States and Japan. Why has this not yet occurred between South Korea and Japan? Today, 70 years after Korea’s Independence from Japanese rule, South Korean and Japanese relations are still strained due to the Japanese government’s refusal to acknowledge the comfort women. As South Korea faces the last vestiges of Japanese militarism, the two nations continue to clash in long standing territorial disputes and engage in political battles. Unlike Germany, a post war nation that placed emphasis on not only preserving the crimes of its history, but also fully compensating its victims, Japan has simply turned a blind eye. The Japanese government should sincerely apologize and acknowledge the surviving comfort women not only because it is a moral obligation, but also for its own benefit: to build a cohesive relationship between the two most powerful democratic nations in the Asian Pacific region.</p><p>As South Korea continually repeats its demands that Japan acknowledges the former sex slaves and compensates them, Japan looks further away, worsening the already tenuous relationship between the two nations. Thus, Japan and South Korea have been locked in political warfare: when South Korea’s former president, Lee Myung Bak, made a politically charged trip to Dokdo, a cluster of remote, rocky islands also claimed by Japan, President Lee suggested that his visit was linked to Japan’s failure to offer an official apology. Japan retaliated by deciding not to renew a $57 billion dollar currency swap with South Korea, a policy designed to protect both Asian countries from a potential financial crisis. Another critical issue and source of conflict between the two nations is Japan’s textbook distortion and omission policy. According to media reports, Manabisha, a Japanese textbook publisher, was forced to omit content on the comfort women and sexual slavery from its history books. While the original drafts of the books included a map with dots where the comfort stations were located, a picture of a woman with her arm being dragged by a Japanese soldier, and a firsthand account of the abuses suffered by a victim, the Japanese government completely removed this content. The final versions of the books, which are intended to educate Japanese school children, also include erroneous claims that, “the recruitment of comfort women was done on a voluntary basis and that no evidence was found to support the argument that these women were coerced to offer sex by the Japanese military.” Just days after the controversy, South Korea made the stories of the comfort women essential parts of its historical curriculum. Kim Jae Ryeon, a South Korean official, said that these new teaching materials detailing the lives of comfort women have been distributed to all elementary, middle, and high schools in the hope that students rightfully understand the sex slavery and wartime brutalities committed by Japan with an unbiased historical view.</p><p>It is imperative that the history of the comfort women system and the atrocities committed by the Japanese soldiers be remembered. If the crimes of past humanity are forgotten, these human rights violations and mistakes could reoccur in the future. Germany, one of the key nations involved in the start of World War II, realized its own mistakes and has sworn to preserve the memories of Nazi crimes. German Chancellor, Angela Merkel, publicly stated that Germans have an “everlasting responsibility” to acknowledge its own history and the German government has taken steps to compensate the surviving victims and apologize to the international community. Thus, Germany, unlike Japan, has emerged as a key country in its region and has retained its say in international issues of the 21st century. On the other hand, Japan tries to conceal its dark past and the country’s actions only cause conflicts and divisions within the East Asia. As August 15, 2015 marks the 70th anniversary of the end of World War II, it is finally time for Prime Minister Abe and the Japanese government to acknowledge its own past. For as long as the stories of these women go unnoticed, Japan cannot be viewed as a responsible member of the international community. As the date rapidly approaches, all the pressure is now on Japan. The world, including the United Nations, key political figures like Hilary Clinton, and groups of renowned historians, is watching and challenging the Japanese government to address its own history correctly.</p><p>Time is running out for the surviving comfort women as well. The 50 or so surviving comfort women all approach 90 years old and are being plagued with numerous health issues. All they hope for is a resolution before they pass away.</p><p><strong>Bibliography</strong></p><p>“‘I Can’t Die without Getting Apology’” <em>Koreatimes</em>. Web. 18 July 2015.</p><p>“A Korean “comfort Woman” Still Seeks Redress from Japan — CNN.com.” <em>CNN</em>. Cable News Network. Web. 18 July 2015.</p><p>Brooks, Katherine. “The History Of ‘Comfort Women’: A WWII Tragedy We Can’t Forget.” <em>The Huffington Post</em>. TheHuffingtonPost.com. Web. 18 July 2015.</p><p>“Comfort Women: South Korea’s Survivors of Japanese Brothels — BBC News.” <em>BBC News</em>. Web. 18 July 2015.</p><p>“Facing up to Historical Facts.” <em>Koreatimes</em>. Web. 18 July 2015.</p><p>“Former Comfort Woman Tells Uncomforting Story | Asia | DW.COM | 02.09.2013.” <em>DW.COM</em>. Web. 18 July 2015.</p><p>John Power And Kim Hae-yoon In Gwangju For Mailonline. “‘I Had to Receive 50 Japanese Soldiers a Day. They Kicked and Beat Me… and My Children Are Still Ashamed of Me’: WWII ‘comfort Woman’ Sex Slave Tells of the Barbarity She Suffered and Why She Is Suing Japan for £16million.” <em>Mail Online</em>. Associated Newspapers, 30 June 2015. Web. 18 July 2015.</p><p>McCurry, Justin. “Anger of Wartime Sex Slaves Haunts Japan and South Korea.” The Guardian. Web. 18 July 2015.</p><p>“Remembering the Horrors of War.” <em>Koreatimes</em>. Web. 18 July 2015.</p><p>“Schools to Get Teaching Materials on ‘comfort Women’” <em>Koreatimes</em>. Web. 18 July 2015.</p><p>“South Korean ‘Comfort Women’ Threaten to Sue Japan for $20 Million in the US | VICE News.” <em>VICE News RSS</em>. Web. 18 July 2015.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=990fefe7012d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Intro to MVC Architecture for Swift 3]]></title>
            <link>https://medium.com/@eliothan/mvc-architecture-for-swift-3-7206b7dc985a?source=rss-c5f190299597------2</link>
            <guid isPermaLink="false">https://medium.com/p/7206b7dc985a</guid>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Eliot Han]]></dc:creator>
            <pubDate>Sat, 21 Jan 2017 04:07:14 GMT</pubDate>
            <atom:updated>2017-05-22T20:16:04.956Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*XckspFY1Sv-3oeILmToyqA.jpeg" /></figure><p>The MVC — Model View Controller Architecture Design Pattern is the most common architecture found in iOS apps and is recommended by Apple.</p><p>An app which adopts the MVC pattern typically has 3 main layers.</p><ol><li>Model</li></ol><p>Models are representations of your your app’s data. For example, objects like Users or Posts would be models of data. A User class or struct could hold information tied to a specific user like username, birthdate, etc.</p><p>2. View</p><p>Views are objects that users of your app can see and interact with. View objects should be reusable and flexible. Things like UILabels which can show any kind of text are views.</p><p>3. Controller</p><p>Controllers mediate between the View and the Model. Controllers set up views with the data from models and update models when users interact with views.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*j_a2nAVjuvTBoQuXV7MAHw.png" /></figure><h3>The Dream behind MVC</h3><p>MVC is meant to be a powerful iOS architecture pattern for good object oriented programming. It allows for a clear separation of your application’s data/logic, views, and controllers. Ideally, models and views should not directly interact and controllers should mediate. If you use a backend or local storage system, the logic for updating your model objects should be in those model files. Views should be “dumb” and only handle presentation related tasks.</p><h3><strong>Reality</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*kaWC6FFWc8m5DpJlFPoM1A.jpeg" /></figure><p>Massive View Controllers.</p><p>Often, apps which follow the MVC design pattern have absolutely massive view controller files which do everything. Also, it is almost inevitable that your app will in some way, breach MVC rules.</p><p>Views might directly interact with your app’s data or Models might update what the user sees on their screen. While this is a no-no according to MVC and Apple, it happens all the time.</p><h3>Should I Use MVC for my app?</h3><p>If you are just starting out or are building a relatively simple application, MVC will most likely be perfect. Having UIViewController objects do lots of different things is a very easy way to create simple apps. MVC is established and well documented so it is easy to find great examples.</p><p>Apple’s documentation on MVC:</p><p><a href="https://developer.apple.com/library/content/documentation/General/Conceptual/DevPedia-CocoaCore/MVC.html">https://developer.apple.com/library/content/documentation/General/Conceptual/DevPedia-CocoaCore/MVC.html</a></p><p><em>Some alternatives:</em></p><p>MVVM — Model, View, ViewModel</p><p><a href="http://artsy.github.io/blog/2015/09/24/mvvm-in-swift/">MVVM in Swift - Artsy Engineering</a></p><p>VIPER — View, Interactor, Presenter, Entity, Routing</p><p><a href="https://www.objc.io/issues/13-architecture/viper/">Architecting iOS Apps with VIPER</a></p><p>Other design patterns might be harder to start out with for newcomers, but if you are developing a complex application, learning about and adopting MVVM or VIPER might be helpful for you and your team in the long run.</p><p>Most popular applications today use their own design patterns — often a mixture of traditional ones.</p><h3>Some Final Tips for those using MVC</h3><ol><li>Give your objects clear responsibilities and don’t deviate from them.</li><li>Make your views reusable, flexible, and testable.</li><li>Try and keep your Controllers as clean as possible. Debugging will be much easier.</li></ol><p><em>This post was written for the Mobile Developers of Berkeley, UC Berkeley’s premier mobile development focused student organization.</em></p><p><em>http://www.mobiledevsberkeley.org/</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7206b7dc985a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering the Storyboard Reference]]></title>
            <link>https://medium.com/@eliothan/mastering-the-storyboard-storyboard-reference-77beb40e302e?source=rss-c5f190299597------2</link>
            <guid isPermaLink="false">https://medium.com/p/77beb40e302e</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Eliot Han]]></dc:creator>
            <pubDate>Thu, 12 Jan 2017 21:38:58 GMT</pubDate>
            <atom:updated>2017-08-09T18:20:57.492Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_hyuJ_rhIdc14eo_W4bF6A.png" /><figcaption>It’s not as bad as some others I’ve seen…</figcaption></figure><p>Storyboards.</p><p>Love em or hate em, they definitely can be useful.</p><p>While I was beginning to learn iOS development, I did everything I possibly could on Main.storyboard. Drag/drop was fast and easy and allowed me to easily visualize what I was creating. Why would I ever do anything else?</p><p>Yet, even when creating my first simple app, my Main.storyboard got fairly cluttered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*gcvzA9Ar52T7ZJU83fj56g.png" /><figcaption>This one isn’t that bad as well, I guess…</figcaption></figure><p>Oh and by the way, check out another screenshot from my first app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/1*TyDWvAuZhwOnfWwGO1d9cQ.png" /><figcaption>dem issues</figcaption></figure><p>However, as I later found out working on my first app within a team, git and storyboards did not work well together. For those of you who haven’t experienced a storyboard merge conflict, don’t worry, you aren’t missing out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/815/1*T3ygeLQHpseoSm4ZwjRy2Q.png" /><figcaption>A comment on stack overflow talking about sboards: <a href="http://stackoverflow.com/questions/9404471/when-to-use-storyboard-and-when-to-use-xibs">http://stackoverflow.com/questions/9404471/when-to-use-storyboard-and-when-to-use-xibs</a></figcaption></figure><h3>A Mix of Old &amp; New</h3><p>After dipping my feet in iOS development, I still liked to use storyboards to quickly setup the flow of an app despite all the points I had seen. I gave my View Controllers StoryboardIDs and created segues between them with my mouse. I had transitioned into setting UI for my controllers in code and linking each one to a Storyboard object.</p><p>Yet, this can still be a bit messy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HW_5usgbcL5xjtr_KEkR1Q.png" /><figcaption>Programmatic UI</figcaption></figure><p>Don’t think any of my personal examples were too bad so…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*bfo2GczXEwsvlQprM_5FVA.png" /><figcaption>Storyboard UI</figcaption></figure><h3>Cleaning up Storyboards Using References</h3><p>Let’s learn how to refactor our project! I will be refactoring the project highlighted in the picture with the caption <em>Programmatic UI</em>.</p><p>As this project uses a tab bar controller, I’ve decided to use a separate storyboard for each set of screens corresponding to each tab.</p><p>First, I hold <em>cmd</em> while clicking on a set of screens, making their borders blue. Then, in the top menu bar, I go to Editor --&gt; Refactor To Storyboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cf2lAph87sye68ePrDa8aw.png" /></figure><p>Click it and you will be given to the option to give your new storyboard a name.</p><p>After I do this for each set of screens, I now have 6 storyboards in my project, excluding the LaunchScreen one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/236/1*UlsCaCui_PYMssZ3xo0RZQ.png" /><figcaption>Voila, nice and neat</figcaption></figure><p>To manually create a Storyboard reference to a new storyboard file, you can just drag/drop from the bottom right corner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/255/1*uWEVcs3WKNwMcQqrfxZk0Q.png" /></figure><p>After you select the reference, make sure you give it an identity by linking it to a Storyboard and choosing an ID in the upper right corner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/264/1*MT68hjsN1j2SLfBgch6uWQ.png" /></figure><p>To present a View Controller programmatically, first, give it a StoryboardID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/255/1*pULfwrZ9j7nWEf7kyEODkw.png" /></figure><p>Then, instantiate it using its StoryboardID and present.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*OPEnvf6noaoVORuJACmduw.png" /></figure><h3>Establishing a Workflow</h3><p>It’s important to remember that the approach highlighted above is not the only approach nor the best one. Everyone’s needs are different and teams should discuss how they want to structure the workflow of their projects.</p><p>Maybe, you could just stick to one giant storyboard and have one person manage it all. (not recommended)</p><p>There’s also the approach of having every single view controller on its own storyboard file or using something I haven’t mentioned yet called nibs.</p><p>It’s up to you and your team.</p><p><a href="https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/LoadingResources/CocoaNibs/CocoaNibs.html">Nib Files</a></p><h3>Last tips</h3><ol><li>Figure out a workflow.</li><li>Don’t be afraid to use storyboards in teams.</li><li>Merge often.</li></ol><p>Good luck developing!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77beb40e302e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hashtags and Mentions in Swift]]></title>
            <link>https://medium.com/@eliothan/clickable-hashtags-and-mentions-in-swift-3-0-c627c7d3dd9d?source=rss-c5f190299597------2</link>
            <guid isPermaLink="false">https://medium.com/p/c627c7d3dd9d</guid>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[swift-3]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Eliot Han]]></dc:creator>
            <pubDate>Wed, 11 Jan 2017 06:42:16 GMT</pubDate>
            <atom:updated>2017-11-20T20:22:52.332Z</atom:updated>
            <content:encoded><![CDATA[<p>Update 11/20/2017 : The following feature is being used in Spotlight! Check it out here. <a href="https://spotlight.social/">https://spotlight.social/</a></p><p>Also, the github no longer points to latest version which fixes all the problems I had when writing this guide. I don’t plan on releasing the latest version but the current version on github will get you 95% of the functionality you want.</p><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p>One of the features I recently had to implement for a yet unnamed app in development at my startup was hashtags and mentions. Here is how it looks in the product without any personalized info.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*22YnmwZ1cwdhz2Ri01UmDg.png" /></figure><h3><strong>A General Overview</strong></h3><p>In order to implement the necessary functionality, I created a custom class called AttrTextView which inherits from UITextView.</p><p>The logic within AttrTextView does two main things:</p><ol><li>Sets text attributes on an incoming string.</li><li>Handles the tap gesture and triggers actions upon selection of # or @</li></ol><h3><strong>Setup</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lilk7xkAnbUNd1Bbx_6Cjg.png" /></figure><p>wordType is an enum we will use to refer to a word’s type, textString refers to the string you pass into AttrTextView, attrString refers to the string after attributes are applied onto it, and callBack is a function which handles what data will be displayed.</p><p>If a user clicks on a hashtag, they will be presented with search results for the hashtag, and if a user clicks on a mention, they will go to the mentioned user’s profile page if it exists.</p><h3>Setting &amp; Configuring Text</h3><p>In a public setText function, you pass the string and the text attributes you want to set on it. setText will handle setting attributes and adding a tap gesture to the hashtag or mention.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*On93rw6L-UEr1DSY2xygOQ.png" /></figure><p>Next up is setAttrWithName, a custom function that is used in setText.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mXPb0SfjqRiCpd8lQ7X1IQ.png" /></figure><h3>Handling the Tap</h3><p>After setting text attributes and adding a tap gesture recognizer, the tap is handled via a tapRecognized function. In other implementations of tap handling found on StackOverflow’s comments or on the excellent</p><p><a href="https://yeti.co/blog/hashtags-and-mentions/">Hashtags and Mentions in Swift</a></p><p>, text is checked with a .word granularity. Sadly, this means that special characters such as # and @ are omitted!</p><p>In layman’s terms, that means that while clicking on the word itself will register properly, clicking on the “#” character or “@” character in front of the word will not register. To get around around this, I use a .character granularity so I can identify if a special character is clicked. However, my function still makes sure that the callback function can receive the full word even when a special character is clicked! How I do this is shown below with a thorough explanation in the comments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lWHOSkN6NDWiWzpk3jXyaA.png" /><figcaption>don’t worry there will be a swift file to download at the bottom!</figcaption></figure><h3>A Quick Demo and the Callback</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4xAg6YJajCef9gqUkdTO6A.png" /></figure><p>Make sure to turn off the textView’s editable, scrollable, and selectable properties.</p><p>Also, insert a space at the end of the string you want to pass into setText.</p><p>And a very simple callBack function using that enum we created earlier, wordType.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wH2qUzmHREQD9BoWwIlbmg.png" /><figcaption>“call me back baby”</figcaption></figure><h3>Final Thoughts</h3><p>Hope this post was useful and of course, you are free to use AttrTextView.</p><p>Note: Aug 1 2017 → Some screenshots might be out of date. Check repo and readme for more information.</p><p><a href="https://github.com/eliot1019/AttrTextView">eliot1019/AttrTextView</a></p><p>Shoutout again to the folks at yeti for a great guide and starting point.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c627c7d3dd9d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>