UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Passing by Reference

Forums > Swift

I'm new to swift and have been trying to figure out how to pass by reference to populate my JSON data structure. Here is the scenario that is not working.

class faxioPrefs {

    var faxioDict = [
    "To": "",
    "From": "",
    "Regarding": "",
    "Cell": "",
    "NumPages": "",
    "Comments": "",
    "FaxNumber": ""]

    init() {

    }

}

// Initiate instance of class
let prefjson = faxioPrefs()

// Read the faxio.json file and use JSONSerialization to populate the dictionary of data
status = readJSON(dict: prefjson.faxioDict, prefsFile: "faxio.json") as! [String : String]

I started by using a struct but then read that structs are always passed by value so I switched to a class. My question is should this work?

Thanks,

Brian

2      

I believe what you are looking for is an inout parameter. https://www.hackingwithswift.com/sixty/5/10/inout-parameters

2      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.