Yesterday I installed the official Xcode 7 and when I tried to open one of my Swift projects, appeared an alert saying that the new Xcode version wants to update my swift co
unfortunately, I always has the same error as you are. I suggest the best way for you is recreating an new project by new Xcode and the transplant all the code to this new project, the problem will solve. By the way, after updating any place like framework or xcode, this error may be occur, the apple is stupid.
For me, the problem was changing how I check if something was false. Instead of:
if object1.hidden == false {
}
change to:
if object1.hidden != true {
}
In my case, the cast I had to correct was similar to Murat Yasar answer ( https://stackoverflow.com/a/36867502/512403 ), but mine had two parts to correct. The compiler didn't work with the original fix, so I had to tweak my code still a bit more:
Bad version:
let jsonObject: AnyObject? = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments)
Good version:
let jsonObject = try? NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments) as! [String: AnyObject]
Maybe this can help someone new to these quirks of Swift.
I was trying to write the NSData to file as following code.
if let currentResumeData = currentUserInfo["NSURLSessionDownloadTaskResumeData"]
{
// the following "do" was giving the above mentioned compile error.
do {
try currentResumeData.writeToFile(fileNameString, options: .DataWritingAtomic)
} catch {}
// the above error code.
}
After reading various answers on StackOverflow, I changed it as under, which removed the error.
if let currentResumeData:NSData = currentUserInfo["NSURLSessionDownloadTaskResumeData"] as? NSData {
{
do {
try currentResumeData.writeToFile(fileNameString, options: .DataWritingAtomic)
} catch {}
}
As you can see, compiler required proper NSData type of variable "currentResumeData" to call it's method .writeToFile.
I am sure, this will be helpful to others.
The error disappeared at the same time with the next version of Xcode. After some research on apple forums, there was a bug with that version of the "best" IDE ever, Xcode. Hopes that all the answers helped someone.
For me, the problem (XCode 7.3.1) was using a += operator on a dictionary item.
for example:
func test() {
var myDict:[String:String] = [:]
myDict["key"] = "pig"
myDict["key"] += "dog"
var myArray:[String] = []
myArray.append("pig")
myArray[0] += "dog"
}
This will cause a segmentation fault. Remove the += on myDict, and all is ok.
I am aware this is a bug (dictionary references are nullable) but the compiler should not crap out like this.