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

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -