小编del*_*los的帖子

xcode NSInvalidUnarchiveOperationException,当尝试unarchive文件时

这是xcode的错误抛出:

由于未捕获的异常'NSInvalidUnarchiveOperationException'而终止应用程序,原因:'*** - [NSKeyedUnarchiver decodeInt64ForKey:]:键的值(评级)不是整数'

这是创建Meal对象的类的一部分:

// MARK:属性

var rating: Int
var name: String
var photo: UIImage?
Run Code Online (Sandbox Code Playgroud)

// MARK:Path

static let DocumentDirectory = NSFileManager().URLsForDirectory(.DocumentDirectory, inDomains:.UserDomainMask).first!

static let ArchivelUrl = DocumentDirectory.URLByAppendingPathComponent("meals")
Run Code Online (Sandbox Code Playgroud)

// MARK:NSCoding

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)
}
Run Code Online (Sandbox Code Playgroud)

这是归档者和unarchiver:

// …

xcode ios

3
推荐指数
2
解决办法
3790
查看次数

.Net 中的多任务

正如代码注释所要求的那样。我不知道为什么等待“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)

.net c# multithreading multitasking

-2
推荐指数
1
解决办法
40
查看次数

标签 统计

.net ×1

c# ×1

ios ×1

multitasking ×1

multithreading ×1

xcode ×1