Re: NSValue/initWithBytes
Re: NSValue/initWithBytes
- Subject: Re: NSValue/initWithBytes
- From: "Clark Cox" <email@hidden>
- Date: Thu, 27 Dec 2007 09:11:42 -0500
On Dec 27, 2007 8:30 AM, Roland Silver <email@hidden> wrote:
> I think I can create an NSValue object for a pointer to structure using the
> class method valueWithPointer like this:
> struct Foo foo;
> NSValue* value = [NSValue valueWithPointer:&foo]; //(1)
>
> But I would like instead to create such a pointer using the init method for
> the class:
> NSValue* value = [[NSValue alloc] initWithBytes:val objCType:typ]; //(2)
>
> Please tell me what val and typ I should use so that (2) produces the same
> value as (1).
void *pointer = &foo;
[[NSValue alloc] initWithBytes: &pointer objCType: @encode(void*)];
Notice the double-indirection; the pointer passed to
initWithBytes:objCType: is a _pointer to a pointer to your structure_
(BTW, this question is probably more appropriately posted to the
Cocoa-dev mailing list, as it has nothing to do with Xcode)
--
Clark S. Cox III
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden