• <tfoot id='i08B6'></tfoot>
    <i id='i08B6'><tr id='i08B6'><dt id='i08B6'><q id='i08B6'><span id='i08B6'><b id='i08B6'><form id='i08B6'><ins id='i08B6'></ins><ul id='i08B6'></ul><sub id='i08B6'></sub></form><legend id='i08B6'></legend><bdo id='i08B6'><pre id='i08B6'><center id='i08B6'></center></pre></bdo></b><th id='i08B6'></th></span></q></dt></tr></i><div id='i08B6'><tfoot id='i08B6'></tfoot><dl id='i08B6'><fieldset id='i08B6'></fieldset></dl></div>
    <legend id='i08B6'><style id='i08B6'><dir id='i08B6'><q id='i08B6'></q></dir></style></legend>

        <bdo id='i08B6'></bdo><ul id='i08B6'></ul>

        <small id='i08B6'></small><noframes id='i08B6'>

      1. 快速从函数中返回多个值

        时间:2023-10-04
          <bdo id='zUu4R'></bdo><ul id='zUu4R'></ul>

            • <legend id='zUu4R'><style id='zUu4R'><dir id='zUu4R'><q id='zUu4R'></q></dir></style></legend>
              <tfoot id='zUu4R'></tfoot>

                    <tbody id='zUu4R'></tbody>

                • <i id='zUu4R'><tr id='zUu4R'><dt id='zUu4R'><q id='zUu4R'><span id='zUu4R'><b id='zUu4R'><form id='zUu4R'><ins id='zUu4R'></ins><ul id='zUu4R'></ul><sub id='zUu4R'></sub></form><legend id='zUu4R'></legend><bdo id='zUu4R'><pre id='zUu4R'><center id='zUu4R'></center></pre></bdo></b><th id='zUu4R'></th></span></q></dt></tr></i><div id='zUu4R'><tfoot id='zUu4R'></tfoot><dl id='zUu4R'><fieldset id='zUu4R'></fieldset></dl></div>

                  <small id='zUu4R'></small><noframes id='zUu4R'>

                  本文介绍了快速从函数中返回多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何从 swift 中的函数返回 3 个相同类型(Int)的单独数据值?

                  How do I return 3 separate data values of the same type(Int) from a function in swift?

                  我正在尝试返回一天中的时间,我需要将小时、分钟和秒作为单独的整数返回,但是从同一个函数中一次性返回,这可能吗?

                  I'm attempting to return the time of day, I need to return the Hour, Minute and Second as separate integers, but all in one go from the same function, is this possible?

                  我想我只是不明白返回多个值的语法.这是我正在使用的代码,我遇到了最后(返回)行的问题.

                  I think I just don't understand the syntax for returning multiple values. This is the code I'm using, I'm having trouble with the last(return) line.

                  任何帮助将不胜感激!

                  func getTime() -> Int
                  {
                      let date = NSDate()
                      let calendar = NSCalendar.currentCalendar()
                      let components = calendar.components(.CalendarUnitHour | .CalendarUnitMinute | .CalendarUnitSecond, fromDate: date)
                      let hour = components.hour
                      let minute = components.minute
                      let second = components.second
                      let times:String = ("(hour):(minute):(second)")
                      return hour, minute, second
                  }
                  

                  推荐答案

                  返回一个元组:

                  func getTime() -> (Int, Int, Int) {
                      ...
                      return ( hour, minute, second)
                  }
                  

                  然后它被调用为:

                  let (hour, minute, second) = getTime()
                  

                  或:

                  let time = getTime()
                  println("hour: (time.0)")
                  

                  这篇关于快速从函数中返回多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Swift 可以从异步 Void 返回块返回值吗? 下一篇:将参数传递给 AsyncTask,并返回结果

                  相关文章

                  <i id='2g7IE'><tr id='2g7IE'><dt id='2g7IE'><q id='2g7IE'><span id='2g7IE'><b id='2g7IE'><form id='2g7IE'><ins id='2g7IE'></ins><ul id='2g7IE'></ul><sub id='2g7IE'></sub></form><legend id='2g7IE'></legend><bdo id='2g7IE'><pre id='2g7IE'><center id='2g7IE'></center></pre></bdo></b><th id='2g7IE'></th></span></q></dt></tr></i><div id='2g7IE'><tfoot id='2g7IE'></tfoot><dl id='2g7IE'><fieldset id='2g7IE'></fieldset></dl></div>

                  <legend id='2g7IE'><style id='2g7IE'><dir id='2g7IE'><q id='2g7IE'></q></dir></style></legend>

                  <small id='2g7IE'></small><noframes id='2g7IE'>

                  1. <tfoot id='2g7IE'></tfoot>
                    • <bdo id='2g7IE'></bdo><ul id='2g7IE'></ul>