Questions tagged [inout]

98 questions
0
votes
1 answer

How do you pass a chunk of an array to an inout function? Type-erasure?

I have a function func doThing(inout array: [Int]) { //thing } I have the array var stuff = [0,1,2,3,4,5,6] I want doThing to operate on just the first three elements. doThing(&stuff[0..<3]) doesn't work since var partOfStuff: ArraySlice =…
lanza
  • 1,512
  • 2
  • 13
  • 26
0
votes
1 answer

Use the inout keyword when passing an NSManagedObjectContext into a function?

I'm working on my first real Core Data application and have been able to successfully pass the pointer to my managedObjectContext instance throughout my application using segues. I've run into a question however as I am at a crossroad where I need…
Dan Beaulieu
  • 19,406
  • 19
  • 101
  • 135
0
votes
1 answer

How to set a Inout parameter inside a closure

So my question is this: I'm trying to implement a extension to CLGeoCoder to be able to get a city name from a CLLocation but I'm facing a problem when I try to set the inout city name string inside the completionhandler of the…
Martin
  • 843
  • 8
  • 17
0
votes
2 answers

How to modify a two dimensional array passed to a function?

My function is as following func helper(root: TreeNode?, _ result: [[Int]], _ list: [Int], _ sum: Int, _ total: Int) { list.append(root!.val) if(total + root!.val == sum && root?.left == nil && root?.right == nil) { …
Xuting
  • 1
  • 1
-1
votes
1 answer

Swift inherited protocols sent to functions as inout

The code below does not compile. I am trying to send a class to a function that changes that class, where the class conforms to a protocol. This protocol inherits from another base protocol. I would expect the compiler to know that s (SportsCar)…
-1
votes
2 answers

Inout vs pass by reference swift optimization

I have a very large list of numbers and I would like to pass it to a function to do some manipulations to it. Originally, I created a function with an inout property. As many know, inout in swift does NOT pass by reference, rather it makes an…
EK_AllDay
  • 1,095
  • 2
  • 15
  • 35
-2
votes
1 answer

How to write columnwise in FORMAT in FORTRAN 77

I am using FORTRAN77 as a third party language on ANSYS computation software. Here we can write the entire row and columns to files during I/O operations. I am not able to however move the cursor to the first row and write column wise thereafter-…
Vikram
  • 1
  • 1
-4
votes
1 answer

"&" in "swap(&someInt, &anotherInt)". What does it represent? What is its function?

I'm new to Swift and I'm trying to learn the concept of 'inout' keyword. I saw this code in "the swift programming language 2.1". My question is, why is there a "&" in "swap(&someInt, &anotherInt)". What does it represent? What is its function? func…
Thor
  • 9,638
  • 15
  • 62
  • 137
1 2 3 4 5 6
7