Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如何在swift中比较json值_Arrays_Json_Swift - Fatal编程技术网

Arrays 如何在swift中比较json值

Arrays 如何在swift中比较json值,arrays,json,swift,Arrays,Json,Swift,如何比较json数组值?我不懂逻辑 我需要在tableView中显示加密货币的价格变化(增加或减少),同时从服务器更新数据 据我所知,我必须创建两个数组:一个用于旧值,另一个用于新值,以及用于比较的函数,其中两个数组最初应该相等。接下来我该怎么办?我的方向对吗 var currencies = [Cryptocurrency]() var newCurrencies = [Cryptocurrency]() 我正在通过NSNotificationCenter获取数据数组。我应该在这里换些东西吗

如何比较json数组值?我不懂逻辑

我需要在tableView中显示加密货币的价格变化(增加或减少),同时从服务器更新数据

据我所知,我必须创建两个数组:一个用于旧值,另一个用于新值,以及用于比较的函数,其中两个数组最初应该相等。接下来我该怎么办?我的方向对吗

var currencies = [Cryptocurrency]()
var newCurrencies = [Cryptocurrency]()
我正在通过NSNotificationCenter获取数据数组。我应该在这里换些东西吗

NotificationCenter.default.addObserver(self, selector: #selector(getCurrencies), name: Notificator.getCurrencyNotification, object: nil)

@objc func getCurrencies(notification: Notification) {

            if let receivedCurrencies = notification.object as? [Cryptocurrency] {

                self.currencies = receivedCurrencies
                AnimatableReload.reload(tableView: tableView, animationDirection: "up")

                }
            }


func showPriceChanges() {

        currencies = newCurrencies
        ?
    } 

不清楚问题是什么,在我看来,你需要将每种货币的价值与同一种货币的旧价值进行比较是的。至于现在,我只能在tableView(货币数组)中显示这些数据,并用UIBarButtonItem更新它们。如果到目前为止我只有一个数组(货币),我无法理解如何比较价格值。我想这样比较两个价格,但这是错误的:(你认为如何?我认为你需要改进你的问题,而不是发布代码图像的链接。改为将代码添加到问题中(作为文本)。