Lisp HUG Maillist Archive

arrayWithObjects: in LW

Hi,

I have following problem in LW 4.5.5. When i try to invoke method arrayWithObjects: with arguments as shown below i got the following error message: "Too many arguments in ("dave" "john" "guy") to method "arrayWithObjects:", wanted 1". I think that arrayWithObjects: method takes variable number of arguments, but may be i am worng, because of my ObjC knowledge is poor. Where's the problem ?

example:

 (let*  ((my-array (objc:invoke "NSArray" "arrayWithObjects:"  "dave" "john" "guy" nil))
          (my-item (objc:invoke-into 'string  my-array "objectAtIndex:" 0)))

Thanks.


Unable to render article 4083 because of ":DEFAULT stream decoding error on #<SB-SYS:FD-STREAM for \"socket 192.168.43.216:64413, peer: 116.202.254.214:119\" {1001580DA3}>: the octet sequence #(225 108 32) cannot be decoded." error

Re: arrayWithObjects: in LW

On Jun 29, 2005, at Wed, Jun 29, 10:45 06 AM, Martin Simmons wrote:
>
> Sorry, the LW ObjC API doesn't support calling varargs methods so  
> you will
> have to make an empty array and then fill it.

Something like this:

;; note that this returns an NSArray which is immutable.
;; if you want a mutable array, just edit this to leave
;; out the arrayWithArray: line and return mut-array instead.

(defun ns-array-with-list (some-list)
   "returns an NSArray whose contents are the items of some-list"
   (let ((ns-array)
         (mut-array (objc:invoke "NSMutableArray"  
"arrayWithCapacity:" 1)))
          ;; 1 is arbitrary - mut-array can expand
         (loop for item in some-list do
               (objc:invoke mut-array "addObject:" item))
         (setf ns-array (objc:invoke "NSArray" "arrayWithArray:" mut- 
array))
         ns-array))

Then you can do:

CL-USER 25 > (objc:with-autorelease-pool ()
                (objc:invoke-into 'string (ns-array-with-list (list  
"hello" "there" "you" "guys")) "objectAtIndex:" 0))
"hello"

regards,

Ralph


Raffael Cavallaro, Ph.D.
raffaelcavallaro@mac.com


Updated at: 2020-12-10 08:52 UTC