{"id":4781,"date":"2017-06-14T18:54:30","date_gmt":"2017-06-14T18:54:30","guid":{"rendered":"https:\/\/blog-stg.cheesecakelabs.com\/blog\/breakpoints-debugging-like-pro\/"},"modified":"2022-07-01T17:34:02","modified_gmt":"2022-07-01T17:34:02","slug":"breakpoints-debugging-like-pro","status":"publish","type":"post","link":"https:\/\/blog-stg.cheesecakelabs.com\/br\/breakpoints-debugging-like-pro\/","title":{"rendered":"Breakpoints: Debugging like a Pro"},"content":{"rendered":"<p>When I started as an iOS developer, my biggest problem was with app crashes, that&#8217;s because I really didn&#8217;t know how iOS, Swift, and Objective-C worked.&nbsp;<span style=\"font-weight: 400;\">Back then, I wrote a lot of bad code<\/span>, not worrying about memory usage, memory access, ARC or GCD. That&#8217;s simply because I didn&#8217;t know about that stuff. I was a beginner, for God sakes.<\/p>\n<p>Like most beginners, <a class=\"zem_slink\" title=\"Stack Overflow\" href=\"http:\/\/www.stackoverflow.com\" rel=\"homepage\">Stack Overflow<\/a> <span style=\"font-weight: 400;\">community taught me a lot about \u201cdoing things the right way\u201d.<\/span> <span style=\"font-weight: 400;\">I\u2019ve learned a lot of tricks that helped me improve my work process. In this article, I\u2019ll share some of them about the most important tool used in this learning process: the&nbsp;<\/span><strong>breakpoints<\/strong>!<\/p>\n<p><!--more--><\/p>\n<p>So, get your shovels and let&#8217;s go dig in \ud83d\ude42<\/p>\n<h1>Breakpoints<\/h1>\n<p><span style=\"font-weight: 400;\">The Xcode Breakpoints is a powerful tool and there is no doubt about it. Its main purpose is to debug code, but what if I say that they can offer more than that? Ok, let\u2019s start with the tricks!<\/span><\/p>\n<h2>Conditioning breakpoints<\/h2>\n<p><span style=\"font-weight: 400;\">Maybe you have already gotten yourself in a situation where your <\/span><i><span style=\"font-weight: 400;\">TableView<\/span><\/i><span style=\"font-weight: 400;\"> is working so well for all users models, but there is a particular one that is causing some trouble. To debug this entity, the first thing that you may think is: \u201c<\/span><i><span style=\"font-weight: 400;\">Ok, I will put a breakpoint on cell loading and see what is going on<\/span><\/i><span style=\"font-weight: 400;\">\u201d. But for each cell, even the working ones, your breakpoint will be activated and you will have to skip it until you&nbsp;have reached one that you want to debug.<\/span><\/p>\n<p><a href=\"https:\/\/media.giphy.com\/media\/12XMGIWtrHBl5e\/giphy.gif\"><img decoding=\"async\" class=\" wp-image-4608 aligncenter\" src=\"https:\/\/media.giphy.com\/media\/12XMGIWtrHBl5e\/giphy.gif\" alt=\"The Office TV show gif, saying &quot;please god, no&quot;\" width=\"467\" height=\"381\"><\/a><\/p>\n<p>To solve this issue, you can go ahead and give your breakpoint a condition to stop, like I did for the user named \u201cCharlinho\u201d.<br \/>\n<img decoding=\"async\" class=\"aligncenter wp-image-4763 size-full\" src=\"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2017\/06\/3.png\" alt=\"A conditional breakpoint screenshot\" width=\"476\" height=\"146\"><\/p>\n<h2>Symbolic Breakpoints<\/h2>\n<blockquote><p><em>\u201cRelax, I will use a pod, that should save us some work.\u201d<\/em><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">Who never said that? But using a pod or an external library you are importing external code into your project and the way it was written might be unknown. Let&#8217;s say that you tracked an error occurring on some function on a pod, but you don&#8217;t know where the function is in the code. Just take a breath, keep it cool\u2026 you have <b><i>Symbolic Breakpoints<\/i><\/b><i>.<\/i><\/span><\/p>\n<p><span style=\"font-weight: 400;\">These breakpoints are activated when a previously declared <\/span><i><span style=\"font-weight: 400;\">symbol<\/span><\/i><span style=\"font-weight: 400;\"> is called. This <\/span><i><span style=\"font-weight: 400;\">symbol<\/span><\/i><span style=\"font-weight: 400;\"> can be any free functions, instance and class methods, whether in your own classes or not. So to add a breakpoint in a function, no matter who&#8217;s calling it, you just have to add a <\/span><i><span style=\"font-weight: 400;\">Symbolic Breakpoint<\/span><\/i><span style=\"font-weight: 400;\"> observing the function that you want to debug. In my sample below, I observe the method <\/span><i><span style=\"font-weight: 400;\">UIViewAlertForUnsatisfiableConstraints<\/span><\/i><span style=\"font-weight: 400;\">. This method will be called every time that Xcode finds some <\/span><i><span style=\"font-weight: 400;\">Autolayout<\/span><\/i><span style=\"font-weight: 400;\"> issue. You can see a more advanced tip on<\/span><span style=\"font-weight: 400;\">&nbsp;<a href=\"http:\/\/nshint.io\/blog\/2015\/08\/17\/autolayout-breakpoints\/\">this post<\/a><\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-4762 size-full\" src=\"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2017\/06\/2.png\" alt=\"A Symbolic breakpoint option screenshot\" width=\"476\" height=\"191\" srcset=\"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2017\/06\/2.png 476w, https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2017\/06\/2-380x152.png 380w\" sizes=\"(max-width: 476px) 100vw, 476px\" \/><\/p>\n<h2>Customizing breakpoints<\/h2>\n<p><span style=\"font-weight: 400;\">Like I said previously, breakpoints are a powerful tool. Did you know that you can even add custom actions on a breakpoint? Yeah, you can do that! You can perform an AppleScript, Capture CPU Frame, use LLDB (Low-level Debugger) commands and even shell commands.<\/span><\/p>\n<figure id=\"attachment_4600\" aria-describedby=\"caption-attachment-4600\" style=\"width: 459px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-4600 size-full\" src=\"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2017\/05\/4.png\" alt=\"\" width=\"459\" height=\"176\"><figcaption id=\"caption-attachment-4600\" class=\"wp-caption-text\">To do that you can simply click on the right button and select <em>edit breakpoint<\/em><\/figcaption><\/figure>\n<h3>OK, you could be thinking: \u201cCool! But why?\u201d<\/h3>\n<p><span style=\"font-weight: 400;\">I&#8217;ll give you a good use case that will improve your work. The most common feature on an app is the Login, and sometimes testing it is a little bit boring. Having to type the user and password multiple times \u2013 if you are using an admin and a normal account \u2013 could make the process a little nasty. The common approach to &#8220;automate&#8221; the login screen is to create a <\/span><i><span style=\"font-weight: 400;\">mocked<\/span><\/i><span style=\"font-weight: 400;\"> entity and use it into an <\/span><i><span style=\"font-weight: 400;\">if debug<\/span><\/i><span style=\"font-weight: 400;\"> clause. Something like this:<\/span><\/p>\n<pre><code class=\"language-swift\">\nstruct TestCredentials {\n    static let username = \"robo1\"\n    static let password = \"xxxxxx\"\n}\n\nprivate func fillDebugData() {\n     self.userNameTxtField.text = TestCredentials.username\n     self.passwordTxtField.text = TestCredentials.password\n}\n<\/code><\/pre>\n<h3>But hey, you can use breakpoints to make things a little easier!<\/h3>\n<p><span style=\"font-weight: 400;\">Go into your login screen, add a breakpoint and then add two LLDB expressions that will fill your user and password. Like I did in the example below:<\/span><\/p>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-4764 size-full\" src=\"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2017\/06\/6.png\" alt=\"A Custom breakpoint executing express commands. \" width=\"485\" height=\"258\"><\/p>\n<p><span style=\"font-weight: 400;\">With that in mind, you can add two breakpoints with different credentials. To switch between them, you just have to enable\/disable the one that you want to test. There is no rebuild required once you are changing the user on the fly. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Pretty cool, huh?<\/span><\/p>\n<h1>COMBO BREAKER!<\/h1>\n<p><span style=\"font-weight: 400;\">The WWDC 2017 was happening while I was writing this article. They launched some cool stuff like the new Xcode 9, for example.&nbsp;<\/span><span style=\"font-weight: 400;\">If you want to know what is new with debug tools on Xcode 9, I strongly recommend watching the<\/span><a href=\"https:\/\/developer.apple.com\/videos\/play\/wwdc2017\/404\/\"> <span style=\"font-weight: 400;\">Session 404<\/span><\/a><span style=\"font-weight: 400;\">. <\/span><\/p>\n<p><a href=\"https:\/\/media.giphy.com\/media\/l41m0ysPANVkPS8JW\/giphy.gif\"><img decoding=\"async\" class=\"size-full wp-image-4608 aligncenter\" src=\"https:\/\/media.giphy.com\/media\/l41m0ysPANVkPS8JW\/giphy.gif\" alt=\"\"><\/a><\/p>\n<p><span style=\"font-weight: 400;\">That&#8217;s all folks! Now you know the basics Breakpoint tricks that helped me a lot when I was a beginner. Are there any cool tricks that I didn&#8217;t mention? Do you have any good ones too? Please feel free to share them in the comments!<\/span><\/p>\n<p><span style=\"font-weight: 400;\">See ya!<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I started as an iOS developer, my biggest problem was with app crashes, that&#8217;s because I really didn&#8217;t know how iOS, Swift, and Objective-C worked.&nbsp;Back then, I wrote a lot of bad code, not worrying about memory usage, memory access, ARC or GCD. That&#8217;s simply because I didn&#8217;t know about that stuff. I was [&hellip;]<\/p>\n","protected":false},"author":65,"featured_media":9131,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[471],"tags":[1146,1156],"class_list":["post-4781","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-engenharia","tag-tag-ios-br","tag-tag-mobile-br"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Breakpoints: Debugging like a Pro | Cheesecake Labs<\/title>\n<meta name=\"description\" content=\"How to use breakpoints to improve your work as an iOS developer bringing you some tips, automating your daily developer tasks.\" \/>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"pt_BR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Breakpoints: Debugging like a Pro | Cheesecake Labs\" \/>\n<meta property=\"og:description\" content=\"How to use breakpoints to improve your work as an iOS developer bringing you some tips, automating your daily developer tasks.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog-stg.cheesecakelabs.com\/br\/breakpoints-debugging-like-pro\/\" \/>\n<meta property=\"og:site_name\" content=\"Cheesecake Labs\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/cheesecakelabs\" \/>\n<meta property=\"article:published_time\" content=\"2017-06-14T18:54:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-01T17:34:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2017\/06\/Banner_xcode3.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2000\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Cheesecake Labs\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@cheesecakelabs\" \/>\n<meta name=\"twitter:site\" content=\"@cheesecakelabs\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. tempo de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/breakpoints-debugging-like-pro\/\",\"url\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/breakpoints-debugging-like-pro\/\",\"name\":\"Breakpoints: Debugging like a Pro | Cheesecake Labs\",\"isPartOf\":{\"@id\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/#website\"},\"datePublished\":\"2017-06-14T18:54:30+00:00\",\"dateModified\":\"2022-07-01T17:34:02+00:00\",\"author\":{\"@type\":\"person\",\"name\":\"Alan Ostanik\"},\"description\":\"How to use breakpoints to improve your work as an iOS developer bringing you some tips, automating your daily developer tasks.\",\"breadcrumb\":{\"@id\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/breakpoints-debugging-like-pro\/#breadcrumb\"},\"inLanguage\":\"pt-BR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog-stg.cheesecakelabs.com\/br\/breakpoints-debugging-like-pro\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/breakpoints-debugging-like-pro\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Breakpoints: Debugging like a Pro\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/#website\",\"url\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/\",\"name\":\"Cheesecake Labs\",\"description\":\"Empresa de desenvolvimento e design de aplicativos mobile &amp; web que est\u00e1 reinventando o desenvolvimento de produtos com times remotos. N\u00f3s desenvolvemos aplicativos iOS, Android e aplica\u00e7\u00f5es Web com as melhores empresas dos EUA, do Brasil e do mundo.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pt-BR\"},{\"@type\":\"Person\",\"name\":\"Alan Ostanik\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-BR\",\"@id\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2016\/11\/alan3-300x300.jpg\",\"contentUrl\":\"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2016\/11\/alan3-300x300.jpg\",\"caption\":\"Alan Ostanik\"},\"description\":\"10 years of experience in Marketing and Sales in the Technology sector. My main purpose is help, support and structure efficient operations and also develop independent and multidisciplinary teams.\",\"url\":\"https:\/\/blog-stg.cheesecakelabs.com\/br\/\/autor\/alan-ostanik\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Breakpoints: Debugging like a Pro | Cheesecake Labs","description":"How to use breakpoints to improve your work as an iOS developer bringing you some tips, automating your daily developer tasks.","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"pt_BR","og_type":"article","og_title":"Breakpoints: Debugging like a Pro | Cheesecake Labs","og_description":"How to use breakpoints to improve your work as an iOS developer bringing you some tips, automating your daily developer tasks.","og_url":"https:\/\/blog-stg.cheesecakelabs.com\/br\/breakpoints-debugging-like-pro\/","og_site_name":"Cheesecake Labs","article_publisher":"https:\/\/www.facebook.com\/cheesecakelabs","article_published_time":"2017-06-14T18:54:30+00:00","article_modified_time":"2022-07-01T17:34:02+00:00","og_image":[{"width":2000,"height":720,"url":"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2017\/06\/Banner_xcode3.png","type":"image\/png"}],"author":"Cheesecake Labs","twitter_card":"summary_large_image","twitter_creator":"@cheesecakelabs","twitter_site":"@cheesecakelabs","twitter_misc":{"Escrito por":null,"Est. tempo de leitura":"4 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/blog-stg.cheesecakelabs.com\/br\/breakpoints-debugging-like-pro\/","url":"https:\/\/blog-stg.cheesecakelabs.com\/br\/breakpoints-debugging-like-pro\/","name":"Breakpoints: Debugging like a Pro | Cheesecake Labs","isPartOf":{"@id":"https:\/\/blog-stg.cheesecakelabs.com\/br\/#website"},"datePublished":"2017-06-14T18:54:30+00:00","dateModified":"2022-07-01T17:34:02+00:00","author":{"@type":"person","name":"Alan Ostanik"},"description":"How to use breakpoints to improve your work as an iOS developer bringing you some tips, automating your daily developer tasks.","breadcrumb":{"@id":"https:\/\/blog-stg.cheesecakelabs.com\/br\/breakpoints-debugging-like-pro\/#breadcrumb"},"inLanguage":"pt-BR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog-stg.cheesecakelabs.com\/br\/breakpoints-debugging-like-pro\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog-stg.cheesecakelabs.com\/br\/breakpoints-debugging-like-pro\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog-stg.cheesecakelabs.com\/br\/"},{"@type":"ListItem","position":2,"name":"Breakpoints: Debugging like a Pro"}]},{"@type":"WebSite","@id":"https:\/\/blog-stg.cheesecakelabs.com\/br\/#website","url":"https:\/\/blog-stg.cheesecakelabs.com\/br\/","name":"Cheesecake Labs","description":"Empresa de desenvolvimento e design de aplicativos mobile &amp; web que est\u00e1 reinventando o desenvolvimento de produtos com times remotos. N\u00f3s desenvolvemos aplicativos iOS, Android e aplica\u00e7\u00f5es Web com as melhores empresas dos EUA, do Brasil e do mundo.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog-stg.cheesecakelabs.com\/br\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pt-BR"},{"@type":"Person","name":"Alan Ostanik","image":{"@type":"ImageObject","inLanguage":"pt-BR","@id":"https:\/\/blog-stg.cheesecakelabs.com\/br\/#\/schema\/person\/image\/","url":"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2016\/11\/alan3-300x300.jpg","contentUrl":"https:\/\/ckl-website-static.s3.amazonaws.com\/wp-content\/uploads\/2016\/11\/alan3-300x300.jpg","caption":"Alan Ostanik"},"description":"10 years of experience in Marketing and Sales in the Technology sector. My main purpose is help, support and structure efficient operations and also develop independent and multidisciplinary teams.","url":"https:\/\/blog-stg.cheesecakelabs.com\/br\/\/autor\/alan-ostanik\/"}]}},"_links":{"self":[{"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/posts\/4781","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/comments?post=4781"}],"version-history":[{"count":1,"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/posts\/4781\/revisions"}],"predecessor-version":[{"id":10287,"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/posts\/4781\/revisions\/10287"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/media\/9131"}],"wp:attachment":[{"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/media?parent=4781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/categories?post=4781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog-stg.cheesecakelabs.com\/br\/wp-json\/wp\/v2\/tags?post=4781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}