<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cocoa &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/cocoa/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.xojo.com</link>
	<description>Blog about the Xojo programming language and IDE</description>
	<lastBuildDate>Wed, 15 Feb 2017 19:55:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Speeding Up TextArea Modifications In OS X</title>
		<link>https://blog.xojo.com/2015/12/28/speeding-up-textarea-modifications-in-os-x/</link>
		
		<dc:creator><![CDATA[Joe Ranieri]]></dc:creator>
		<pubDate>Mon, 28 Dec 2015 00:00:00 +0000</pubDate>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Declares]]></category>
		<category><![CDATA[OS X]]></category>
		<guid isPermaLink="false">http://blogtemp.xojo.com/2015/12/28/speeding-up-textarea-modifications-in-os-x/</guid>

					<description><![CDATA[Speeding up TextArea modifications Under Cocoa]]></description>
										<content:encoded><![CDATA[<p>When doing a lot of manipulation to a TextArea&#8217;s contents under Cocoa, performance can suffer due to the underlying NSTextView doing work on layout and glyph selection. This can be sped up by telling the text view that you&#8217;re going to begin editing. You can do this by using a few Cocoa Declares.</p>
<p><span id="more-249"></span></p>
<p>The Declare statements are relatively simple:</p>
<pre>Declare Function documentView Lib "AppKit" Selector "documentView" _
  ( obj As Integer ) As Integer
Declare Function textStorage Lib "AppKit" Selector "textStorage" _
  ( obj As Integer ) As Integer
Declare Sub beginEditing Lib "AppKit" Selector "beginEditing" _
  ( obj As Integer )
Declare Sub endEditing Lib "AppKit" Selector "endEditing" _
  ( obj As Integer )</pre>
<p>These Declares give you access to methods for enabling &#8220;batch-editing mode&#8221; for the underlying NSTextView.</p>
<p>First, you want to get the text storage for the document, which is a two-step process. In the first step, you take the TextArea&#8217;s Handle property (an NSScrollView instance) and ask for its document view:</p>
<pre>Dim docView As Integer
docView = documentView(MyTextArea.Handle)</pre>
<p>Now you get the NSTextStorage for the NSTextView:</p>
<pre>Dim storage As Integer
storage = textStorage(docView)</pre>
<p>With the text storage, you can now enable batch-editing mode by calling beginEditing:</p>
<pre>beginEditing(storage)</pre>
<p>Now you can make your significant changes to the TextArea:</p>
<pre>For i As Integer = 0 To 5000
 MyTextArea.AppendText("Lorem ipsum dolor sit amet. ")
Next</pre>
<p>And when you are finished disable batch-editing mode:</p>
<pre>endEditing(storage)</pre>
<p>So how much does this improve performance? In my tests, the For loop by itself takes about 4.3 seconds to complete. Using batch-edit mode with these Declares drops it to 0.02 seconds. That&#8217;s almost instantaneous!</p>
<p>If you find you are going to use these Declare often, you can add them to a module as Extension methods so that you can call them more easily (as shown in the sample project):</p>
<ul>
<li><a href="http://files.xojo.com/BlogExamples/FastCocoaTextAreaUpdates.xojo_binary_project.zip">Download Sample Project</a></li>
</ul>
<p><strong><span style="font-size: 10px;">Originally published on November 26, 2012 by Joe Ranieri</span></strong> <span id="hs-cta-wrapper-85379a6a-4918-471b-8a83-e3a826fc5e01" class="hs-cta-wrapper"><span id="hs-cta-85379a6a-4918-471b-8a83-e3a826fc5e01" class="hs-cta-node hs-cta-85379a6a-4918-471b-8a83-e3a826fc5e01"><br />
</span></span> <!-- end HubSpot Call-to-Action Code --></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
