OGeek|极客世界-中国程序员成长平台

标题: ios - 使用多个变量创建字符串 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 19:56
标题: ios - 使用多个变量创建字符串

我有一些变量,我想用这些变量来创建一个可以打印到 UILabel 的字符串。

maturityDate | ComparisonTerm | monthsToMaturity | ComparisonRate

以下是变量:

maturitDateate // value (value to return MMM DD, YYYY) Ex June 23, 2017

ComparisonTerm: Double
MonthsToMaturity: Double
ComparisonRate: Double

我想要“|”条作为分隔符。我最大的挑战是处理日期值。目前以返回2021-09-01 04:00:00 + 000为例。



Best Answer-推荐答案


其他三个这样的变量应该很简单

   "\(ComparisonTerm) | \(monthsToMaturity) | \(ComparisonRate)"

对于日期,您必须使用日期格式化程序

      let dateFormatter = DateFormatter()
      dateFormatter.dateStyle = .mediumStyle  // or .shortStyle
      dateFormatter.timeStyle = .noStyle

所以所需的日期字符串基本上是

    "\(dateFormatter.dateFromString(maturitDate)) | \(ComparisonTerm) | \(monthsToMaturity) | \(ComparisonRate) "

关于ios - 使用多个变量创建字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44731264/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4