Projects

Ticket #131 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Dictionary arg not accepted

Reported by: francois@… Owned by: lsansonetti@…
Priority: major Milestone: MacRuby 0.4
Component: MacRuby Keywords:
Cc: masterkain@…

Description

The interpreter finds an error here:

@tmp = NSAttributedString.alloc.initWithData(data, options:NSCharacterEncodingDocumentOption, documentAttributes:0, error:outError);

/Users/francois/Documents/Essais_xcode_et_Ruby/temp3R/build/Debug/temp3R.app/Contents/Resources/MyDocInRuby.rb:46:in initWithData:options:documentAttributes:error:': can't convert Ruby object 0' to Objective-C value of type `@' (ArgumentError)

The problem seems to be in the documentAttributes argument; you can pass 0, an NSDictionary, or a Hash, nothing works. Cocoa expects a value of type NSDictionary** for this argument.

Change History

Changed 3 years ago by lsansonetti@…

So, NSDictionary** means that this argument is returned by reference. Currently this is not implemented in MacRuby, so I will keep this ticket open until it's fixed.

In the meantime you can pass "nil", which is the Objective-C nil equivalent (so, C's NULL). Passing 0 will not work, because 0 in Ruby is a fixnum (numeric) object.

Changed 3 years ago by masterkain@…

Changed 3 years ago by masterkain@…

  • cc masterkain@… added

Cc Me!

Changed 3 years ago by lsansonetti@…

  • status changed from new to closed
  • resolution set to fixed

The Pointer class was introduced in MacRuby trunk to specifically address these problems.

  pattributes = Pointer.new_with_type('@')
  perror = Pointer.new_with_type('@')
  o = NSAttributedString.alloc.initWithData(data, options:NSCharacterEncodingDocumentOption, documentAttributes:pattributes, error:perror);
  unless o
    p perror[0]
  else
    p pattributes[0]
  end
Note: See TracTickets for help on using tickets.