Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift字符串数组迭代函数_Ios_Arrays_Swift_Func - Fatal编程技术网

Ios Swift字符串数组迭代函数

Ios Swift字符串数组迭代函数,ios,arrays,swift,func,Ios,Arrays,Swift,Func,我正在尝试输入一个包含所有月份的数组,并在我的滚动日历上逐个显示它们。我试图返回日历每个标题的每个“月” 我正在使用下面的字符串数组,但是我不确定如何返回我想要的字符串类型。你知道我做错了什么吗?谢谢 let months: [String] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"] fu

我正在尝试输入一个包含所有月份的数组,并在我的滚动日历上逐个显示它们。我试图返回日历每个标题的每个“月”

我正在使用下面的字符串数组,但是我不确定如何返回我想要的字符串类型。你知道我做错了什么吗?谢谢

let months: [String] = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]

func monthCounter(inputArray:Array<String>) -> String{
    for name in inputArray{
        return name

    }


} 
您的代码有几个问题。 首先,
数组
应该是
[String]
,从迭代内部返回将终止迭代。您可以在那里调用函数,也可以
打印(\(名称)”)
开始查看代码是否正常工作


正如我在下面的评论中所写,我认为你的方法是不正确的。您的委托函数不是这样工作的。即使一个monthCounter调用能够返回多次,您也会一次又一次地覆盖相同的文本属性。查找要使用的正确委托函数,该函数在将显示的标题的月份中传递。有关可能的提示,请参阅我的注释。

月份计数器将在第一次运行时返回,即一月,并将从循环中出来。它希望我在函数中的for循环后返回一个类型“String”。我该怎么做?ThanksI将使用此代码获取一个月数组,该数组为您本地化并完成:
let months=Calendar.current.monthSymbols
ahh,我不知道。非常感谢ColGraff!可以使用
数组
。我们有
公共结构数组:RandomAccessCollection,MutableCollection
你完全正确。[String]只是数组的简写版本。然而,我认为这很奇怪,使用[String]作为类型长达数月,然后在函数声明中使用数组。明白了,但是在for循环括号之后我应该返回什么呢?谢谢,我不确定您是否使用了正确的委托功能来实现您想要实现的目标。您需要知道返回标题文本的月份。您可能想签出
func calendar(calendar:JTAppleCalendarView,SectionHeaderIdentifier for range:(开始:日期,结束:日期),beloving to month:Int)->String
,在这里您可以直接使用一个月参数来确定您需要的月名(例如,只需执行
返回月[month]
headerCell?.monthsHeader.text = monthCounter[index of section]
headerCell?.monthsHeader.text = monthCounter[index of section]