fix swift undefined method for nil:NilClass