Objective-C wrapper API design methodology

I know that no one answered this question, but I would like to tell people about how they approach the situation.

I am writing an Objective-C wrapper to the C library. My goals are:

1) The shell uses Objective-C objects. For example, if the C API defines a parameter such as char *, the Objective-C API should use the name: (NSString *).

2) A client using the Objective-C wrapper does not need to know knowledge about the internal operation of the C library.

Speed ​​is not really a problem.

It is easy with simple parameters. Of course, there is no problem to take NSString and convert it to a C string to pass it to the C library.

My indecision arises when complex structures are involved.

Say you have:

struct flow
{
    long direction;
    long speed;
    long disruption;
    long start;
    long stop;
} flow_t;

And then your C API call is:

void setFlows(flow_t inFlows[4]);

, :
1) flow_t API Objective-C
2) NSArray NSDiction,
3) NSArray "Flow", ,

:
1: .
2: - , " w485". , NSDictionary NSNumber. , , .
3: - , . , # 2, , ( , ), .

, , ? , ? , , ?

+3
4

, 3 -. , , .

, , , . , , ... , stop, , start, , stop , start stop, stop start ( , ).

+2

3. , Flow . , , , , C.

+2

- , , , " ".

, , - " ?" " Objective-C", " , ", C Objective-C ".

, , SQLite . , - :

A) (, , ...)

B) ()

C) SQLite

, SQLite, Objective-C.

:

1) (, , ...)

2) ()

3) SQLite Wrapper (Objective-C)

4) SQLite

, , 3 .

, B SQLite, SQLite , SQLite. , A, SQLite . "" SQLite, . .

+1

Since Objective-C uses structures, why not leave it as a structure, such as NSRect ?

0
source

Source: https://habr.com/ru/post/1737377/


All Articles