{"id":384,"date":"2011-10-20T07:05:15","date_gmt":"2011-10-20T07:05:15","guid":{"rendered":"http:\/\/www.blogs.abeazam.com\/dev\/?p=384"},"modified":"2011-10-20T07:05:15","modified_gmt":"2011-10-20T07:05:15","slug":"no-more-logs-using-breakpoints-in-xcode","status":"publish","type":"post","link":"http:\/\/www.blogs.abeazam.com\/dev\/2011\/10\/no-more-logs-using-breakpoints-in-xcode\/","title":{"rendered":"NO MORE LOGS!!!!! (Using breakpoints in xCode)"},"content":{"rendered":"<p>I cant count the number of times I have compiled an app and found my self lost in logs. This is not not just an xCode issue I have come across this in every language\/IDE I have used. For some reason we like to log it and leave it.<\/p>\n<p>We give our selves all maner of excuses for not removing log\u00a0statements. Whether its needed so every developer\u00a0on the project knows whats happening or simply not\u00a0\u00a0having time to go back and remove them. We do end up\u00a0accumulating\u00a0a lot of logs over the span of a project.<\/p>\n<p>Dont get me wrong a well placed log can make\u00a0debugging\u00a0a problem much easier. There are other ways to do it though. Using breakpoints in xCode rocks logging as well as giving you a few extra perks.<\/p>\n<p>Lets start with right click and editing a breakpoint to see:<\/p>\n<p><a href=\"http:\/\/www.blogs.abeazam.com\/dev\/wp-content\/uploads\/2011\/10\/RootEdit.jpg\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-389\" title=\"break point edit\" src=\"http:\/\/www.blogs.abeazam.com\/dev\/wp-content\/uploads\/2011\/10\/RootEdit.jpg\" alt=\"\" width=\"512\" height=\"149\" \/><\/a><\/p>\n<p>Now this is one of my favorite tools in xCode. Off that bat it allows for conditional breaks. The above break for example will not break unless the\u00a0variable\u00a0newPos is equal to 42. This can help with keeping an eye on a value to make sure it does not act in\u00a0appropriately\u00a0and if\u00a0does\u00a0you will get the break. How ever clicking the actions text above marked with a blue arrow will\u00a0unleash\u00a0the true power behind the xCode breakpoint.<\/p>\n<p><a href=\"http:\/\/www.blogs.abeazam.com\/dev\/wp-content\/uploads\/2011\/10\/action-Select-edit.jpg\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-386\" title=\"Action Select edit\" src=\"http:\/\/www.blogs.abeazam.com\/dev\/wp-content\/uploads\/2011\/10\/action-Select-edit.jpg\" alt=\"\" width=\"513\" height=\"197\" \/><\/a><\/p>\n<p>Out of the 5 above options I only use two with any\u00a0frequency. \u00a0The &#8220;Debugger\u00a0Command&#8221; which will allow you to log, inject calls and set\u00a0variables. \u00a0The &#8220;Log Message&#8221; more for english messages and keeping track of the\u00a0frequency\u00a0of code used. \u00a0OH ya one more thing\u00a0&#8220;Log Message&#8221; supports text to speech.<\/p>\n<p><strong>Lets start with the &#8220;Debugger\u00a0Command&#8221;:<\/strong><\/p>\n<p><a href=\"http:\/\/www.blogs.abeazam.com\/dev\/wp-content\/uploads\/2011\/10\/printObjectEdit.jpg\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-388\" title=\"printObjectEdit\" src=\"http:\/\/www.blogs.abeazam.com\/dev\/wp-content\/uploads\/2011\/10\/printObjectEdit.jpg\" alt=\"\" width=\"510\" height=\"198\" \/><\/a><\/p>\n<p>&#8220;po someObject&#8221; looks like it would print the description of someObject. Thats not all though. Dont forget the conditional above it &#8220;newPos == 42&#8221;. Combine the two and you will only print someObject to the consol when\u00a0newPos is equal to 42. If you uncheck\u00a0the bottom\u00a0checkbox &#8220;Option&#8221; it will log the description with out breaking.<\/p>\n<p>You can also use the\u00a0field\u00a0to more than log. Be careful \u00a0though as this can easily cause problems if you forget to remove or disable the break.<\/p>\n<p>The command could be to call a function or set a\u00a0variable\u00a0like this: &#8220;newPos = 13&#8221;<\/p>\n<p>If you were to forget to remove a command like that it could burn a lot of time\u00a0tracking\u00a0it down.<\/p>\n<p><strong>Moving onto the &#8220;Log Message&#8221;:\u00a0<\/strong><\/p>\n<p><a href=\"http:\/\/www.blogs.abeazam.com\/dev\/wp-content\/uploads\/2011\/10\/logEdit.jpg\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-387\" title=\"Log Edit\" src=\"http:\/\/www.blogs.abeazam.com\/dev\/wp-content\/uploads\/2011\/10\/logEdit.jpg\" alt=\"\" width=\"510\" height=\"251\" \/><\/a><\/p>\n<p>This obviously prints a message. If you look under text\u00a0field\u00a0to the right you can see a key. Above I used the %H which will be replaced by the number of times the break has been hit. Also if you\u00a0remember\u00a0to uncheck the Option at the botton it wont break but will simply log at the break.<\/p>\n<p>You also get the option to have the message read out loud. This is\u00a0useful\u00a0if you\u00a0have\u00a0to keep your attention on the app and cant keep an eye on the logs.<\/p>\n<p>This covers the two basic\u00a0implementations. What if you need to do more than one thing like run\u00a0multiple\u00a0commands?<\/p>\n<p><strong>Stacking Actions:<\/strong><\/p>\n<p><a href=\"http:\/\/www.blogs.abeazam.com\/dev\/wp-content\/uploads\/2011\/10\/double2.jpg\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-390\" title=\"Stacking Actions\" src=\"http:\/\/www.blogs.abeazam.com\/dev\/wp-content\/uploads\/2011\/10\/double2.jpg\" alt=\"\" width=\"507\" height=\"318\" \/><\/a><\/p>\n<p>Pressing the + button as indicated above by the orange arrow. That would be the top arrow as the bottom one is yellow. (my color selection is\u00a0rubbish) You get\u00a0another\u00a0action that runs at the same time. \u00a0You can run any number of commands in the one break which can provide very rich loggin and\u00a0debugging\u00a0capabilities.<\/p>\n<p><strong>Managing\u00a0your breaks:<\/strong><\/p>\n<p><a href=\"http:\/\/www.blogs.abeazam.com\/dev\/wp-content\/uploads\/2011\/10\/mangEdit.jpg\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-391\" title=\"mangEdit\" src=\"http:\/\/www.blogs.abeazam.com\/dev\/wp-content\/uploads\/2011\/10\/mangEdit.jpg\" alt=\"\" width=\"516\" height=\"286\" \/><\/a><\/p>\n<p>Toggling\u00a0the button indicated by the green arrow you can enable or disable all your breaks in one go.<\/p>\n<p>The only way to manage large numbers of logs is to search nslog and edit the file. This will\u00a0cause\u00a0the file to have been touched wich will obviously need versioning.\u00a0Fortunately\u00a0if you open the break window indicated by the blue arrow above. A list of all your breaks and their locations can be found.<\/p>\n<p>Each break can be enabled or disabled by pressing the break symbol to its right as indicated by the purple arrow above.<\/p>\n<p><strong>Sharing\u00a0Breaks:<\/strong><\/p>\n<p>Most projects are version\u00a0controlled\u00a0with\u00a0either\u00a0SVN or GIT. In all of my projects we make sure to ignore the personal settings folder in the\u00a0.xcodeproj file. Which\u00a0incidentally\u00a0is just a folder. You can right click &#8220;Show its Contents&#8221;. In there you will find a folder called &#8220;xcuserdata&#8221; this will contain the personal profile for each\u00a0developer. It will contain\u00a0\u00a0the\u00a0developer\u00a0specific\u00a0xCode settings like layout. This folder is ignored and never\u00a0committed\u00a0or pushed.<\/p>\n<p>However if you were to share a breakpoint.<\/p>\n<p><a href=\"http:\/\/www.blogs.abeazam.com\/dev\/wp-content\/uploads\/2011\/10\/Share.jpg\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-398\" title=\"Share\" src=\"http:\/\/www.blogs.abeazam.com\/dev\/wp-content\/uploads\/2011\/10\/Share.jpg\" alt=\"\" width=\"444\" height=\"240\" \/><\/a><\/p>\n<p>Right click a break point and select share as seen above. It creates a new folder in the project file. The &#8220;xcshareddata&#8221; can then be used to share break points with other\u00a0developers\u00a0. Say you had a\u00a0particularly\u00a0nasty bug and set up some\u00a0particularly\u00a0elaborate\u00a0breaks they would be easily passed on to\u00a0another\u00a0developer\u00a0who could help you or continue on the work.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I cant count the number of times I have compiled an app and found my self lost in logs. This is not not just an xCode issue I have come across this in every language\/IDE I have used. For some reason we like to log it and leave it. We give our selves all maner [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[24,25,26,36,37],"tags":[61],"_links":{"self":[{"href":"http:\/\/www.blogs.abeazam.com\/dev\/wp-json\/wp\/v2\/posts\/384"}],"collection":[{"href":"http:\/\/www.blogs.abeazam.com\/dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.blogs.abeazam.com\/dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.blogs.abeazam.com\/dev\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.blogs.abeazam.com\/dev\/wp-json\/wp\/v2\/comments?post=384"}],"version-history":[{"count":0,"href":"http:\/\/www.blogs.abeazam.com\/dev\/wp-json\/wp\/v2\/posts\/384\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.blogs.abeazam.com\/dev\/wp-json\/wp\/v2\/media?parent=384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.blogs.abeazam.com\/dev\/wp-json\/wp\/v2\/categories?post=384"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.blogs.abeazam.com\/dev\/wp-json\/wp\/v2\/tags?post=384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}