TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

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      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

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.