这是xcode的错误抛出:
由于未捕获的异常'NSInvalidUnarchiveOperationException'而终止应用程序,原因:'*** - [NSKeyedUnarchiver decodeInt64ForKey:]:键的值(评级)不是整数'
这是创建Meal对象的类的一部分:
// MARK:属性
Run Code Online (Sandbox Code Playgroud)var rating: Int var name: String var photo: UIImage?// MARK:Path
Run Code Online (Sandbox Code Playgroud)static let DocumentDirectory = NSFileManager().URLsForDirectory(.DocumentDirectory, inDomains:.UserDomainMask).first! static let ArchivelUrl = DocumentDirectory.URLByAppendingPathComponent("meals")// MARK:NSCoding
Run Code Online (Sandbox Code Playgroud)func encodeWithCoder(aCoder: NSCoder) { aCoder.encodeObject(name, forKey: propertyKey.nameKey) aCoder.encodeObject(photo, forKey: propertyKey.photoKey) aCoder.encodeInteger(rating, forKey: propertyKey.ratingKey) } required convenience init?(coder aDecoder: NSCoder) { let name = aDecoder.decodeObjectForKey(propertyKey.nameKey) as! String let photo = aDecoder.decodeObjectForKey(propertyKey.photoKey) as? UIImage let rating = aDecoder.decodeIntegerForKey(propertyKey.ratingKey) //must call to designate initiallizer self.init(name: name,photo: photo,rating: rating) }
这是归档者和unarchiver:
// …
正如代码注释所要求的那样。我不知道为什么等待“continuation.Result”的主线程在打印出它的值之前有值。
static void Main(string[] args)
{
Task<string> antecedent = Task.Delay(5000).ContinueWith<string>(x =>
{
Console.WriteLine("return in task1 {0}", Thread.CurrentThread.ManagedThreadId);
return DateTime.Today.ToShortDateString();
});
Task<string> continuation = antecedent.ContinueWith(x =>
{
x.Wait(1000);
Console.WriteLine("return in task2 {0}{1}",Thread.CurrentThread.ManagedThreadId,x.Status);
return "Today is " + antecedent.Result;
});
Console.WriteLine("this will print before the result");
Console.WriteLine(continuation.Result); //why this waiting ?
Console.ReadKey();
}
Run Code Online (Sandbox Code Playgroud)