swift - Optional bindings and references -
swift - Optional bindings and references -
can somehow utilize optional binding references? if yes, how can it?
the next code sorts re-create of self.threadsinfo?.threads?, not original one.
if var threads = self.threadsinfo?.threads? { switch self.threadssorttype { case .score: threads.sort { $0.score > $1.score } case .views: threads.sort { $0.views > $1.views } case .postscount: threads.sort { $0.postscount > $1.postscount } default: assert(false, "unknown threads sort type") } } thanks in advance.
arrays value type beingness copied here:
var threads = self.threadsinfo?.threads? you can assign sorted array original:
if var threads = self.threadsinfo?.threads? { switch self.threadssorttype { case .score: threads.sort { $0.score > $1.score } case .views: threads.sort { $0.views > $1.views } case .postscount: threads.sort { $0.postscount > $1.postscount } default: assert(false, "unknown threads sort type") } self.threadsinfo?.threads = threads } swift
Comments
Post a Comment