Split Vs Components(separateBy)

MdNiks
1 min readJul 26, 2020

--

Devs are habituate with components (separateBy), but Split is more powerful.

Welcome Guys,

Here first we can check with both Parameter value, Return type, Execution time.

Split

Split have 3 different parameters 1. separator, 2. maxSplits, 3. omittingEmptySubsequences.

Components

But components have only one parameter 1. separator.

Let’s start with code and demo.

Output

Last but not the least, Use of components is returning a [String], where split is returning [Substring]. Each String is a String allocation, Substring is only using references, does not allocate new String and is faster and cheaper.

Due to that split Complexity: O(n), where n is the length of the collection.

Just use it. w00t! How cool is that and all done with just follow fews steps.

If you have any comments or questions, please respond below! I’d love to hear from you.

--

--

MdNiks

I'm an accomplished iOS programmer with more than 12 years of experience working in a collaborative environment with tight deadlines.