删除发行版iOS Swift的println() [英] Remove println() for release version iOS Swift

查看:104
本文介绍了删除发行版iOS Swift的println()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我不在Debug构建中,我想全局忽略我的Swift代码中的所有 println()调用。我找不到任何有力的分步说明,并希望得到指导。有没有办法在全球范围内这样做,或者我需要用 #IF DEBUG /#ENDIF println() c>陈述?

I would like to globally ignore all println() calls in my Swift code if I am not in a Debug build. I can't find any robust step by step instructions for this and would appreciate guidance. is there a way to do this globally, or do I need to surround every println() with #IF DEBUG/#ENDIF statements?

推荐答案

如上所述,我是一名学生,需要更清楚地定义一些内容。经过大量研究,我需要遵循的顺序是:

As noted, i am a student and need things defined a little more clearly to follow along. After lots of research, the sequence I needed to follow is:

点击Xcode项目窗口左侧File Navigator顶部的项目名称。这是具有项目名称,有多少构建目标以及iOS SDK版本的行。

Click on the project name at the top of the File Navigator at the left of the Xcode project window. This is line that has the name of the project, how many build targets there are, and the iOS SDK version.

选择构建设置选项卡并向下滚动到底部附近的 Swift编译器 - 自定义标志部分。点击其他标志旁边的向下箭头展开该部分。

Choose the Build Settings tab and scroll down to the "Swift Compiler - Custom Flags" section near the bottom. Click the Down Arrow next to Other Flags to expand the section.

点击调试行将其选中。将鼠标光标放在该行的右侧,然后双击。将出现一个列表视图。点击列表视图左下角的 + 按钮添加值。文本字段将变为活动状态。

Click on the Debug line to select it. Place your mouse cursor over the right side of the line and double-click. A list view will appear. Click the + button at the lower left of the list view to add a value. A text field will become active.

在文本字段中,输入文本 -D DEBUG 并按返回提交该行。

In the text field, enter the text -D DEBUG and press Return to commit the line.

将新的Swift文件添加到项目中。您将要为该文件创建自定义类,因此请按以下行输入文本:

Add a new Swift file to your project. You are going to want to make a custom class for the file, so enter text along the lines of the following:

class Log {

  var intFor : Int

  init() {
    intFor = 42
   }

  func DLog(message: String, function: String = __FUNCTION__) {
    #if DEBUG
      println("\(function): \(message)")
    #endif
  }
}

我今天无法让Xc接受这个类,所以init可能是比必要的更重量级。

I was having trouble getting the class to be accepted by Xcode today, so the init may be a bit more heavyweight than necessary.

现在,您需要在任何打算使用新自定义函数的类中引用您的自定义类来代替 println()在每个适用的类中将其添加为属性:

Now you will need to reference your custom class in any class in which you intend to use the new custom function in place of println() Add this as a property in every applicable class:

   let logFor = Log()

现在你可以用<替换 println()的任何实例code> logFor.DLog()。输出还包括调用该行的函数的名称。

Now you can replace any instances of println() with logFor.DLog(). The output also includes the name of the function in which the line was called.

注意,在类函数内部我无法调用函数,除非我复制了作为该类中的类函数, println()对输入也更灵活,所以我不能在我的代码中的每个实例中使用它。

Note that inside class functions I couldn't call the function unless I made a copy of the function as a class function in that class, and println() is also a bit more flexible with the input, so I couldn't use this in every instance in my code.

这篇关于删除发行版iOS Swift的println()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆