Swift3 为节创建常量是个好主意吗?

Swift3 为节创建常量是个好主意吗?,swift3,coding-style,Swift3,Coding Style,我有一个表格视图,它有许多部分。假设第一部分是针对UserProfile的。在第节的numberOfRows中,我想使用like if section == UserProfileSection { return 2 } 这样做是个好主意吗?因为UserProfileSection不会在其他任何地方使用。或者我应该像这样使用目录0 if section == 0 { return 2 } 是的,常数是个好主意!这是100%基于观点的,因此是离题的。如果我设定一个常数,它会增加内存

我有一个表格视图,它有许多部分。假设第一部分是针对UserProfile的。在第节的numberOfRows中,我想使用like

if section == UserProfileSection {
  return 2
} 
这样做是个好主意吗?因为UserProfileSection不会在其他任何地方使用。或者我应该像这样使用目录0

if section == 0 {
  return 2
} 

是的,常数是个好主意!这是100%基于观点的,因此是离题的。如果我设定一个常数,它会增加内存消耗吗。为什么?2.别担心那样的事!