Does Objective C Have Optionals?

It is common in Objective-C to return nil for an object reference where in Swift you would use an optional type. Unfortunately there is nothing in the Objective-C code that tells the compiler which references can be nil so it assumes the worst and makes everything an implicitly unwrapped optional.

What is optional in Objective-C?

A Optional is a generic type, that is, a type that's dependent (actually, parametric) on another subtype, so whe can have, for example, a Optional<String> or a Optional<Int> : thanks to some syntactic sugar, those types are written in Swift as String? and Int? .

Is Objective-C harder than Swift?

Objective-C is older and currently more popular. It's a little bit more difficult to learn, but the majority of developers out there know how to use it. Swift is still new, but it's making progress fast. It's perceived as a safer option compared to Objective-C, and it's easier to learn.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.