PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 5, 2022

[FIXED] How to pass structure by reference?

 July 05, 2022     pass-by-reference, struct, swift     No comments   

Issue

If I have some existing struct, but I want to use "Reference" behavior, how do I achieve that?

I can write some simple class-holder like

class Box<T> {
    var value: T
    init(_ value: T) {
        self.value = value
    }
}

I guess there must be ready class in the standard library, but I didn't find it.

I want to store that reference in my class, so inout parameter isn't what I need.


Solution

For me the best variant was using class-holder:

class Ref<T> {
  var value: T

  init(_ value: T) {
    self.value = value
  }
}


Answered By - vbezhenar
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing