Home>

I am always indebted to you. It seems to be the basic content, but I couldn't do it well, so please help me.
I have the following array that represents such a date, and I would like to reorganize the array for each year and month.

var datesArray: [String] = ["2020-08-11", "2020-11-18", "2021-02-14", "2020-09-03", "2020-12-21", "2020" -09-11 "]]

The result of what I want to do
var nextYear = ["2021-02-14"]

var thisYear = ["2020-08-11", "2020-09-03", "2020-09-11", "2020-11-18", "2020-12-21"]
var augThisYear = ["2020-08-11"]
var sepThisYear = ["2020-09-03", "2020-09-11"]
var novYhisYear = ["2020-11-18"]
var decThisYear = ["2020-12-21"]


The current situation is saved in the database like this
"year" "2020"
"month" "09"
"day" "11"

It is divided at the time of calling. .. ..
I'm sorry, thank you.

I found this article!
https://www.tutorialfor.com/go.php?id=76437

var datesArray: [String] = ["2020-08-11", "2020-11-18", "2021-02-14", "2020-09-03", "2020-12-21", "2020" -09-11 "]]
var a = datesArray.filter {$0.contains ("09")}
print (a)

Error message
Cannot convert value of type'String' to expected argument type'String.Element' (aka'Character')

  • Answer # 1

    Cannot convert value of type'String' to expected argument type'String.Element' (aka'Character') error was resolved by importing UIKit!
    Excuse me! Thank you for visiting us!

    import UIKit
    var datesArray: [String] = ["2020-08-11", "2020-11-18", "2021-02-14", "2020-09-03", "2020-12-21", "2020" -09-11 "]]

    var a = datesArray.filter {$0.contains ("09")}
    print (a)

    result
    ["2020-09-03", "2020-09-11"]