I had designed an custom object which was sure to return a value. Now the whole app is build around that custom object. Now conditions have appeared which can cause the custom object to be nil.
What do I do . Change the type to optional ? and change code everywhere to unwrap. Any other better solutions ?
Change the type to implicitly unwrapped optional. This way you can use it like a regular non-optional value everywhere you know for sure it wouldn't be
nil(or wherenilwould mean an unrecoverable error), and check for nil where it can benil.Example:
Generally you would want to avoid implicitly unwrapped optionals, except for cases where you cannot initialise objects too early for technical reasons, e.g. in the case of interface builder outlets or asynchronously initialised objects, etc.