One of my objects is an integer id, since it is a required asset I'm not defining it as an alternative I need it in the designated initial form:
square thing {var uniqueID: Int var name: String? Init (uniqueID: int) {self.uniqueID = uniqueID}}
Since I am making one of these from some JSON, it is used with the following:
if unique ID = dictionary ["id"]? <{P>
(I would like to have a prudent investigation on the way I have done so far).
Next, I would like to add the feature starter to the Thing class which accepts the dictionary object and sets the property accordingly. It contains the necessary uniqueID
and some other optional properties. My best effort is to:
feature init (dictionary: [string: onlinebase]) {if unique ID = Then give "[id"]? Int {self.init (uniqueID: uniqueID) // set other values here? } //or here? }
But of course this is not enough because the specified starter is not called on all the conditional conditionals.
How should I settle this scenario? Is this possible? Or should I accept that uniqueID
should be an alternative?
You have some options with one of the following:
Feature init? (Dictionary: [String: any object]) {If unique ID = "[id"], then? IT {self.init (uniqueID: uniqueID)} and {self.init (uniqueID: -1) returns blue}}
Technically this little hole (mainly your choice) / Swift's version), but my preferred preference is:
class func fromDictionary (dictionary: [string: onlinebase]) - & gt; Cheese? {If unique ID = dictionary ["id"], then? Int {Return Neal}
All together, as a playground:
square thing {var uniqueID: Int Var name: string? Init (uniqueID: int) {self.uniqueID = uniqueID} feature init? (Dictionary: [String: AnyObject]) {If unique ID = "[id"], then? Int {self.init (uniqueID: uniqueID)} and {self.init (uniqueID: -1) returns blue}} class func fromDictionary (dictionary: [string: anyObject]) - & gt; Cheese? {If unique ID = dictionary ["id"], then? INTTIF = Thing ("[id:"] / Pre>
No comments:
Post a Comment