Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement Toll-Free Bridging in ObjectiveC/C?

Tags:

objective-c

The iOS and OS X Sdk have a very cool concept of toll-free bridging. If I were to write my own code in C and write Obj-C wrapper for it, and want to use it as Toll-Free-Bridged, how should I do that? Any examples please.

like image 818
zakishaheen Avatar asked Jan 25 '12 12:01

zakishaheen


Video Answer


2 Answers

See the tutorial at https://web.archive.org/web/20111013023821/http://cocoadev.com/index.pl?HowToCreateTollFreeBridgedClass. Basically, you need to create a C structure, that has the same size and layout as the obj-c counterpart. Also some funky stuff has to be done to correctly implement retain/release.

like image 56
kuba Avatar answered Oct 13 '22 19:10

kuba


The simplest way to do this, if you can, is to write your code in Objective-C, and then wrap it in C. That avoids all of the tricky parts of toll-free bridging (and those tricky parts are only getting trickier. -retain/-release is more complicated if you want to support ARC __weak for example).

like image 23
Catfish_Man Avatar answered Oct 13 '22 20:10

Catfish_Man