<?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 MonGuNare on Medium]]></title>
        <description><![CDATA[Stories by MonGuNare on Medium]]></description>
        <link>https://medium.com/@ahimahas12?source=rss-36c8b1184023------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*C3aZ6rqw-lIgKAnbSqJSnQ.jpeg</url>
            <title>Stories by MonGuNare on Medium</title>
            <link>https://medium.com/@ahimahas12?source=rss-36c8b1184023------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 11:10:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ahimahas12/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[Developer Relations 그리고 Tech Evangelist]]></title>
            <link>https://medium.com/@ahimahas12/developer-relations-%EA%B7%B8%EB%A6%AC%EA%B3%A0-tech-evangelist-6e3d03094b5e?source=rss-36c8b1184023------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e3d03094b5e</guid>
            <category><![CDATA[developer-relations]]></category>
            <category><![CDATA[korea]]></category>
            <dc:creator><![CDATA[MonGuNare]]></dc:creator>
            <pubDate>Sun, 17 Nov 2019 07:58:50 GMT</pubDate>
            <atom:updated>2019-11-19T07:07:15.314Z</atom:updated>
            <content:encoded><![CDATA[<p>잘 다니던 회사를 때려치우고 배낭 하나 메고 유럽을 돌아다니다가, 문뜩 지인으로부터 이 Developer Relations 에 대한 포지션을 제안 전화를 받았을때만 해도 도대체가 뭐하는 직업인지 알 수 없었다. 그도 그럴 것이 한국 IT 회사에서는 이 포지션을 구하는 회사도 잘 없기도 했고 나는 내가 개발자로 있는게 너무나 행복했기도 해서인지 다른 직업을 찾아보지 않아서 그랬을수도 있었을것 같다.</p><p>마침 외국계 회사에 도전해보고 싶기도 하고, 떨어지더라도 뭐 안되면 개발자나 다시하지 😀 라는, 지금 생각해보면 정말 아무 생각없이 지원한다는게 벌써 2년째 이 일을 하고 있을 줄은 몰랐다. 또 생각보다는 개발보다 지금 하는 일이 더 재미있기도 하고, 잘 맞는것 같기도해서 신기하다.</p><p>최근 주변 사람들 중 Developer Relations 혹은 Tech Evangelist 로 활동하고 계시는 분들을 하나 둘 씩 만나보면서 혹여나 이 일에 관심이 있으신분이 있을까해서 이것저것 적어본다.</p><h3><strong>그래서 뭐하는 직업인데</strong></h3><p>그 뭐냐. 반전 영화같은거 보면 문제의 해답이 돌고 돌아서 결국 첫장면에 있었다하는 클리쉐가 있던데 이것도 비슷한 것 같다. 아니 실제 입사하고 나서도 이게 뭐하는 직업인지 한 1여년정도 고민했었는데 결국은 포지션 이름이 이 일에 대해 모든 것을 말해주고 있다는 걸 뒤늦게나마 알게 되었다.</p><p>Developer Relations (줄여서 DR), 그대로 번역하면 <strong>개발자 관계</strong>인데 흔히 플랫폼 회사와 그 플랫폼을 사용하는 개발사와의 전반적인 관계를 유지하는 포지션이다. 무슨 관계를 어떻게 유지하느냐는 각 회사별로 다르기 때문에 같은 DR 포지션이라고 해도 회사별로 하는 일이 다 다른것 같다. 최근에 만난 분들 중 조금 더 대회협력부서의 역할을 하시는 분들도 있었으며, 어떤 분들은 인사과에서 할 만한 일들을 하시는 분들도 계셨다. 그래서 딱 “<strong>이거다!</strong>”라고 정의하기 정말 어려운 포지션인것 같다.</p><h3>그래서 넌 뭐하는데</h3><p>내가 있는 회사에서는 DR 이 크게 Partnership Manager 와 Tech Evangelist 로 나뉘어져 있다. Partnership Manager 들은 커뮤니케이션 채널 역할을 주로 하는데 아직 만나보지 못한 회사에 연락하여 관계를 만들기도 하고, 이미 잘 일을 하는 회사들과는 더욱 더 긴밀하게 일을 할 수 있도록 조율하기도 한다. 반대로 Tech Evangelist 는 회사간의 커뮤니케이션에 일절 관여하지 않고, 정말 순수하게 기술을 알려주고 그 기술을 잘 쓸 수 있도록 도움을 주는 역할을 한다. 그래서 Evangelist 는 개발 지식이 있어야하기 때문에 대부분 개발자로 일을 하던 사람들이 이 포지션으로 오는 경우가 많이 있다.</p><p>나의 경우엔, 좋게 말해서 하이브리드, 나쁘게 말해서 혼자 다 하는 포지션으로 이 Partnership Manager 역할과 Tech Evangelist 역할을 동시에 수행하고 있다. 이게 생각보다 웃픈 경우가 종종 생기는데, 다른 나라에 있는 DR들은 PM 이 연락해서 미팅잡으면 Evangelist 가 들어가서 도와주는 이쁜 그림이 그려진다. 하지만 나는 내가 연락해서 미팅잡고, 미팅 들어가서 “<strong>안녕 사실 발표자는 나야 데헷</strong>&quot; 하며 뻘쭘하게 일을 해야한다.</p><h3>그래서 정확히 무슨일을 하냐고</h3><p>일단, 공부를 한다. 아니 진짜. 공부를 해야한다.</p><p>무슨 말이냐면, 플랫폼 회사이다보니 매년매년 컨퍼런스때 새로운 기술들이 쏟아져 나오는데, 이걸 누구보다 빨리, 누구보다 정확하게 공부한 뒤에 이 기술들을 각 회사에 있는 개발자들에게 알려줘야 한다. 각 기능 별로 약 1시간 발표를 몇 개씩이나 진행하는데, 올해의 경우엔 모든 발표를 다 보려면 거의 100개가 넘어가는 비디오 클립을 일일이 보고 공부해야한다. 그래서 1년 중 컨퍼런스가 진행된 이후에는 약 한 달 동안 일과 공부를 동시에 진행해야한다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*wkv-M-3FHHA4w4DgOoNsuA.png" /></figure><p>진짜 재미있는 게, 미리 이 기술들에 대해 내부에서 공유받거나 교육 받는 일이 전혀 없다. 컨퍼런스가 열리는 그 날, 새로운 기술 발표 세션을 보면서 <strong>우와 쩐다</strong> 하고 있는 개발자들 옆에 앉아 나도 <strong>우와 대박인데</strong> 이러고 앉아 있다. 😂</p><p>그 후 자료를 짧고 간단하게 정리하여 개발사들에게 기술을 알려주고 문제가 있을 경우, 내부 개발팀과 협력하여 개발사들이 이 새로운 기술을 최대한 잘 적용하도록 도와주는 일을 일년 내내 한다. 그 것 말고도 할 일은 많다는 게 함정이지만.</p><p>Tech Evangelist 로서 꾸준히 공부를 해야한다면, Partnership Manager 로서는 많은 사람을 만나고 다녀야한다. 사람이라는 게 자주 연락하지 않다보면 관계가 소홀해지듯이 회사간에 일을 할때도 똑같이 적용된다. 별 일이 없더라도 꾸준히 먼저 연락하고 미팅을 가져서 싱크업을 해야하는데 말이 쉽지 평소에 집에도 연락을 잘 안하는 내가… 갑분효도 🙏</p><p>그리고 처음 만나는 사람들이 다 친절할 것이다라는 착각에 빠져서도 안된다.생각보다, 아니 생각 이상으로 호의적이지 않는 회사도 많은데 메일을 써도 읽씹당하는 일도 태반이고 말도 꺼내기전에 거절부터하는 사람들도 많이 있다.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*Dh6xNCZCGofFvj_ucELmYA.jpeg" /></figure><p>또한 각종 컨퍼런스를 찾아보고 꾸준히 다니면서 새로운 개발사들을 찾아내야 하는데 이건 생각보다 잘 맞다. 아니, 내가 게임을 좋아해서 게임 컨퍼런스만 다녀서 그런 걸 수도 있는데 뭐 어쨌든.</p><h3>그래서 밥은 먹고 다니고</h3><p>그럼. 잘먹지.</p><h3>그래서 어떤 사람에게 추천하는지</h3><p>DR의 하는 일을 가만히 살펴보면 내가 일을 잘했다 못했다를 판단할 수 있는 객관적인 output 을 측정하기 굉장히 난해하다. 생각해보면 한 회사가 새로운 기능을 잘 적용한 게 내가 알려줘서 그런 것인지 아니면 회사내 개발자들이 잘해서 그런 것인지 알 수가 없다. 또한 Evangelist 활동을 통해 기술을 알려주더라도 이 사람이 얼마나 이해했는지를 어떻게 측정할 수 있을까.</p><p>그래서인지, 여긴 일을 벌리는 만큼 일을 해야하는 곳인 것 같다. 무슨 말이냐 하면, 아무 것도 안 해도 내가 무엇을 얼마나 했는지 잘 알 수가 없지만, 반대로 내가 마음만 먹으면 정말 많은 일들을 할 수 가 있고 그만큼 내가 엄청나게 바빠질 수도 있다. 누구 하나 나에게 어떻게 일을 하라고 알려주지 않기 때문에, 나는 나의 방법대로 개발사들에게 도움줄 수 있는 방법을 찾아내고 실현할 수 있기에 굉장히 성취감이 큰 직업으로 생각된다. 내가 벌린 일이라서 바쁘더라도 신기하게 스트레스가 많이 쌓이지 않는 장점(?)도 있다.</p><h3>그래서 마무리는 지어야지</h3><p>나는 사람들과 이야기하는 것 보다 혼자 좋아하는 노래 들으면서 개발하는것을 더 좋아하는 사람이었고, 개발자라는 직업이 천직이다라고 생각할정도로 만족하면서 살아왔었지만, 생각보다 난 사람들과 이야기하거나 남을 도와주는것에서 만족감을 많이 느낀다는 것을 알게 해준 포지션이다. 나의 개발자 인생은 3년 이상 같은 팀에서 일을 해본 적이 없었지만, 아마도 DR은 평생해도 재밌지 않을까하는 생각이 문뜩 든다.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e3d03094b5e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Grab user experience — 8 things to improve game quality on iOS]]></title>
            <link>https://blog.prototypr.io/grab-user-experience-8-things-to-improve-game-quality-on-ios-1b9971ef0b25?source=rss-36c8b1184023------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b9971ef0b25</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[games]]></category>
            <category><![CDATA[mobile-game-development]]></category>
            <category><![CDATA[mobile-game-design]]></category>
            <dc:creator><![CDATA[MonGuNare]]></dc:creator>
            <pubDate>Tue, 21 May 2019 16:59:21 GMT</pubDate>
            <atom:updated>2019-07-30T07:37:13.269Z</atom:updated>
            <content:encoded><![CDATA[<h3>Grab user experience — 8 things to improve game quality on iOS</h3><p>Are you considering launching a game on the App Store? Or maybe on both Android and iOS platforms using a middleware such as Unity or Unreal? Well then, you are at the right address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*IRXYnhTFJqi79iyEhEyZgw.jpeg" /></figure><p>Here are several points that you should know before or after launching a game on the App Store.</p><ul><li>remove the <strong>get notification</strong> auth step</li><li>allow <strong>background download</strong> for the extra data</li><li>keep the <strong>tutorial</strong> short</li><li>provide <strong>skip</strong> buttons for every situation</li><li>enable <strong>touching in the background to escape </strong>from pop-up</li><li>consider supporting the display for the <strong>iPhone X and above</strong></li><li>keep the <strong>screen UI clean and intuitive</strong></li><li>use <strong>Haptic</strong> feedback</li></ul><p>Time is gold💰 Let’s move on!</p><p>— —</p><h3>Remove the get notification auth step</h3><p>Notification can be useful if they are <strong>allowed. </strong>However, think about how many users will grant permission before knowing what notification content will be.</p><p>From iOS 12, developer can let users decide later after received the first notification, which called provisional authorization. See this <a href="http://iosbrain.com/blog/2018/07/05/new-in-ios-12-implementing-provisional-authorization-for-quiet-notifications-in-swift/">great article</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*3_Lqz7ocaxghG_6VIhz2ZA.png" /><figcaption>post non-interruptive user notifications</figcaption></figure><h3>Allow background download for the extra data</h3><p>Heavy games tend to need additional data for playing the game, e, g, MMORPG game needs to download 5~10GB more When it 1st launches. That takes a lot of time, sometimes more than 10 minutes, making users exhausted even before starting the game.</p><p>The best experience is, providing tutorial steps or early game stages beforehand starting to wait the extra data. That let players enjoy at least minimum amount of contents. At the meantime, the additional data could be downloaded through background process so that game plays can go to the next stage without waiting. You can reference the best on-boarding process through those games — <a href="https://itunes.apple.com/us/app/hearthstone/id625257520?mt=8">Hearthstone</a>, <a href="https://itunes.apple.com/us/app/epic-seven/id1322399438?mt=8">Epic Seven</a> and <a href="https://itunes.apple.com/id/app/durango-wild-lands/id1281442514?mt=8">Durango</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*llAaoGvKdftOCvYpemUrNg.png" /><figcaption>background download allows user to move around menus (Hearthstone)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-t3uLQYPr5r4r9mg0kqUKg.png" /><figcaption>additional data is downloading during tutorial battle (Epic Seven)</figcaption></figure><h3>Keep the tutorial short</h3><p>Well, unlike you think, users are smart enough to understand basic controls on the game unless you create an innovative feature or new game genre. Don’t forget that users launch your game, not for being educated but being fun.</p><p>Try to make a tutorial intuitive and do not interfere users action. <a href="https://itunes.apple.com/us/app/altos-odyssey/id1182456409?mt=8">Alto’s Odyssey</a> shows the best tutorial flow, and <a href="https://itunes.apple.com/us/app/cytus-ii/id1290687550?mt=8">Cytus 2</a>, one of the famous rhythm game, shows it as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qsJKJujFgCV5JsV59zwmRg.png" /><figcaption>tutorial process smoothly within game play (Alto’s Odyssey)</figcaption></figure><p>The worst experience would be placing multiple tutorials serially that force users to complete for all without any options, e, g, a battle tutorial is followed to an inventory tutorial which is followed to a weapon enhancement tutorial and, oh god, an another battle tutorial and it goes on and on. 🤬</p><p>To reduce those time consuming process, providing skip buttons for every tutorial would be a great option. <a href="https://itunes.apple.com/us/app/epic-seven/id1322399438?mt=8">Epic Seven</a>, developed by Smilegate Megaport, does the great job that you should check!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kY8307nsYtU84pwnUiplfQ.png" /><figcaption>give an option to cancel battle tutorial (Epic Seven)</figcaption></figure><h3>Provide skip buttons for every situation</h3><p>Talking about the skip buttons mentioned above, someone might not agree with certain cases, such as at story based games or while video clips played. Well, I can agree with some points but the existence of skip button itself can give an option to the users who don’t really care about tutorials or video clips but swiftly jump into game contents. Showing a skip button at the corner of a screen while video clip is playing and making it hidden in few seconds later and then fading the button in again once user touches screen could be the best practice so that players can fully focus on video. <a href="https://itunes.apple.com/us/app/fishing-and-life/id1457176367?mt=8">Fishing and Life</a> can explain it very well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5W5MZX76SXX3CfLF6zBr5A.png" /><figcaption>skip button appears only when screen touched (Fishing and Life)</figcaption></figure><h3>Enable touching in the background to escape from pop-up</h3><p>Unlike using mouse experience at PC, pin-pointing a small button is a lot of burden to the finger, especially to thumb when users use the smartphone as portrait way. Why not just let users can get out of a floating menu through touching a dimmed background as well as touching the close button? Download <a href="https://itunes.apple.com/ca/app/brawl-stars/id1229016807?mt=8">Brawl Stars </a>and try yourself!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CZzNCT7nrG3cafzEVjI8Rw.png" /><figcaption>close menu through touching dimmed background as well as X button (Brawl stars)</figcaption></figure><h3>Consider supporting the display for the iPhone X and above</h3><p>Imagine how users feel if their favorite game, said <a href="https://itunes.apple.com/us/app/hearthstone/id625257520?mt=8">Hearthstone</a>, is not supported for iPhone X display. Imagine how much people disappointed when they see your game shown on in smaller area than it could be.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fIWAmXlFJbgP80WZLTU3Aw.png" /><figcaption>shrink image and make side/bottom area black by force (Hearthstone)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KYOmGArHv9wMrWF5zAN4eQ.png" /><figcaption>even smaller — actual play screen of (Brown Dust)</figcaption></figure><p>Adjusting an image to fit on a screen is not enough if you are still thirsty of quality. Please check <a href="https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/adaptivity-and-layout/">Apple Human Interface Guideline — Layouts </a>and put all touchable buttons inside of safe area, making touch experience be better.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cYkOrBlYVeGZaAOW7TOcfw.png" /><figcaption>locate all touchable buttons inside of the blue area</figcaption></figure><h3>Keep the screen UI clean and intuitive</h3><p>Mobile device has a relatively smaller screen comparing with PC or console environment. More information added, more complexity level goes up that makes people to focus on harder.</p><p>You can reduce overall UI complexity through removing buttons and any information label as much as you can, putting them into somewhere under menu hierarchy. And then, think twice whenever that UI component be fronted at the main screen. Giving an option to hide redundant information or hiding menus while users are moving the screen would be great choice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pQtO3gjUVZa4hQT66De_CA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GQw8Qr9aUppUn2cCEX7DIg.png" /><figcaption>Cleaning up through hiding text labels (The War of Genesis)</figcaption></figure><h3>Use <strong>Haptic</strong> feedback</h3><p>You know what? I almost crashed my iPhone while I was playing the masterpiece classic RPG game, which was remade for mobile platform, <a href="https://itunes.apple.com/us/app/valkyrie-profile-lenneth/id1324458386?mt=8">Valkyrie Profile</a>, i, e, I thought that I definitely touched a jump button but character didn’t jump over, felling down and game’s over!!!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q-ZBIjbQMhD7cEuoDvX8Rw.png" /><figcaption>Valkyrie Profile: LENNETH</figcaption></figure><p>As you can easily guess, mobile device doesn’t have hardware buttons but controlled by virtual buttons on flat screen that it’s hard to give feedback back to the users for what they’re acting. Haptic feedback, which differ from vibration, would be great choice give a rich feedback along with sound effect and visual effect. Also giving on/off option would be great choice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*jeiYn3OMnZ2MR04OGDD4YQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lJK8KoT1I9vQW7FiqETNqQ.png" /><figcaption>give an option to turn on/off haptic feedback (Fortnite)</figcaption></figure><h3>Overall</h3><p>UX is something like an invisible monster that if your manager ask you to prove the quality as a number, well, I’m so sorry but those information cannot be helped. And you know what? It <strong>IS</strong> true that better quality might not effect making money more. Pretty sad. isn’t it?</p><p>However, DO NOT forget that each platform has its own specific experiences and features, strongly connected with hardware function. If your eyes closed and publishing game to Android and iOS with the same experience, or just porting console/PC game to mobile platform, then the one who is going to be suffered is not you, but users.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Ff51076%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Ff51076%2F&amp;image=http%3A%2F%2Fapi.screenshotlayer.com%2Fapi%2Fcapture%3Faccess_key%3Dfe59908dad3baab69ffab249a2224b03%26viewport%3D1024x612%26width%3D1000%26url%3Dhttps%253A%252F%252Fupscri.be%252Ff51076%253Fscreenshot&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/b85dfbb5286d8a25cf2e754b9462cf45/href">https://medium.com/media/b85dfbb5286d8a25cf2e754b9462cf45/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b9971ef0b25" width="1" height="1" alt=""><hr><p><a href="https://blog.prototypr.io/grab-user-experience-8-things-to-improve-game-quality-on-ios-1b9971ef0b25">Grab user experience — 8 things to improve game quality on iOS</a> was originally published in <a href="https://blog.prototypr.io/">Prototypr</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Swift: Use Interface Protocol just like “.h” file in Objc does]]></title>
            <link>https://medium.com/@ahimahas12/swift-use-interface-protocol-just-like-h-file-in-objc-does-fd57ab8ed303?source=rss-36c8b1184023------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd57ab8ed303</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[MonGuNare]]></dc:creator>
            <pubDate>Sat, 22 Jul 2017 05:48:01 GMT</pubDate>
            <atom:updated>2017-07-22T05:48:36.276Z</atom:updated>
            <content:encoded><![CDATA[<p>I am a huge fan of Objective-C language as much as Swift. I totally agree with that using Swift, I can create my code more grammatically just like a novel, which has great advantage for code readability aspect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*OHso4FvGXbpX5MvvCm-d8g.png" /><figcaption>Code reading is always fun!</figcaption></figure><p>However, one of my favorite feature in Objective-C is, it has separated header file that explains me how the certain class works and provides functions. So whenever I need to use 3rd party module, the first thing I’ll take is open up the header file and look through all functionalities. Unfortunately in Swift, I have experienced many times that I look though all enormous codes in one class file; some of codes that I have to know but most of codes is ignorable.</p><p>How can I design a class that also has high readability for those who wants to use it? Here is some suggestion; using <strong><em>//MARK:</em></strong> notation and interface protocol.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*Wb-Fj3kxto91FEuELvGEag.gif" /><figcaption>Time to coding! yeah!</figcaption></figure><h3>Let’s do it</h3><p>Let’s say I’m making a ScheduleReminder that reminds me whole schedules for today every morning. I can set a AlarmingTime which has two integer values, hour and minute. Here is a simple code example;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*AW6Xw8g__UWKVsCr1OW5rQ.png" /></figure><p>There are two properties, the schedule lists property as public (actually, default access scope is Internal but let’s say public in here) and alarmingTime as private. Also it has three public methods for add, modify and delete the schedule and two utility methods as private.</p><p>Now, I’m done and pass this module to my colleague. What action can be expected when the first time my colleague give this module? Of course, he’ll look through all codes and figure out the available functions he can use.</p><p>Fortunately, this ScheduleReminder class has only few properties and methods which is not take so long time reading through all codes, but what if the module has hundred and thousands lines of code? I’m quite sure that we’re having meeting just after 5 minute I gave it to him.</p><p>As a perspective of readability, there is one possible solution; put <strong><em>//MARK:</em></strong> notation between public and private functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*V48YAhNWfwDV-nCnNwfjSg.png" /></figure><p>This approach has a several advantage. Putting all functions which have same access scope in together, the other developer can easily find out what function this module provides and doesn’t need to read and understand all codes. The other advantage of this way is, you can understand the module structure at a glance using breadcrumb menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*hHKb4UvXCere53vc9zFC1g.png" /></figure><p>However, using <strong><em>//MARK:</em></strong> notation is too fragile as maintenance side. What if the other developer adds a public function at the end of code? What if the modify function is changed to private function during refactoring and what if developer forget to put “private” notation in front of function that has to be private? Do we fix the notation position as well every time? Since a <strong><em>//MARK:</em></strong> notation is a sort of COMMENT, it is a cost for maintain itself.</p><p>Another option I can choose is, using protocol to specify all features in a protocol file. I prefer to name it as interface; in this example, it can be named like ScheduleReminderInterface.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*Bf8eCLkrNs_-i7OKxoljkQ.png" /></figure><p>For the use case, declare property as ScheduleReminderInterface and initialize it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*S2GoiZ3os62XbgsVe3dbXA.png" /></figure><p>Now, I can create a new Swift file and put the protocol codes in there, it will work just like what Objc header file does.</p><p>The best benefit of using interface protocol is, the other developers don’t need to care about how long and how complex the module is but simply figure out what they needs. Plus, since ScheduleReminderInterface is a protocol, the class who has this interface is not affected by code changing for ScheduleReminder class at all.</p><h3>Conclusion</h3><p>Providing interface protocol is a one way to improve code readability and maintenance. The famous phrase says that “There is no silver bullet”, this approach is not solve every problem perfectly but think though, more cards for architecture we have, better way we can find out for problems I believe.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd57ab8ed303" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS Performance Optimization Tips]]></title>
            <link>https://medium.com/@ahimahas12/ios-performance-optimization-tips-cee13f9f61f8?source=rss-36c8b1184023------2</link>
            <guid isPermaLink="false">https://medium.com/p/cee13f9f61f8</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[optimization]]></category>
            <dc:creator><![CDATA[MonGuNare]]></dc:creator>
            <pubDate>Sat, 01 Apr 2017 10:07:04 GMT</pubDate>
            <atom:updated>2017-04-01T10:07:04.060Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*cBdrD0YgNXR8NtFXe0aUOQ.png" /></figure><p>There are so many great articles about “OPTIMIZATION” over the Internet. I have been researching through read those articles. Here I want to share tips about where you can start from optimization you application.</p><p>Tuning Points are;</p><ol><li>Touch responsiveness</li><li>Touch Responsiveness in WebView</li><li>Application Launch Time</li><li>Reduce Image Resources</li><li>Monitoring Network Usage</li><li>Parsing Api Response Data in other Thread</li><li>Smooth Scrolling</li></ol><p>Since I just want to share the points of optimization, I rather not attach a detail codes nor repository.</p><h3>Touch Responsiveness</h3><p>Touch responsiveness is the time it takes for the user to get feedback from the device as a consequence of an input. If it takes longer, then that means your application is SLUGGY.</p><p>To measure touch responsive time, you can measure the time from touch event fired to view is appeared. Then, how can I detect the very first touch event on device? To do that, making custom UIApplication, called MyApplication, overriding “sendEvent:”.</p><pre>// .h<br>extern CFTimeInterval touchStartTime;</pre><pre>// .m <br>CFTimeInterval touchStartTime;</pre><pre>@implementation MyApplication<br>    <br>- (void)sendEvent:(UIEvent *)event {<br>    touchStartTime = CACurrentMediaTime();</pre><pre>    [super sendEvent:event];<br>}</pre><pre>@end</pre><p>To apply custom UIApplication, go to “main.m” and put “MyApplication” in “UIApplicationMain” method.</p><pre>#import &quot;AppDelegate.h&quot;<br>#import &quot;MyApplication.h&quot;</pre><pre>int main(int argc, char *argv[]) {<br>    @autoreleasepool {<br>        return UIApplicationMain(argc, argv, @&quot;MyApplication&quot;, NSStringFromClass([AppDelegate class]);<br>}</pre><p>Then, select target view that you want to measure touch response time and simply compare with “touchStartTime” when the view is appeared. If it is view controller, “viewWillAppear” would be the best place.</p><p>If it takes logger than you expected, remind view controller’s life cycle and check “loadView” and “viewDidLoad” methods that whether it has heavy works or not. In my case, a certain view controller was too late to showing up because of a bunch of data were parsed in “viewDidLoad” on a main thread.</p><h3>Touch Responsiveness in WebView</h3><p>Using with UIWebView, the touch responsive time takes more than 300ms which is proper time for reacting user’s interaction Apple thought, but still developers can reduce this time. Through catching touch event on Javascript level and changing to custom event handler, this delayed touch can be removed. Here is a great article about how to cover it.</p><p><a href="http://developer.telerik.com/featured/300-ms-click-delay-ios-8/">http://developer.telerik.com/featured/300-ms-click-delay-ios-8/</a></p><p>On the other hands, you can simply using WKWebView instead of UIWebView, the default 300ms touch delay is gone away. It sounds perfect that you might change every single web view to wkWebView but there are some issues on that; it requires iOS 9 or later, doesn’t support some caching, cookie setting problem or etc. You can check issues in here.</p><p><a href="http://docs.kioskproapp.com/article/840-wkwebview-supported-features-known-issues">http://docs.kioskproapp.com/article/840-wkwebview-supported-features-known-issues</a></p><h3>Application Launch Time</h3><p>There are two ways application launches from background to foreground, cold and warm launch.</p><p>Cold start up is happened when your application is not sustained on memory area so that it is needed to load all required data from the scratch. See the WWDC video clip “Optimizing App Startup Time” can help you to understand what kind of things are actually happened during the cold start up time.</p><p><a href="https://developer.apple.com/videos/play/wwdc2016/406/">https://developer.apple.com/videos/play/wwdc2016/406/</a></p><p>To be honest, there are not many solutions that we can improve our application’s cold start up time in reality. However, still you can make application faster through tuning in warn start up period. Check your codes from “main.m” to the first view controller’s “viewWillAppear” is called. Generally “application:didFinishLaunchingWithOptions:” method in AppDelegate will be main target since you request a main api call, setting up application’s view architecture and parsing all data.</p><h3>Reduce Image Resources</h3><p>The application’s IPA file is consists of your own codes, library’s codes, and resources. Among them, also same in my cases, the criminal who makes application’s app size larger is the image resources. Using followed command, you can check how much those image resources take a possession of the file size.</p><pre>unzip -lv YOUR_APP.ipa | sort -k +3nr | head</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*jIjj1_8i0One3LeYDiH3Nw.png" /></figure><p>You can reduce assets size through removing redundant images, changing image format or event re-targeting membership setting on Xcode. In my case, I set a asset’s target to my main application and also target to a widget extension which cause duplication of Assets.car in IPA file. So I simple move all images that used in extension code from main asset to extension asset, my application size is reduced 15% down.</p><h3>Monitoring Network Usage</h3><p>Reducing network data usage is also good point of optimization. There can be many options that how to cut network usage down but before you jump into work, you better to know how to measure current network status.</p><p>All default url connection on iOS are pass through a NSURLProtocol which means, once you make custom URLProtocol and register it into protocol pool, you can detect all url connections and data transactions. Here is sample code.</p><pre>// .h<br>@interface CustomURLProtocol: NSURLProtocol<br>@end</pre><pre>// .n<br>@implementation CustomURLProtocol</pre><pre>// need to override some required method<br>+ (BOOL)canInitWithRequest:(NSURLRequest *)request {<br>    if (![[NSURLProtocol propertyForKey:@&quot;RequestFlag&quot; inRequest:request] boolValue]) {<br>        return YES;<br>    }</pre><pre>    return NO;<br>}</pre><pre>- (void)startLoading {<br>    NSURLRequest *request = //...<br>    [NSURLProtocol setProperty:@YES forKey:@&quot;RequestFlag&quot; inRequest:request];</pre><pre>    NSURLSession *session = //... <br>    [[session dataTaskWithRequest:request] resume];<br>}</pre><pre>#pragma mark - NSURLSessionDelegate</pre><pre>- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data {<br>    <br>    // receiving data<br>    // add codes here</pre><pre>    [[self client] URLProtocol:self didLoadData:data];<br>}</pre><pre>- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error {</pre><pre>    // received all data<br>    // add codes here</pre><pre>    if (error == nil) {<br>        [[self client] URLProtocolDidFinishLoading:self];<br>    } else {<br>        [[self client] URLProtocol:self didFailWithError:error];<br>    }<br>}</pre><pre>@end</pre><p>This sample code is not a perfect enough but still it can help you to understand how the things are going on. Using NSURLSessionDelegate, you can measure each network connection from begin to end.</p><p>If your application use libraries for network request such as AFNetworking, SDWebImage or etc, that network connections won’t be detected in this custom url protocol class; those libraries have their own url session. Hopefully, most of network libraries provide their network status through notification center, you can still catch each stage of network status.</p><h3>Parsing Api Response Data in other Thread</h3><p>It is common sense that api request should be called in a different thread from main thread. Many famous libraries also process an api network connection on their own thread pool. But when api request is over, the process was returned back to the main thread and usually, developers do a bunch of parsing data in same thread without any doubt. Check your api network module and where the response data is parsed in your code.</p><p>I had a big latency issue when I got a data from server. The api response usually less than 500kb, but once it was increased more than 10MB by accident, it took 2~3 seconds to parse all data and guess what, my application was frozen during parsing was processing.</p><h3>Smooth Scrolling</h3><p>I will not surprise that if almost every applications on market contain at least one table view or collection view. Those two components are probably the most used component through all components provided by Apple. Your customer always do scrolling up and down in your application. If the scrolling action is not smooth enough, it directly affects to negative user experience seriously.</p><p>One way to improve smooth scrolling is prefetching data and cell in advance. Most of time for drawing cell is spent to calculate a height of cell if the cell is growing dynamically depending on data. Even though Apple provide “estimatedRowHeight” option, it won’t be helpful that much.</p><p>Hopefully, the UICollectionView classes for iOS 10 promise better performance with the under-the-hood changes like prefetching and life cycle function improvements. It supports “UICollectionViewDataSourcePrefetching” protocol and contains two instance functions;</p><pre>- (void)collectionView:(UICollectionView *)collectionView prefetchItemsAtIndexPaths:(NSArray&lt;NSIndexPath *&gt; *)indexPaths // required</pre><pre>- (void)collectionView:(UICollectionView *)collectionView cancelPrefetchingForItemsAtIndexPaths:(NSArray&lt;NSIndexPath *&gt; *)indexPaths // optional</pre><p>For tableView component and the codes less then iOS 10, you can make custom prefetching module just like UICollectionView does, calculating cell’s height around 5 or more in advance.</p><h3>Sums Up</h3><p>There are not a black magic nor silver bullet to improve application’s performance at once. And also difference application has difference logic inside. Time and continuous effort can only weapon to redeem low-quality application I believe.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cee13f9f61f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Make your Objective-C code simple using DSL]]></title>
            <link>https://medium.com/@ahimahas12/make-your-objective-c-code-simple-using-dsl-46fd2bd388cf?source=rss-36c8b1184023------2</link>
            <guid isPermaLink="false">https://medium.com/p/46fd2bd388cf</guid>
            <category><![CDATA[objective-c]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[MonGuNare]]></dc:creator>
            <pubDate>Sun, 05 Feb 2017 05:53:50 GMT</pubDate>
            <atom:updated>2017-02-05T05:53:50.556Z</atom:updated>
            <content:encoded><![CDATA[<p>When the first time I learned iOS programming, I struggled a lot with Objective-C grammars. But once I adapt myself, it becomes one of my favorite language; it contains so many philosophies in it! However, because Objc has its own style, sometimes codes is written in a little too lengthy.</p><p>For me, I had a problem to make a common module using Objc language. Once I made it, it needs bunch of boiler-plate codes to use it. At the time, I decided to make my own DSL, domain specific language, to solve my code issue and I got a results through that! Here is the thing!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*6biJUKkNFJXN9PUzSayUFg.png" /></figure><h3>Here is the situation I faced with</h3><p>My mission was making some “<strong>super easy to use for team members</strong>” module that it measures a time to first interaction from a user. For example, when user enters some page, they do some actions such as touching loading display, but once that page takes way too long time, what the user action expected is simply going out of that page, they are not patient enough!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/1*Nsr-bAhTt0IFaghhhXqVqg.png" /></figure><p>Then, what is the time to interaction module, named TTI, do? It figures out which component takes how much time to load up.</p><p>I have know idea how Facebook requests API but here is simple example. To show up the below feed page, let’s assume that it needs one API request for whole data and one request for retrieving image data from cdn server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*EEdU81nKUtKe_OPiB2HPog.png" /></figure><p>In this case, TTI module measures those two network requests and calculate how long it takes to get information for each.<br>Good, then, let’s make it!</p><h3>General Objective-C Style</h3><p>The module design I take is declare all API calls before a page is loaded. Using example above,</p><blockquote>“Oh, this page will shows up one feed. To do that, it needs one api request and one image request. Then measure those two thing!”</blockquote><p>It can be changed into code like;</p><pre>// some viewController<br>- (void)loadView {<br>  [TTICenter targetPage:@&quot;newsFeedPage&quot;];<br>  [TTICenter measureRequest:API_REQUEST named:@&quot;feedRequest&quot;];<br>  [TTICenter measureRequest:IMAGE_REQUEST named:@&quot;attachedImage&quot;];<br>  [TTICenter start];<br>}</pre><p>It seems a bit complicated to use that it has to follow certain “method call process” from “targetPage” to “start” which is not convenient.</p><p>So I put it in one method call like below;</p><pre>// some viewController<br>- (void)loadView {<br>  [[TTICenter targetPage:@&quot;newsFeedPage&quot;<br>              measureRequests:@[API_REQUEST, IMAGE_REQUEST] <br>              named:@[@&quot;feedRequest, @&quot;attachedImage&quot;]] <br>  start];<br>}</pre><p>Now, the new method looks more clear to understand and do not has to follow all method call process anymore! Mission completed!</p><p>When I almost finished my job, my boss came to me and said, “Did you consider about A/B test case? I want the results of both side of different cases.” Wait, what? I can see your point and it is totally understandable but, why didn’t you said me at the first step??</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*G7LDTB_HDx9QRSQ1walfmw.png" /></figure><p>According to my new added spec, the above example feed view can be shown as different types depends by received data. If received data tells that “I’m a view with three images without no text!”, the result view looks somehow different from the first one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/1*oDo4d9GEOQGvN2T1Yis0Eg.png" /></figure><p>Alright then, I can change my TTI method depends by different view type;</p><pre>// some viewController<br>- (void)loadView {<br>  [TTICenter targetPage:@&quot;newsFeedPage&quot;<br>             viewType:@&quot;textAndImage&quot;<br>             measureRequests:@[API_REQUEST, IMAGE_REQUEST] <br>             named:@[@&quot;feedRequest, @&quot;attachedImage&quot;]];</pre><pre>  [TTICenter targetPage:@&quot;newsFeedPage&quot;<br>             viewType:@&quot;onlyImages&quot;<br>             measureRequests:@[IMAGE_REQUEST, IMAGE_REQUEST, IMAGE_REQUEST] <br>             named:@[@&quot;image1, @&quot;image2&quot;, @&quot;image3&quot;]];   <br>  [TTICenter start];<br>}</pre><pre>// after get data about view type<br>{<br>  ...<br>  [TTICenter selectedViewType:@&quot;onlyImages&quot;];<br>  ...<br>}</pre><p>Since the module hasn’t got a clue which view type will be selected, all possible view types are declared at the first time and one of type will be selected after receive information from server.</p><p>Here is a BIG problem. I break the rule. “<strong>EASY TO USE</strong>”. What if a feed has 4 different view type? Do my team members have to write these boiler-plate codes in each pages? No way!</p><h3>Using DSL: declare my own language</h3><p>The approach is started from usage case. If I’m a developer that going to use this module, how it would be designed for applying easily?</p><p>I inspired a lot from the github module named, Masonry, which supports easy way to apply view’s layout constraint programatically. Here is a reference link;<br><a href="https://github.com/SnapKit/Masonry">https://github.com/SnapKit/Masonry</a></p><p>So, my code is changed using own custom language;</p><pre>// some viewController<br>- (void)loadView {<br>  [[TTICenter declareWith:^(TTIConstraint * make) {<br>    make.targetPage(@&quot;newsFeedPage&quot;);<br>    make.viewType(@&quot;textAndImage&quot;).api(@&quot;feed&quot;).image(@&quot;image&quot;);<br>    make.viewType(@&quot;onlyImages&quot;).images(@[image1, image2, image3]);<br>  ] start];<br>}</pre><p>The unnecessary request type now is changed to “api” and “image”, or “images” for the multiple images. Moreover, each related information is linked through dot(.) notation which is super clear to understand!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*L-8OUBim8WYJwwoZKvTChA.png" /></figure><h3>How it works</h3><p>First problem is, how can I get the value inside of round brackets such as “make.targetPage(“value”)” ?</p><p>Using Swift is super easy, you can simply make a methods for TTIConstraint;</p><pre>class TTIConstraint {<br>  public final func targetPage(_ page: String)  {<br>    //.. do something</pre><pre>    // return self for chaining<br>    return self <br>  }<br>} </pre><p>But once you tried to apply it using Objective-C, it’s a different story. Objc’s method style is different from Swift’s one, it is not possible to access method using dot(.) notation. If you make a code just like Swift way;</p><pre>- (TTIConstraint *)targetPage(NSString *page) {<br>  //.. do something<br>  <br>  //return self for chaining<br>  return self;<br>}</pre><p>The usage case will be;</p><pre>...<br>// expect &quot;make.targetPage()&quot; but actually it is not<br>[make targetPage:@&quot;newsFeedPage&quot;];<br>...</pre><p>To use dot(.) notation in Objc, returning a block statement rather than a self class.</p><pre>- (TTIConstraint  *(^)(NSString *))targetPage {<br>  return ^id(NSString *value) {<br>    //.. do something</pre><pre>    // return self for chaining<br>    return self;<br>  };<br>}</pre><p>In this code, when you access to make.targetPage, it returns block statement. In that block, you can specify some value running that block, “NSString *value” in this case, processing that block and it returns self.</p><p>In “do something” area, you can keep that value using any data structure. This class will be used by chaining method call so that you can add more information related by first declared TTIConstraint class.</p><p>I will add sample code later on but someone who want to see code structure first, you can reference github code I mentioned before, Masonry code for Objective-C, SnapKit code for Swift.</p><h3>Final Thought</h3><p>Domain specific language might generate more complexity; it raise learning cost up to other developers. But once it is implemented with well-defined grammar, and not frequently changeable, I strongly believe that it helps to improve using Objective-C grammar.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46fd2bd388cf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tech Algorithm Interview in Swift: Lego Problem]]></title>
            <link>https://medium.com/@ahimahas12/algorithm-in-swift-lego-problem-d58c7c809556?source=rss-36c8b1184023------2</link>
            <guid isPermaLink="false">https://medium.com/p/d58c7c809556</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[fibonacci]]></category>
            <dc:creator><![CDATA[MonGuNare]]></dc:creator>
            <pubDate>Fri, 27 Jan 2017 10:00:32 GMT</pubDate>
            <atom:updated>2017-01-27T11:04:03.930Z</atom:updated>
            <content:encoded><![CDATA[<h3>Intro</h3><p>Several month ago, I had a chance to have a technical interview from a company located in San Fransisco. At that time, I was challenged to solve this Lego problem. It seems quite easy and simple enough question but since I have been working in a company and lived without facing with algorithm, I was struggled to solve it out in an hour. After then, I googled and found that all articles are written in c++, Java, or Python. Okay then. why not for Swift?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*HKCUb95oGyCWbcZyezsK2Q.png" /></figure><h3>Here is definition of problem</h3><p>Let’s assume that we have four different peace of Lego which height is 1, 3, 4 and 6 for each and using these Lego, we want to build up Lego towel up to certain height.</p><p>To given target height, get a number of ways that usage of different Legos.</p><p>For example, when the target height is 4, the ways to get that height will be 3 ways such as;</p><ul><li>use 1 height Lego x 4</li><li>use 1 height Lego x 1 and 3 height Lego x 1</li><li>use 4 height Lego x 1</li></ul><h3>How to approach</h3><p>First of all, I like Lego. Yeah This problem makes me feel good!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/164/1*ynjdSWnQHl5vMIFVS5szwg.png" /></figure><p>Have a coffee and move next. <br>If you feel that you might see a similar problem like this one, Yes, this problem is not only about Lego, but can be modified as “Ways to step up stairs”, “Pay money using coins (Quarter, Dime, Nickel and Penny)” or etc.</p><p>It can be solved by using recursion manner and dynamic programming. To explain that I use the most intuitive way, brute force.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/396/1*uOTOCftSXKEcVVPFypCvXg.png" /></figure><p>Let’s think the way to build up Lego towel using only one peace of Lego. Using 1 height Lego, there is only one way to build 1 height towel, 2 height towel, … and 10 height towel. So write it down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*LxLa6ow95nu8kZ0sRSM-KA.png" /></figure><p>Do the same thing for the all. Yes. Brute force!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*r1I2sR_Qyo1xBEV4uBasPQ.png" /></figure><p>Now we did it all. Okay. Calm down and think it how it works.</p><p>Let’s move back to first process which using only 1 height Lego peace. <br>For the 10 height towel using 1 height Lego, the way is like this;</p><ul><li>1 height Lego x 10</li></ul><p>Now, we have another Lego peace which is 3 height Lego. Let’s do the same process. Up to 2 height towel, there is no changes because nothing I can do using 3 height Lego to build to 2 height towel. But after 3 height, we can you a new peace!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*mx8l_fji8Ip8nhr4XkUkzQ.png" /></figure><p>Let’s pick up a sample about 6 height towel;</p><ul><li>1 height Lego x 6</li><li>1 height Lego x 3 and 3 height Lego x 1</li><li>3 height Lego x 2</li></ul><p>And it could be changed to like this;</p><ul><li>ways to build up 6 height towel using 1 height Lego + ways to build up 3 height towel using 1 and 3 height Lego</li></ul><p>Let’s check on the sheet. For the first sentence, we can get a number from red circle and for the next sentence, we can achieve the number from the blue circle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/1*Sg3m2o5AngYKNL3cxD18nw.png" /></figure><p>It is obvious that there is only one way for the red circle. Then how can blue circle be two?</p><p>For the 3 height towel, the ways are like this;</p><ul><li>1 height Lego x 3</li><li>3 height Lego x 1</li></ul><p>And it also could be changed to like this;</p><ul><li>ways to build up 3 height towel using 1 height Lego + ways to build up 0 height towel using 1 and 3 height Lego</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*wLTziYYC7X4unipxQQWVpg.png" /></figure><p>You may notice that the number of ways for the zero height is one not zero. The way to build zero height towel is just do nothing which I counted as one way.</p><p>Now, when all circles put together, there is some patterns shown up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*kuFGHstwJC8En-bMTkgjJA.png" /></figure><p>When I describe it as a word;</p><ul><li>Get ways to build up N height towel using up to X th Lego peace = get ways to build up N height towel using up to X - 1 th Lego peace + get ways to build up N - X th Lego heith towel using up to X th Lego peace.</li></ul><p>And it could be changed as sudo code;</p><ul><li>waysToBuildTowel(targetHeight, currentLego) = waysToBuildTowel(targetHeight, prevLego) + waysToBuildTowel(targetHeight - prevLegoHeight, currentLego)</li></ul><p>Using above pattern, let’s fill up all fields! Then we can find the answer of this problem, which is 11.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*J7lWTdRxldnqhTuvzDhmGw.png" /></figure><h3>Let’s Coding: Swift Time</h3><p>First of all, let’s define variables.</p><pre>let legos: [Int] = [1, 3, 4, 6]</pre><pre>let totalHeight: Int = 10</pre><pre>var map: [[Int]] = Array&lt;Array&lt;Int&gt;&gt;(repeating: Array&lt;Int&gt;(repeating: 0, count: totalHeight + 1), count: legos.count)</pre><p>The “map” variable is for caching results. The second array’s size is added 1 more than total height because height will be started from zero and set all value to zero as a default.</p><p>Then the main code is like that;</p><pre>func waysToReach(toTargetHeight targetHeight: Int) -&gt; Int {</pre><pre>  for legoIndex in 0..&lt;legos.count {<br>    let lego: Int = legos[legoIndex]</pre><pre>      for height in lego…targetHeight {<br>        let ways = waysToReach(toTargetHeight: height, withLegoIndex: legoIndex)</pre><pre>        if map[legoIndex][height] == 0 {<br>          map[legoIndex][height] = ways<br>        }<br>      }<br>    }</pre><pre>  return map[legos.count — 1][targetHeight]<br>}</pre><p>In the inner for loop, height starts from current lego’s height not from zero. This is because it always has same result with previous result building N height towel using higher peace of Lego. So the red area in below is not needed to be calculated again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/965/1*cq-s9m1xlENJSgi1-PEDDw.png" /></figure><p>The recursively run method looks like that;</p><pre>func waysToReach(toTargetHeight height: Int, withLegoIndex legoIndex: Int) -&gt; Int {<br>  if legoIndex &lt; 0 || height &lt; 0 {<br>    return 0<br>  }<br> <br>  if height == 0 {<br>    return 1<br>  }<br> <br>  if map[legoIndex][height] != 0 {<br>    return map[legoIndex][height]<br>  }<br> <br>  return waysToReach(toTargetHeight: height, withLegoIndex: legoIndex — 1) + waysToReach(toTargetHeight: height — legos[legoIndex], withLegoIndex: legoIndex)</pre><pre>}</pre><p>This method is similar to Pibonacci’s recursion method. It recursively look into itself until cached data is found or the height reaches to zero.</p><h3>Final Thoughts</h3><p>This algorithm problem is a bit complicated when I tried to solve from the scratch. It would have been solved easier if the difference of Lego’s height is 1 for each; simply I could use the solution of “Pibonacci number”.</p><p>You can download the sample code from github;</p><ul><li><a href="https://github.com/ahimahas/WhyNotAlgorithmInSwift/tree/master/RealProblems/Lego%20Problem">https://github.com/ahimahas/WhyNotAlgorithmInSwift/tree/master/RealProblems/Lego%20Problem</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d58c7c809556" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS Tests working with Objective-C and Swift class together]]></title>
            <link>https://medium.com/if-let-swift-programming/ios-tests-working-with-objective-c-and-swift-class-together-aaf40f91a27c?source=rss-36c8b1184023------2</link>
            <guid isPermaLink="false">https://medium.com/p/aaf40f91a27c</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[unittest]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[MonGuNare]]></dc:creator>
            <pubDate>Thu, 26 Jan 2017 06:02:31 GMT</pubDate>
            <atom:updated>2017-01-26T06:02:31.184Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Swift is awesome. Yes I know. But still many companies are using Objective-C and starting to add new Swift code in it. Our generous Xcode tool supports to combine these two different style codes. It is only needed a small, no frankly, complicated setting.<br>The situation is still fine when my concern is only main target project. However once I tried to use existing Objective-C class inside of Swift test class, I stuck in the middle.<br>Here is solutions that how to use Objective-C and Swift class together for each situations.</p><h3>Four different situations using Objective-C and Swift class</h3><ul><li><strong>using Objective-C class in Objective-C unit test class</strong><br>This is common case that you can simply import objc class in a unit test class. Easy peasy!</li></ul><pre>#import &lt;XCTest/XCTest.h&gt;<br>#import “ObjcClass.h”</pre><pre><a href="http://twitter.com/implementation">@implementation</a> SampleProjectForTestingTests</pre><pre>- (void)testExample {<br>  ObjcClass *aClass = [ObjcClass new];<br>  [aClass doSomething];<br>}</pre><pre><a href="http://twitter.com/end">@end</a></pre><ul><li><strong>using Swift class in Swift unit test class</strong><br>There are two ways that you can use a Swift class in your Swift test class. First way is, select Swift class file and set “Target Membership” for Tests.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/1*GbByhZ55X0IXwak7FkJUdQ.png" /></figure><p>But think though. What if you have a bunch of files needed to be added? It won’t be compiled not only adding all classes directly used in in the test class but also classes that are imported by that class.</p><p>Easier, and more effective way is using “testable” attribute.<br>The definition of “testable” attribute in Apple document is like that;</p><blockquote>testable<br>Apply this attribute to import declarations for modules compiled with testing enabled to access any entities marked with the internal access-level modifier as if they were declared with the public access-level modifier. Tests can also access classes and class members that are marked with the internal or public access-level modifier as if they were declared with the open access-level modifier.</blockquote><p>Now, code will looks like below,</p><pre><br>import XCTest<br><a href="http://twitter.com/testable">@testable</a> import SampleProjectForTesting</pre><pre>class SampleProjectForTestingTests: XCTestCase {<br>  func testExample() {<br>    let aClass: SwiftClass = SwiftClass()<br>    aClass.doSomething()<br>  }<br>}</pre><ul><li><strong>using Objective-C class in Swift unit test class</strong><br>You may find a header file, “YourProject-Bridging-header.h” in you project hierarchy. It is automatically generated by Xcode whenever you create Swift class file in Objc project or vise versa. <br> <br>Open “YourProject-Bridging-header.h” and import any class that you want to handle in Swift class.</li></ul><pre>//<br>// Use this file to import your target’s public headers that you would like to expose to Swift.<br>//</pre><pre>#import “ObjcClass.h”</pre><p>Once you register classes, Xcode will convert those classes internally when Xcode build time. Dark magic!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*9niUoIAGoq-fUHYYBnYyPA.gif" /></figure><p>Now, without specifying any key words, you can use those Objc classes in Swift class in your project and test file.</p><pre><br>import XCTest<br><a href="http://twitter.com/testable">@testable</a> import SampleProjectForTesting</pre><pre>class SampleProjectForTestingTests: XCTestCase { <br>  func testExample() {<br>    let aClass: SwiftClass = SwiftClass()<br>    aClass.doSomething()<br> <br>    let aObjcClass: ObjcClass = ObjcClass()<br>    aObjcClass.doSomething()<br>  }<br>}</pre><ul><li><strong>using Swift class in Objective-C unit test file</strong><br>Objective-C class is converted to Swift class by Xcode’s dark magic, but how about the opposite way? In fact, Swift class through using “objc” keyword and inheriting “NSObject” is also converted to Objc class by our mighty Xcode builder. The Swift class looks like that;</li></ul><pre>import Foundation<br><a href="http://twitter.com/objc">@objc</a> class SwiftClass: NSObject {<br>  func doSomething() {<br> <br>  }<br>}</pre><p>And hidden Objc header file which contains all Swift classes definition in it is also created at the build time so that the other Objc class can use Swift class. The header file’s name is “YourProject-Swift.h” which is invisible but still can be accessed manually.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*E7a81BBrAOB-HUAAnLmdbQ.png" /></figure><p>Now, you got a clue. Through importing this header file, you can access Swift class in Objc class. It is perfectly work within your project but once you try to apply same process to unit test file, boom! you will meet an error like that;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*28R-49YWOSrDOaD8MHMYTQ.png" /></figure><p>The reason why your test class couldn’t find the Swift classes is that the header file is an auto-generated file which only existed in the build directory, and the test target doesn’t see the main target as a framework module to be imported.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/246/1*1rspNYe5c2Bz0Ysb-bGVcw.png" /></figure><p>To solve this frustrated issue, adding the folder containing the main target’s auto-generated header file to the test target’s header search paths. Go to test target &gt; Build Settings &gt; Header Search Paths, and add $CONFIGURATION_TEMP_DIR/YourProject.build/DerivedSources in it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OmeF0jLBR-fES_ueXHuIpA.png" /></figure><p>Go back to your test class, do clean up and build again. Now the red alert has gone and you can access Swift class freely!</p><h3>Conclusion</h3><p>Connecting Objective-C and Swift class in unit test still uncomfortable that developer has to set a bunch of settings and follow certain processes. I strongly believe that Xcode will support those chore works in some later version so that it will be linked each other clicking just one-button option. :)</p><p>Here is reference source code;<br><a href="https://github.com/ahimahas/TestsBetweenObjcAndSwift">https://github.com/ahimahas/TestsBetweenObjcAndSwift</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aaf40f91a27c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/if-let-swift-programming/ios-tests-working-with-objective-c-and-swift-class-together-aaf40f91a27c">iOS Tests working with Objective-C and Swift class together</a> was originally published in <a href="https://medium.com/if-let-swift-programming">If let swift = Programming!</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>