0

In objective-c for NSArray we have methods:

+ (instancetype)arrayWithObject:(id)anObject;
+ (instancetype)arrayWithArray:(NSArray *)array;

are there similar methods in swift?

Thanks in advance!

1 Answer 1

3

No, because they are not needed. Swift arrays are value types, so when you assign an instance of an array to another variable (or pass to a function/method), a copy of it is created and assigned/passed.

So you don't have anything special to do - the problem arises when you need the opposite, as assigning an array by reference is not possible - although it's possible to pass to a function/method by using the inout modifier.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.