0

I have array of dates (strings) which are coming from local data base like following.

datesFromDBArray:["04/12/2017 07:10:41", "04/12/2017 07:12:17", "04/12/2017 07:13:54", "04/12/2017 07:17:45", "04/12/2017 07:18:56", "05/12/2017"]

Here, same date can have multiple times.

Also from same data base, I am getting some other data called actions.

ActionsDBArray:["1", "6", "1", "1", "1", "2", "2", "2", "4", "1", "5", "2", "3"]

these above two data getting from local database. And both arrays number of count is equal.

Now, I am getting number of dates from server response. That is like

TotalDaysServerArray:["22/11/2017 11:59:59", "23/11/2017 11:59:58", "24/11/2017 11:59:57"]

Here, I am showing TotalDaysServerArray data in table view.

So, here, If user pressed on first cell like 22/11/2017 11:59:59, I need to check this date (not time, only same date) is existed in datesFromDBArray, if existed, then need to check how many indexes its existed, and need to fetch ActionsDBArray same indexes data.

So, I need to get the list of ActionsDBArray indexes and need to show the list of that in some other place.

I have tried some logic which was not worked, so, I am posting query here.

Can anyone suggest me, how to achieve this?

4
  • This is not date array logically it is array of string !! Commented Dec 6, 2017 at 14:35
  • @PrashantTukadiya edited. Commented Dec 6, 2017 at 14:36
  • 3
    What have you tried? What issues have you faced? Note that we are not supposed to do your homework. Commented Dec 6, 2017 at 14:38
  • I have tried some logic which is not worked, so, thats why I have raised this query here. Commented Dec 6, 2017 at 14:39

2 Answers 2

1
let clickedStr = TotalDaysServerArray[indexPath.row] 
let str =  clickedStr.components(separatedBy: " ").first
 for(index , value) in datesFromDBArray.enumerated() {
            if str == value.components(separatedBy: " ").first! {
                print(ActionsDBArray[index])
            }
       }
Sign up to request clarification or add additional context in comments.

Comments

0

It's child's play , Don't know where you stuck in logic

Note: I have added First object manually in 04/12/2017 07:10:41 to test the logic

var datesFromDBArray = ["04/12/2017 07:10:41", "04/12/2017 07:12:17", "04/12/2017 07:13:54", "04/12/2017 07:17:45", "04/12/2017 07:18:56", "05/12/2017"]
var ActionsDBArray = ["1", "6", "1", "1", "1", "2", "2", "2", "4", "1", "5", "2", "3"]
var TotalDaysServerArray = ["04/12/2017 11:59:59","22/11/2017 11:59:59", "23/11/2017 11:59:58", "24/11/2017 11:59:57"]

let findingValue =  TotalDaysServerArray.first!

print(findingValue)


let index = datesFromDBArray.index { (string) -> Bool in
    string.components(separatedBy: " ").first == findingValue.components(separatedBy: " ").first
}
print(index)



if let i = index {
    print("Your Object in ActionsDBArray \(ActionsDBArray[i])")
 }

Output :
04/12/2017 11:59:59

Optional(0)

Your Object in ActionsDBArray 1

Hope it is helpful to you

2 Comments

Where can you able to fetch data from ActionsDBArray?, here it would be multiple values fetching not a single value.
You have index 0 , Now you can get object at index 0 , That's what you are asking right ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.