0

I have the following structure:

struct Subject{
let subjectId : String
let subjectName : String
let room : String
let startTime : String
let endTime : String
}

And an array containing the following data

var subjects = [Subject(subjectId: "xQsfz", subjectName: "Math", room: "Room 10", startTime: "10:20", endTime: "11:20"),Subject(subjectId: "yHsPz", subjectName: "Physics", room: "Room 5", startTime: "9:10", endTime: "10:19")]

How do I sort the array subjects by "startTime"?

I find it quite difficult because the startTime is of type String (due to the fact that it cant be Integer), every kind of help is appreciated!

Omar Dlhz
  • 158
  • 12
  • check the following question : http://stackoverflow.com/questions/24781027/how-do-you-sort-an-array-of-structs-in-swift –  Feb 17 '15 at 22:29
  • @texas that question wont work because the data type is integer in that case, in my case the startTime is a String, which cant be sorted numerically. – Omar Dlhz Feb 17 '15 at 22:30
  • Find my answer below. –  Feb 17 '15 at 22:32

0 Answers0