Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
James Lambert
Courses Plus Student 14,477 PointsWhat happened to the archiving stuff in Swift 2.0? I can't use stringByAppendingPathComponent any more?
Real problem. Just updated my Xcode and now it's telling me I need to use URLByAppendingPathComponent on NSURL instead of stringByAppendingPathComponent.
As my users progress through my app I am keeping track of their progress by archiving their progress and calling back to it as I need it.
The basic idea of the code is: let filemgr = NSFileManager.defaultManager() let dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true) let docsDir = dirPaths[0] as? String
dataFilePathDictionary = docsDir!.stringByAppendingPathComponent(dictionaryArchive)
if filemgr.fileExistsAtPath(dataFilePathDictionary!){ print("Loading the progressDictionary") userProgressDictionary = NSKeyedUnarchiver.unarchiveObjectWithFile(dataFilePathDictionary!) as! [Int: Int] }else { print("User Progress Dictionary Didn't Exist yet at File Path: (dataFilePathDictionary!)") userProgressDictionary = [ 0:0, 1: 0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0, 13:0, 14:0, 15:0, 16:0, 17:0] }
I was able to archive anything like a Dictionary, string, int, or what ever I needed. I sunk if I can't figure this out.
And yes, this exact code has been working for months. That is before I updated.
James Lambert
Courses Plus Student 14,477 PointsJames Lambert
Courses Plus Student 14,477 PointsThe answer: Remove the ? after the "as" and change the "String" to "NSString" Doing that makes everything work.