I need to return null or an empty value to identify an error condition. Since NSMutableData is not assignable to NULL in the following method, I'm just initialising it using the init() method.
Now how I check if the data is empty or is it possible to return null?
func generatedata(input:URL)->NSMutableData?
{
if(errorcondition)
{
return NSMutableData.init()
}
}
The swifty way is to throw an error and return non-optional
Dataon successanErrorrepresents a custom error conforming toErrorOr return empty
Data()which can be checked withisEmptyBut never use reference type
NS(Mutable)Datain Swift