Learning Swift - Generics
troz.net·18w
➡️Arrows
Preview
Report Post

29th February 2016 • 841 words • 5 minutes reading time.

One of the nice things about Swift is how clean your code looks. A lot of the weird characters that pepper the code of other languages has been eliminated: No more semi-colons, asterisks etc.

But then you are reading somebody else’s code and you find these angle brackets all over the place and they don’t seem to make sense.

What does this mean?

func mid<T: Comparable>(array: [T]) -> T

It looks like it is a function to find the middle element in an array, but what is <T: Comparable> or [T] or even just T? They are describing Generic data types.

Using the dictionary, I find the following definition for generic:

characteristic of or relating to a class or group of things; not specific.

And that really pro…

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help