Chapter 21

Ten Swift Features That Are Not in C

Considering that Swift is a newly developed, object-oriented language, and that C was developed almost half a century ago (by Dennis Ritchie in 1969-1973), when the object-oriented paradigm wasn’t even in widespread use, you might think that comparing these two languages would be difficult and, in many ways, unfair to both languages.

That's one way of looking at things, but another way is to look at C’s impact on modern languages. C is still taught in computer-science courses in a variety of programs from primary schools to post-graduate courses. C is still being taught because it is still one of the most widely used languages. C may not be cutting-edge, but it has served a major role in the development of today's software and the people who design and develop it.

For those who are familiar with C and now learning Swift, this chapter explains the major distinctions between the two languages. I take for granted that you know that Swift has been developed for an environment that includes large and small computers (that is, Macs and mobile iOS devices) whereas C was developed for minicomputers and mainframes.

With that out of the way, here are ten Swift features that are not in C.

Strong Typing

Swift is much more strongly typed than C. If you want to cast a value to another type, you have to do it rather than rely on it being done for you automatically. For example, consider this code:

var x = 4var y = 4.0var z = x + y

The last ...

Get Swift For Dummies now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.