I have the following code:
var path = NSIndexPath(forRow: index, inSection:0);
and I get a compiler warning saying:
Extra Argument 'inSection' in call
Why? I see the initializer in the documentation here:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/NSIndexPath_UIKitAdditions/index.html#//apple_ref/occ/clm/NSIndexPath/indexPathForRow:inSection:
I imported UIKit, and even tried doing something like:
var path = UIKit.NSIndexPath(forRow: index, inSection:0);
What am I misunderstanding here?
EDIT:
var index = 0;
        for (key, value) in map! {
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), { (index) in
                //some code
                dispatch_async(dispatch_get_main_queue(), { (index) in
                    println("reloadRow row=" + String(index) + ",inSection:0");
                    var path = NSIndexPath(forRow: index, inSection:0);
                    self.tableView.reloadRowsAtIndexPaths([path], withRowAnimation: UITableViewRowAnimation.Automatic);
                });
            });
            index++;
        }
                index may not be recognized by the compiler. Try the code in playground:
import UIKit
let index = 3
var path = NSIndexPath(forRow: index, inSection: 0)
Works
import UIKit
var path = NSIndexPath(forRow: index, inSection: 0)
Error: Extra Argument 'inSection' in call
It means that your index variable is not well defined. Or you should try to Clean and delete the derived data.
Edit:
Remove the index declaration in your dispatch_async it conflicts with your index variable.
dispatch_async(dispatch_get_main_queue(), { _ in
                    println("reloadRow row=" + String(index) + ",inSection:0");
                    var path = NSIndexPath(forRow: index, inSection:0);
                    self.tableView.reloadRowsAtIndexPaths([path], withRowAnimation: UITableViewRowAnimation.Automatic);
                });
Bonus: You should use Swift nice shortcuts with closures. (trailing closure + no parameters) as it:
dispatch_async(dispatch_get_main_queue()) {
       println("reloadRow row=" + String(index) + ",inSection:0");
       var path = NSIndexPath(forRow: index, inSection:0);
       self.tableView.reloadRowsAtIndexPaths([path], withRowAnimation: UITableViewRowAnimation.Automatic);
    }
Edit:  you do the same mistake in the first dispatch async. When you declare a dispatch_async and you write { index in it's the same thing as declaring a function with an index as a parameter. It's a variable scope issue (you should read about this). I update the final code.
    var index = 0
    for (key, value) in map! {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) {
            //some code
            dispatch_async(dispatch_get_main_queue()) {
                println("reloadRow row=" + String(index) + ",inSection:0");
                var path = NSIndexPath(forRow: index, inSection:0);
                self.tableView.reloadRowsAtIndexPaths([path], withRowAnimation: UITableViewRowAnimation.Automatic);
            }
        }
        index++
    }
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With