【问题标题】:Swift variables and memory usageSwift 变量和内存使用
【发布时间】:2016-01-12 04:28:32
【问题描述】:

我使用 storyboard segue 在整个应用程序中导航。我为segue identifiertable cell identifier 声明字符串变量。所以我不会在视图控制器类中打错字。

import UIKit

private let showTripViewSegueIdentifier = "showTripView"
private let contactCellIdentifier = "contactCell"

class JobViewController: UIViewController , UITableViewDataSource,UITableViewDelegate{
}

它会影响应用程序的内存使用吗? (因为整个应用程序会有很多视图控制器)。这是一个好方法吗?

提前致谢。

【问题讨论】:

  • 请扩展您的问题和支持细节。措辞很不清楚:(我已将您的问题读了三遍,但仍然看不到您要问的实际问题:(

标签: ios swift memory-management


【解决方案1】:

这不会产生重大影响。无论如何,字符串都必须存储在某个地方,因为您在运行时使用它们。

【讨论】:

    【解决方案2】:

    像这样声明一个枚举:

    枚举 SegueIdentifier:字符串 { 案例SegueIdentifier1 案例SegueIdentifier2 案例SegueIdentifier3 }

    【讨论】:

      【解决方案3】:

      它不应该真的有所作为。但是,更好的方法是使用上面 Arun 也提到的枚举。

      例如 -

      enum SegueIdentifier{
          case showTripView
          case contactCell
      }
      

      并借助较短的点语法在您的代码中使用它。例如 - .contactCell

      【讨论】:

        猜你喜欢
        • 2011-12-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-02
        • 2021-05-16
        • 1970-01-01
        相关资源
        最近更新 更多