How to avoid null pointer exception in swift iOS

Solution:

If you are getting the value from server or if you don't know the type of data type then use the below code.

The below code is used for get the string value.If the datatype is string then only inside of the code executes.So if the value came as nil then no issues we can handle.


        if let nameString = namStr as? String {
            //use the nameString
        }

Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

Convert NsNumber, NSDate to String in iOS Swift

Global LocationManager Singleton class iOS Swift