zchenah
zchenah

Reputation: 2108

How to get a new NSArray which is the old one without the last element?

I mean get the new array simply, such as in python:

lst[:-1]

Is there any way to do it in objc?

Upvotes: 0

Views: 50

Answers (1)

kennytm
kennytm

Reputation: 523374

You could use -subArrayWithRange:.

[theOriginalArray subarrayWithRange:NSMakeRange(0, [theOriginalArray count]-1)]

This is equivalent to the Python expression lst[0:lst-1], which is the expanded form of your lst[:-1].

Upvotes: 3

Related Questions