# ObjectiveC and Declares

**URL:** <https://forum.xojo.com/t/objectivec-and-declares/18573>\
**Category:** General\
**Created:** [August 13, 2014, 9:50pm UTC](https://forum.xojo.com/t/objectivec-and-declares/18573 "2014-08-13T21:50:19Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Charlesworth](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/958977/32.png) [@Mike\_Charlesworth](https://forum.xojo.com/u/Mike_Charlesworth)\
**Post date:** [August 13, 2014, 9:50pm UTC](https://forum.xojo.com/t/objectivec-and-declares/18573/1 "2014-08-13T21:50:19Z")

</div>

Can anyone clarify in the apple docs what the asterisk would mean in the following:

`Class NSClassFromString (
   NSString *aClassName
);`

but not in:

`BOOL NSContainsRect (
   NSRect aRect,
   NSRect bRect
);`

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [August 13, 2014, 10:05pm UTC](https://forum.xojo.com/t/objectivec-and-declares/18573/2 "2014-08-13T22:05:04Z")

</div>

It means it’s a pointer to the data and not the actual data.

---

<div class="post-metadata">

**Author:** ![Mike\_Charlesworth](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/958977/32.png) [@Mike\_Charlesworth](https://forum.xojo.com/u/Mike_Charlesworth)\
**Post date:** [August 13, 2014, 10:17pm UTC](https://forum.xojo.com/t/objectivec-and-declares/18573/3 "2014-08-13T22:17:34Z")

</div>

> [@120436:@Tim Hare](#):
>
> It means it’s a pointer to the data and not the actual data.

So in NSClassFromString why would this be a pointer rather than just passing a string to the function?

---

<div class="post-metadata">

**Author:** ![Jason\_King](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@Jason\_King](https://forum.xojo.com/u/Jason_King)\
**Post date:** [August 13, 2014, 10:36pm UTC](https://forum.xojo.com/t/objectivec-and-declares/18573/4 "2014-08-13T22:36:23Z")

</div>

Use [CFStringRef](http://documentation.xojo.com/index.php/CFStringRef). So the declare would be:

```auto
Declare Function NSClassFromString lib "Cocoa.framework" (className as CFStringRef) as Ptr
```

Since CFStringRef does implicit conversion from/to string, you can simply pass in the class name as a standard Xojo string, i.e.:

```auto
dim NSObjectClassRef as Ptr = NSClassFromString("NSObject")
```

---

<div class="post-metadata">

**Author:** ![Mike\_Charlesworth](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/958977/32.png) [@Mike\_Charlesworth](https://forum.xojo.com/u/Mike_Charlesworth)\
**Post date:** [August 13, 2014, 10:45pm UTC](https://forum.xojo.com/t/objectivec-and-declares/18573/5 "2014-08-13T22:45:50Z")

</div>

[quote=120445:@Jason King]Use [CFStringRef](http://documentation.xojo.com/index.php/CFStringRef). So the declare would be:

```auto
Declare Function NSClassFromString lib "Cocoa.framework" (className as CFStringRef) as Ptr
```

Since CFStringRef does implicit conversion from/to string, you can simply pass in the class name as a standard Xojo string, i.e.:

```auto
dim NSObjectClassRef as Ptr = NSClassFromString("NSObject")
```

Thanks Jason. Just wondering from ObjectiveC point of view though why it would be a pointer to the class name though and not just the class name.

---

<div class="post-metadata">

**Author:** ![Jason\_King](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@Jason\_King](https://forum.xojo.com/u/Jason_King)\
**Post date:** [August 13, 2014, 10:56pm UTC](https://forum.xojo.com/t/objectivec-and-declares/18573/6 "2014-08-13T22:56:10Z")

</div>

Ah, I misunderstood what you were asking. From my understanding it is because NSRects are a datatype and not a class, and are therefore passed byVal (not as a pointer), while NSString is a class so instances are passed byRef (as a pointer). The same is true in Xojo: integers, doubles, strings, and other datatypes are passed byVal, while classes are passed byRef even when you do not specify that in a method. Hopefully that makes sense?

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [August 13, 2014, 11:09pm UTC](https://forum.xojo.com/t/objectivec-and-declares/18573/7 "2014-08-13T23:09:58Z")

</div>

Mostly because strings are variable in length and you must pass a fixed size variable as a parameter. Thus you pass the pointer. NSRect is fixed size and can be passed directly.

---

<div class="post-metadata">

**Author:** ![Mike\_Charlesworth](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/958977/32.png) [@Mike\_Charlesworth](https://forum.xojo.com/u/Mike_Charlesworth)\
**Post date:** [August 13, 2014, 11:12pm UTC](https://forum.xojo.com/t/objectivec-and-declares/18573/8 "2014-08-13T23:12:51Z")

</div>

> [@120473:@Tim Hare](#):
>
> Mostly because strings are variable in length and you must pass a fixed size variable as a parameter. Thus you pass the pointer. NSRect is fixed size and can be passed directly.

I see, thanks Tim

---

<div class="post-metadata">

**Author:** ![Mike\_Charlesworth](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/958977/32.png) [@Mike\_Charlesworth](https://forum.xojo.com/u/Mike_Charlesworth)\
**Post date:** [August 15, 2014, 11:40am UTC](https://forum.xojo.com/t/objectivec-and-declares/18573/9 "2014-08-15T11:40:24Z")

</div>

Tim what about (void \*) as a return value.

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [August 15, 2014, 11:45am UTC](https://forum.xojo.com/t/objectivec-and-declares/18573/10 "2014-08-15T11:45:10Z")

</div>

For void \* use Ptr (it is a pointer to an unknown type).

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:22pm UTC](https://forum.xojo.com/t/objectivec-and-declares/18573/11 "2020-10-29T17:22:24Z")

</div>


