0

first time here. I'm a beginner student at swift (and programming in general) and I'm trying to make a simple app which will show 5 time values based on current day. I've tried a lot of stuff, but just cannot develop logic here. I will copy paste code (which some of it is pseudocode).

import UIKit

class ViewController: UIViewController {

// TIME Values
let time1 = ["07:01", "07:03", "07:03"] // ..... Array continues for 365 days, every string value representing each day
let time2 = ["11:59", "11:59", "12:00"] // ..... Array continues for 365 days, every string value representing each day
let time3 = ["14:15", "14:16", "14:17"] // ..... Array continues for 365 days, every string value representing each day
let time4 = ["17:12", "17:13", "17:15"] // ..... Array continues for 365 days, every string value representing each day
let time5 = ["19:10", "19:11", "19:12"] // ..... Array continues for 365 days, every string value representing each day

// Current Date
let todaysDate = NSDate()



// Pseudocode to extract the value from time arrays...
choose a value from TIME Values based on todaysDate
print(time1) // single value from time1 array (converted from string to date/time value) based on todaysDate
print(time2) // single value from time1 array (converted from string to date/time value) based on todaysDate
print(time3) // single value from time1 array (converted from string to date/time value) based on todaysDate
print(time4) // single value from time1 array (converted from string to date/time value) based on todaysDate
print(time5) // single value from time1 array (converted from string to date/time value) based on todaysDate

// Final values should be NSDate (or similar) values, because of time manipulation
let timeCorrection1 = ["00:02", "00:03", "00:03"] // ..... Correction continues for 365 days, every string value representing each day
let timeCorrection2 = ["00:02", "00:03", "00:03"] // ..... Correction continues for 365 days, every string value representing each day
let timeCorrection3 = ["00:02", "00:03", "00:03"] // ..... Correction continues for 365 days, every string value representing each day
let timeCorrection4 = ["00:02", "00:03", "00:03"] // ..... Correction continues for 365 days, every string value representing each day
let timeCorrection5 = ["00:02", "00:03", "00:03"] // ..... Correction continues for 365 days, every string value representing each day

override func viewDidLoad() {
    super.viewDidLoad()

}

}

So the idea is to get a value from a string array based on currentdate, and have that in nsdate format (in MM:hh style) so it can be manipulated later, since I would like to subtract or add values from other variables (ie 00:02).

I hope I was clear enough, thank you very much in advance!

Mirza
  • 1
  • Possible duplicate of [Converting NSString to NSDate (and back again)](http://stackoverflow.com/questions/3917250/converting-nsstring-to-nsdate-and-back-again) – techloverr Mar 22 '16 at 12:35
  • Hi, thank you for your answer. Could you please be a little bit more specific? Thanks. – Mirza Mar 22 '16 at 12:47
  • refer the link given – techloverr Mar 22 '16 at 12:50
  • @Mirza looks like all you need is to find out the day of year and use it as the index to extract your array item. http://stackoverflow.com/a/33288119/2303865 – Leo Dabus Mar 22 '16 at 12:57
  • 1
    Leo - Thank you so much, that is exactly what I was try to figure out for quite some time! Thanks!!! – Mirza Mar 22 '16 at 13:10

0 Answers0