When we run the above program using playground, we get the following result:
fatal error: unexpectedly found nil while unwrapping an Optional value
0 swift 0x0000000103410b68
llvm::sys::PrintStackTrace(__sFILE*) + 40
1 swift 0x0000000103411054 SignalHandler(int) + 452
2 libsystem_platform.dylib 0x00007fff9176af1a _sigtramp + 26
3 libsystem_platform.dylib 0x000000000000000b _sigtramp + 1854492939
4 libsystem_platform.dylib 0x00000001074a0214 _sigtramp + 1976783636
5 swift 0x0000000102a85c39
llvm::JIT::runFunction(llvm::Function*, std::__1::vector > const&) + 329
6 swift 0x0000000102d320b3
llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*,
std::__1::vector<std::__1::basic_string, std::__1::allocator >,
std::__1::allocator<std::__1::basic_string, std::__1::allocator > > > const&,
char const* const*) + 1523
7 swift 0x000000010296e6ba
swift::RunImmediately(swift::CompilerInstance&,
std::__1::vector<std::__1::basic_string, std::__1::allocator >,
std::__1::allocator<std::__1::basic_string, std::__1::allocator > > > const&,
swift::IRGenOptions&, swift::SILOptions const&) + 1066
8 swift 0x000000010275764b frontend_main(llvm::ArrayRef,
char const*, void*) + 5275
9 swift 0x0000000102754a6d main + 1677
10 libdyld.dylib 0x00007fff8bb9e5c9 start + 1
11 libdyld.dylib 0x000000000000000c start + 1950751300
Stack dump:
- Program arguments:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/
usr/bin/swift -frontend -interpret - - target x86_64-apple-darwin14.0.0 -target-
cpu core2 -sdk
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/
SDKs/MacOSX10.10.sdk -module-name main
/bin/sh: line 47: 15672 Done cat <<'SWIFT'
import Foundation
</std::1::basic_string</std::__1::basic_string</std::1::basic_string</std::
__1::basic_string
The above program declares 'election poll' as class name and contains 'candidate' as
membership function. The subclass is declared as 'poll booth' and 'name' as its
membership function which is initialized as 'MP'. The call to the super class is initialized by
creating an instance 'cand' with optional '!'. Since the values are not declared in its base
class, 'nil' value is stored thereby returning a fatal error by the force unwrapping
procedure.