|
Hey all, Regarding the challenge at the end of Project 1 of UIKit, Attempting to sort the array my files in ascending order but Swift fails to build, can anyone see where I'm going wrong?
The code in comments where it's not working is for my own benefit so I don't lose track. it builds successfully but when you run the app in the sim, it's still displaying the files in the order I've said! |
|
So I tried:
But this fails to build, I'm trying to run a few sims in Playground but no success |
|
With infered type, this works when I print it out:
But that's it so far, unsure how to alter the contents of FileManager so it's displayed how I wish to |
|
hi, i'm not sure what your picturesArray is doing, because you define it; you attempt to sort it (the closure you attempted give for the sort is suspicious); but you never use it. the UITableView is driven by the pictures array and does not depend on picturesArray. just add a .sorted() function call on the items in the for loop that appends the filenames to the pictures array (then, deep-six what you call picturesArray):
alternatively, just sort the pictures array after it is flled with filenames:
that should do it. hope that helps, DMG |
|
Hey @delawaremathguy I've just added that line into the pictures load IF statement before I saw this and bloody hell it works, can't believe it's that simple! I feel like a fool! |
|
hi, please do not worry about feeling foolish -- not only do i do something pretty silly every day, but i fully expect that i'll do something silly every day. the trick is to think it out a little and learn from it. that's what makes each of us better at this stuff. good luck going forward, DMG -- |
SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.