[MacRuby-devel] My class's initialize not called

Matt Aimonetti mattaimonetti at gmail.com
Thu Jan 21 15:25:22 PST 2010


When reopening a Cocoa class, you should not overwrite initialize and if you
were to do it anyway, don't forget to call super and to return self.
The Cocoa way is to create your own initializer to end up with something
like DuplicateCounterTextField.alloc.initWithDuplicate

Also, remember that when initializing a Cocoa class, you need to do
DuplicateCounterTextField.alloc.init

- Matt


On Thu, Jan 21, 2010 at 3:20 PM, steve ross <cwdinfo at gmail.com> wrote:

> I'm sure this is an elementary question, but I have the class below. In IB,
> I set several NSTextField controls to this class. Everything works in the
> blah, blah, blah part, but strangely enough the
>
> puts "initialize dctf"
>
> never seems to be called. Any thoughts as to why?
>
> require 'strings'
>
> class DuplicateCounterTextField < NSTextField
>  include Strings
>
>  attr_accessor :splitter, :completions
>  attr_accessor :wordCount, :duplicateCount
>
>  def initialize
>    puts "initialize dctf"
>    @splitter = /\W+/
>    @wordCount = 0
>    @cachedWordCount = 0
>    @duplicateCount = 0
>  end
>
>  # blah, blah, blah working code
>
>  def textDidChange(notification)
>    words = stringValue.split(@splitter)
>    @wordCount = words.length
>    @duplicateCount = @wordCount - words.uniq.length
>
>    if
> delegate.respond_to?('controlCountDidChange:wordCount:duplicateCount:')
>      delegate.controlCountDidChange(self,
>                                   wordCount:@wordCount,
>                              duplicateCount:@duplicateCount)
>    end
>  end
>
>  # etc.
> end
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20100121/5e8b7604/attachment-0001.html>


More information about the MacRuby-devel mailing list