1

The following code produces a runtime error and I can't figure out how. Any thoughts?

    var foo: IndexPath
    foo = IndexPath()
    foo.row = 1

    var i = 0

enter image description here

0

1 Answer 1

1

There is a preCondition in swift to access row of indexpath

/// The section of this index path, when used with `UITableView`.
///
/// - precondition: The index path must have exactly two elements.
public var section: Int

/// The row of this index path, when used with `UITableView`.
///
/// - precondition: The index path must have exactly two elements.
public var row: Int

enter image description here

If you want to access or change row you need to initialise indexPath with row and section

 var foo: IndexPath
 foo = IndexPath(row: 0, section: 0)
 foo.row = 1 // return foo (1,0)
Sign up to request clarification or add additional context in comments.

2 Comments

How were you able to step into the IndexPath source? When I try to step in I don't get the nice source view that you get.
when I do that, I just get assembly code: libswiftUIKit.dylib`merged (extension in UIKit):Foundation.IndexPath.section.setter : Swift.Int: 0x1022b22c0 <+0>: pushq %rbp 0x1022b22c1 <+1>: movq %rsp, %rbp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.