{"id":15371,"date":"2014-11-20T11:17:13","date_gmt":"2014-11-20T16:17:13","guid":{"rendered":"http:\/\/blog.xamarin.com\/?p=15371"},"modified":"2014-11-20T11:17:13","modified_gmt":"2014-11-20T16:17:13","slug":"real-time-code-iteration-with-sketches","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/xamarin\/real-time-code-iteration-with-sketches\/","title":{"rendered":"Real-Time Code Iteration with Sketches"},"content":{"rendered":"<p>\t\t\t\t<strong>Sketches<\/strong> are a powerful new feature that we announced as a preview release at Xamarin Evolve in October. With Sketches, developers can iterate on code within Xamarin Studio and immediately see the results, without having to go through a full build and deploy cycle.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/Sketches.png\" alt=\"Sketches\" width=\"1024\" height=\"651\" class=\"aligncenter size-full wp-image-15390\" \/><\/p>\n<p>A sketch is a file that stands alone or can be contained in a project, making it easy to move experimental code from a sketch into a code base. In some ways, it\u2019s the immediate window on steroids.<\/p>\n<p>For example, say you want to inspect the result of some code such as :<\/p>\n<pre class=\"lang:csharp decode:true\">\nvar x = 1;\nvar y = 2;\nvar z = x + y;\n<\/pre>\n<p>Sketches use a REPL (read\u2013eval\u2013print loop) that evaluates the code and displays the results:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-15432\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/simple_results.png\" alt=\"sketch results\" width=\"760\" height=\"375\" \/><\/p>\n<h2>Viewing Output<\/h2>\n<p>There are visualizers for the output built in, too. For instance, a color is displayed as shown below:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-15434\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/color_viz.png\" alt=\"color visualizer\" width=\"864\" height=\"270\" \/><\/p>\n<p>You can even pin the results to the output area:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-15436\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/color_output.png\" alt=\"color output\" width=\"404\" height=\"379\" \/><\/p>\n<p>Additionally, the output can display graphs of data:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-15438\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/graph.png\" alt=\"output graph\" width=\"900\" height=\"373\" \/><\/p>\n<h2>Visualizing Images<\/h2>\n<p>The visualizer can display other types of data, too, such as images:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-15440\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/image_viz.png\" alt=\"image visualization\" width=\"966\" height=\"321\" \/><\/p>\n<h3>Graphics Code<\/h3>\n<p>Having image support is nice, because it allows you to write arbitrary graphics code in a sketch and render it to an image. For example, here&#8217;s a code snippet from a <a href=\"http:\/\/mikebluestein.wordpress.com\/2010\/02\/21\/drawing-with-coregraphics-in-monotouch-2\/\" title=\"Drawing with Core Graphics\" target=\"_blank\">blog post<\/a> I wrote a while back, showing the rendering of some Core Graphics drawing code (updated for the unified API) in an iOS sketch:<\/p>\n<pre class=\"lang:csharp decode:true\">\n\/\/ Sketch your next great idea!\n\nusing UIKit;\nusing Foundation;\nusing CoreGraphics;\n\/\/\nUIGraphics.BeginImageContext (new CGSize (320.0f, 300.0f));\nusing (var gctx = UIGraphics.GetCurrentContext ()){\n\n  gctx.SetLineWidth(4);\n  UIColor.Purple.SetFill ();\n  UIColor.Black.SetStroke ();\n\n  var path = new CGPath ();\n  path.AddLines(new CGPoint[]{\n    new CGPoint(100,200),\n    new CGPoint(160,100),\n    new CGPoint(220,200)});\n  path.CloseSubpath();\n\n  gctx.AddPath(path);\n  gctx.DrawPath(CGPathDrawingMode.FillStroke);\n}\n\nvar image = UIGraphics.GetImageFromCurrentImageContext ();\n\nUIGraphics.EndImageContext ();\n<\/pre>\n<p>This renders a triangle in the sketch, as shown below:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-15446\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/coregraphics_sketch.png\" alt=\"Core Graphics sketch\" width=\"972\" height=\"493\" \/><\/p>\n<h2>Visualizing Views<\/h2>\n<p>Visualizers aren&#8217;t limited to just images. You can display views as well, such as a UIView on iOS or an NSView on OS X. For example, here is an NSBox with a border:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-15442\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/box.png\" alt=\"view visualization\" width=\"997\" height=\"329\" \/><\/p>\n<p>Where sketches start getting even more compelling is when you start using them to modify code running in the iOS simulator and the Xamarin Android Player. For example, here is some Xamarin.Forms code created on the fly in a sketch, running in the Android Player:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-15444\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/forms_sketches.png\" alt=\"forms sketch\" width=\"996\" height=\"488\" \/><\/p>\n<p>To learn more about Sketches, check out the <a href=\"http:\/\/developer.xamarin.com\/guides\/cross-platform\/sketches\/\" title=\"Sketches documentation\" target=\"_blank\">documentation in our developer center<\/a> and the <a href=\"https:\/\/github.com\/xamarin\/sketches\" title=\"Sketches samples\" target=\"_blank\">Sketches&#8217; samples<\/a>. Also see <a href=\"https:\/\/twitter.com\/abock\" title=\"Aaron Bockover\" target=\"_blank\">Aaron Bockover<\/a>&#8216;s great <a href=\"https:\/\/www.youtube.com\/watch?v=v9vEhwomUEY\" title=\"Xamarin Sketches Evolve 2014\" target=\"_blank\">talk from Evolve<\/a>.\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sketches are a powerful new feature that we announced as a preview release at Xamarin Evolve in October. With Sketches, developers can iterate on code within Xamarin Studio and immediately see the results, without having to go through a full build and deploy cycle. A sketch is a file that stands alone or can be [&hellip;]<\/p>\n","protected":false},"author":1932,"featured_media":39167,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[4],"class_list":["post-15371","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developers","tag-xamarin-platform"],"acf":[],"blog_post_summary":"<p>Sketches are a powerful new feature that we announced as a preview release at Xamarin Evolve in October. With Sketches, developers can iterate on code within Xamarin Studio and immediately see the results, without having to go through a full build and deploy cycle. A sketch is a file that stands alone or can be [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/15371","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/users\/1932"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/comments?post=15371"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/15371\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media\/39167"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media?parent=15371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/categories?post=15371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/tags?post=15371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}