Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the technical difference between ? & ! in swift language? [duplicate]

Can anyone explain in detail about the technical difference between ! & ? literals that we are using in swift language. Basically in apple developer document they mentioned it as the nil validation but i didn't understand clearly about the logic behind it. Can you one explain with some real time logic for the same.

Thanks in advance for the user.

like image 344
Naveen Avatar asked Jun 22 '14 14:06

Naveen


People also ask

What is difference between technical and technology?

"Technical" means related to a "technique", a specialized method or procedure, but it can also mean related to machines. "Technological" can also mean related to machines, but now it usually refers to modern electronic machines.

What is difference between technical and non-technical?

Technical writing is meant for experts in their field, while non-technical content is usually written for the general audience who aren't familiar with certain technical terms. This article will explain the key differences between technical and non-technical content writing.

What is the difference between technical and engineering?

Technicians are the "doers" and are tasked with completing projects, whereas engineers are responsible for designing and implementing those projects. Problem-solving abilities: Engineers are required to identify problems and devise solutions to fix those problems, while technicians simply put into action the solutions.

What is the difference between technical and software?

Software's are computer programs that run on computer. Technology are things developed to solve specific problems. It is used to create non-physical tool to solve any information based problem. It is used in production of goods or services to accomplish objective.


1 Answers

Optional Chaining as an Alternative to Forced Unwrapping

You specify optional chaining by placing a question mark (?) after the optional value on which you wish to call a property, method or subscript if the optional is non-nil. This is very similar to placing an exclamation mark (!) after an optional value to force the unwrapping of its value. The main difference is that optional chaining fails gracefully when the optional is nil, whereas forced unwrapping triggers a runtime error when the optional is nil.

— The Swift Programming Language (emphasis added)

Nobody's going to be able to explain it more simply than that. What don't you understand?

like image 141
Tommy Avatar answered Oct 20 '22 01:10

Tommy