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 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
Post a Comment