Swift Array type connected to Foundation NSArray class, how?

In the Swift Language Guide, we read the following:

The Swifts Array type is bound to the Foundations NSArray class.

How can I associate Swift Arraywith the Foundation class NSArraywhen the first is a value type and the second is a reference type? Does an interface connect to an interface in a language to use code in another language?

+4
source share
2 answers

The meaning / reference difference here is a little red herring.

(, ) . _ObjectiveCBridgeable, , ObjC Swift. , , mySwiftArray as NSArray _bridgeToObjectiveC().

Array Foundation. Swift: .

, , Swift Array .

; "", Swift.Array . , . 101 , . . (, , - , .)

C , :

typedef struct _Array {
    void * payload;
} Array;

Array c;
c.payload = malloc( /* Whatever */ );
Array d = c;

d , , . ( , "" NSArray Swift.Array: , .)

+4

, , !

?

, - ...

Swift Array Foundation NSArray, , - ?

... .

a NSArray count objectAtIndex:. Swift Objective-C, NSArray, () Swift, .. .

Objective-C Swift, ; , Swift Objective-C Objective-C. "", Swift Objective-C, . , .

, , . , , , , Swift Objective-C, .

0

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


All Articles