I am trying to initialize a deck of cards. I have card attributes in my card struct. My approach is to try and create an array of "enum states", then iterate through those to initialize each card. I am having trouble doing so.
Game Class
import Foundation
struct Set{
var cards = [Card]()
init(){
let properties : [Any] =
[cardShape.self, cardColor.self, cardNumber.self, cardShading.self]
for prop in properties{
// Not really sure how to iterate through this array...
// Ideally it would be something like this.
// Iterate through array, for property in array,
// card.add(property)
}
}
}
Card Class
import UIKit
import Foundation
struct Card{
var attributes : properties = properties()
mutating func addProperty(value : Property){
if value is cardShape{
attributes.shape = value as! cardShape
} else if value is cardColor{
attributes.color = value as! cardColor
} else if value is cardNumber{
attributes.number = value as! cardNumber
}else if value is cardShading{
attributes.shading = value as! cardShading
}else{
print("error")
}
}
}
protocol Property{
static var allValues : [Property] {get}
}
struct properties{
var shape : cardShape = cardShape.none
var color : cardColor = cardColor.none
var number : cardNumber = cardNumber.none
var shading : cardShading = cardShading.none
}
enum cardShape : String,Property{
case Square = "■"
case Triangle = "▲"
case Circle = "●"
case none
static var allValues : [Property]{ return [cardShape.Square,cardShape.Triangle,cardShape.Circle]}
}
enum cardColor:Property {
case Red
case Purple
case Green
case none
static var allValues : [Property] {return [cardColor.Red,cardColor.Purple,cardColor.Green]}
}
enum cardNumber : Int,Property{
case One = 1
case Two = 2
case Three = 3
case none
static var allValues : [Property] {return [cardNumber.One,cardNumber.Two,cardNumber.Three]}
}
enum cardShading: Property {
case Solid
case Striped
case Outlined
case none
static var allValues : [Property] {return [cardShading.Solid,cardShading.Striped,cardShading.Outlined]}
}
So to summarize, my main issue is trying to create an array of enums, then cycling through the enum states to initialize a card with specific attribute states.
You will want to make sure you cover all combinations of attributes and make sure each card has one of each of the four types of attributes. I would suggest using nested loops:
for shape in cardShape.allValues {
for color in cardColor.allValues {
for number in cardNumber.allValues {
for shading in cardShading.allValues {
var card = Card()
card.addProperty(shape)
card.addProperty(color)
card.addProperty(number)
card.addProperty(shading)
cards.append(card)
}
}
}
}
I believe your Card struct is a bit too complex. If you change your representation, it will be easier to create the cards.
Have your card represent the different attributes as their own property:
struct Card {
let shape: CardShape
let color: CardColor
let number: CardNumber
let shading: CardShading
}
Then use nested loops to create your cards:
for shape in CardShape.allValues {
for color in CardColor.allValues {
for number in CardNumber.allValues {
for shading in CardShading.allValues {
cards.append(Card(shape: shape, color: color, number: number, shading: shading))
}
}
}
}
Notes:
Your enums should start with uppercase characters, and your enum values should start with lowercase characters.
Using separate properties for each attribute will make it much easier to check for matching attributes between cards.
You get an initializer by default that initializes all properties. By initializing them with nested loops, you will be able to create all possible cards.
Change your allValues properties to return arrays of the specific attribute type (for example [CardShape]).
Alternate Answer:
Instead of using nested arrays, you could use MartinR's combinations function to create the list of combinations of the properties. Adding an init to Card that takes [Property], you can create the cards in two lines of code:
struct Card {
var shape = CardShape.none
var color = CardColor.none
var number = CardNumber.none
var shading = CardShading.none
init(properties: [Property]) {
for property in properties {
switch property {
case let shape as CardShape:
self.shape = shape
case let color as CardColor:
self.color = color
case let number as CardNumber:
self.number = number
case let shading as CardShading:
self.shading = shading
default:
break
}
}
}
}
// https://stackoverflow.com/a/45136672/1630618
func combinations<T>(options: [[T]]) -> AnySequence<[T]> {
guard let lastOption = options.last else {
return AnySequence(CollectionOfOne([]))
}
let headCombinations = combinations(options: Array(options.dropLast()))
return AnySequence(headCombinations.lazy.flatMap { head in
lastOption.lazy.map { head + [$0] }
})
}
struct SetGame {
let cards: [Card]
init(){
let properties: [Property.Type] = [CardShape.self, CardColor.self, CardNumber.self, CardShading.self]
cards = combinations(options: properties.map { $0.allValues }).map(Card.init)
}
}
How this works:
properties.map { $0.allValues } calls allValues on each item of the properties array creating an [[Property]] with [[.square, .triangle, .circle], [.red, .purple, .green], [.one, .two, .three], [.solid, .striped, .outlined]]
This is passed to combinations which creates a sequence with all 81 combinations of these properties: [[.square, .red, .one, .solid], ..., [.circle, .green, .three, .outlined]].
map is run on this sequence to call Card.init with each combination which results in an [Card] with 81 cards.
Related
Whilst attempting to create a set, I get the error stating "Cannot convert value of type '[Int]' to specified type 'Set'". This occurs even though I write the code exactly as in the DD: https://developer.apple.com/documentation/swift/set
var intSet2 : Set = [2, 3, 5, 7]
// Cannot convert value of type '[Int]' to specified type 'Set'
I have now switched to 'NSSet' (which I found by accidence) and now it appears to work. How come using normal 'Set' does not work? When I go to the DD of NSSet it says: "An object representing a static, unordered, uniquing collection, for use instead of a Set constant in cases that require reference semantics." Is this about reference types? The DD also states that arrays are value types. I'm at a loss as to when to use Set or NSSet (or even NSMutableSet for that manner).
var intSet2 : NSSet = [2, 3, 5, 7]
// Works
Lastly, when I try to convert an array of colors with type [CardColor] to a Set or NSset, I receive error message stating: "Cannot convert value of type '[CardColor]' to specified type 'NSSet'.
let colorCheck = selectedCards.map { $0.color }
var colorCheckSet : NSSet = colorCheck
// Cannot convert value of type '[CardColor]' to specified type 'NSSet'
Thanks for your help in advance.
Set model:
import Foundation
class Set {
// MARK: properties
var deck = [Card]()
var tableCards = [Card]()
var matchedCards = [Card]()
var selectedCards: [Card] {
get {
var cards = [Card]()
for card in tableCards.indices {
if tableCards[card].isSelected == true {
cards.append(tableCards[card])
}
}
return cards
}
}
var unmatchedCards = 12
var score = 0
// MARK: functions
// Selects the card. If this is the third card to be selected, proceeds to check for matches
func selectCard(at index: Int) {
if tableCards[index].isSelected == false {
if selectedCards.count < 3 {
tableCards[index].isSelected = true
if selectedCards.count == 3 {
checkIfCardsMatch()
}
}
}
else if tableCards[index].isSelected == true {
tableCards[index].isSelected = false
}
}
func checkIfCardsMatch() {
let colorCheck = selectedCards.map { $0.color }
var colorCheckSet : NSSet = colorCheck
// Cannot convert value of type '[CardColor]' to specified type 'NSSet'
var intSet2 : Set = [2, 3, 5, 7]
// Cannot convert value of type '[Int]' to specified type 'Set'
// for item in colorCheck {
// colorCheckSet.insert()
// }
// let symbolCheck: Set = selectedCards.map() { $0.symbol }
// let numberCheck: Set = selectedCards.map() { $0.number }
// let shadingCheck: Set = selectedCards.map() { $0.shading }
}
// MARK: functions
func dealThreeMoreCards() {
if unmatchedCards <= 21 {
unmatchedCards += 3
}
print(unmatchedCards)
}
//MARK: initialization
init() {
for cardcolor in CardColor.allCases {
for cardsymbol in CardSymbol.allCases {
for cardnumber in CardNumber.allCases {
for cardshading in CardShading.allCases {
let card = Card(initcolor: cardcolor, initsymbol: cardsymbol, initnumber: cardnumber, initshading: cardshading)
deck.append(card)
}
}
}
}
}
}
Card model:
import Foundation
struct Card {
var identifier: Int = 0
var isSelected = false
var color: CardColor
var symbol: CardSymbol
var number: CardNumber
var shading: CardShading
static var identifierFactory = 0
init(initcolor: CardColor, initsymbol: CardSymbol, initnumber: CardNumber, initshading: CardShading){
color = initcolor
symbol = initsymbol
number = initnumber
shading = initshading
Card.identifierFactory += 1
self.identifier = Card.identifierFactory
}
}
enum CardColor: Int, CaseIterable {
case red = 1
case green = 2
case purple = 3
// static let all = [cardColor.red, cardColor.green, cardColor.purple]
}
enum CardSymbol: Int, CaseIterable {
case ovals = 1
case squiggles = 2
case diamonds = 3
// static let all = [cardSymbol.ovals, cardSymbol.squiggles, cardSymbol.diamonds]
}
enum CardNumber: Int, CaseIterable {
case one = 1
case two = 2
case three = 3
// static let all = [cardNumber.one, cardNumber.two, cardNumber.three]
}
enum CardShading: Int, CaseIterable {
case solid = 1
case open = 2
case striped = 3
// static let all = [cardShading.solid, cardShading.open, cardShading.striped]
}
// Not every Card variable has been included below. Could cause issues later.
extension Card: Hashable {
static func == (lhs: Card, rhs: Card) -> Bool {
return lhs.identifier == rhs.identifier &&
lhs.isSelected == rhs.isSelected &&
lhs.color == rhs.color &&
lhs.symbol == rhs.symbol &&
lhs.number == rhs.number &&
lhs.shading == rhs.shading
}
func hash(into hasher: inout Hasher) {
hasher.combine(identifier)
hasher.combine(isSelected)
hasher.combine(color)
hasher.combine(symbol)
hasher.combine(number)
hasher.combine(shading)
}
}
I'm trying to print all the values from an object that inherits from a class, here is my example:
I create the class:
class Pokemon {
var name: String?
var type: String?
var level: Int?
var exp = 0.0
}
Create the object and assign some values:
var pikachu = Pokemon()
pikachu.name = "Pika Pika"
pikachu.level = 1
pikachu.type = "electricity"
pikachu.exp = 0
Now I would like to loop through all the pikachu object attributes and print the values. I'm thinking in a for each loop but I'm not sure how to implement it.
I know I can do something like this:
func printStats(pokemon: Pokemon) {
if pokemon.name != nil {
print(" name: \(pokemon.name!)\n level:\(pokemon.level!)\n type:\(pokemon.type!)\n exp: \(pokemon.exp!)")
}
}
printStats(pokemon: pikachu)
output:
name: Pika Pika
level:1
type:electricity
exp: 0.0
But I just want to loop through all values, instead of explicit writing every attribute in the function.
I found it the way of doing it:
let pokeMirror = Mirror(reflecting: pikachu)
let properties = pokeMirror.children
for property in properties {
print("\(property.label!) = \(property.value)")
}
output:
name = Optional("Pika Pika")
type = Optional("electricity")
level = Optional(1)
exp = Optional(0.0)
and if you want to remove the "Optional" just initialize the attributes.
Looks like a duplicate of Does Swift support reflection?
Alternatively, you can use a dictionary to store the attributes of Any? type.
e.g.
class Pokemon {
var attributes = [String:Any?]()
}
var pikachu = Pokemon()
pikachu.attributes["name"] = "Pika Pika"
pikachu.attributes["level"] = 1
pikachu.attributes["type"] = "electricity"
pikachu.attributes["exp"] = 0
func printStats(pokemon: Pokemon) {
pokemon.attributes.forEach { key, value in
if let value = value {
print("\(key): \(value)")
}
}
}
In Swift 5 you can create a new func in your class:
func debugLog() {
print(Mirror(reflecting: self).children.compactMap { "\($0.label ?? "Unknown Label"): \($0.value)" }.joined(separator: "\n"))
}
And then call it with MyObject().debugLog()
use Mirror API to get instance's properties
if you are developing iOS app, using NSObject, you may want to override description. Then can use print to print the instance.
A mirror describes the parts that make up a particular instance, such as the instance’s stored properties, collection or tuple elements, or its active enumeration case.
class YourClass: NSObject {
public override var description: String {
var des: String = "\(type(of: self)) :"
for child in Mirror(reflecting: self).children {
if let propName = child.label {
des += "\(propName): \(child.value) \n"
}
}
return des
}
}
let instance = YourClass()
print(instance)
see more in Reflection in Swift
I have an Avatar struct. This struct has properties called elements that hold several parts of the face like Eyes, Mouth and so on. In the init(withGender: AvatarGender) method. I want all these elements to have their default to zero.
But instead of having zeros I get huge random Ints. I can't figure out why!
struct Avatar {
var gender: AvatarGender
var skin: AvatarSkinColor
var elements: [AvatarElement: Int]
var rawString: String {
// a computed property
}
init(withGender: AvatarGender) {
gender = withGender
skin = .White
elements = [AvatarElement: Int]()
var allElementsType = [AvatarElement]()
if gender == .Man {
allElementsType = AvatarElement.allMaleValues
} else if gender == .Woman {
allElementsType = AvatarElement.allFemaleValues
}
for element in allElementsType {
elements[element] = 0 // <= This doesn't work !!!
}
}
init(fromRawString: String) {
// Another init method that works properly
}
}
Above AvatarGender, AvatarSkinColor and AvatarElement are enums.
I have a struct which represents a bitmap image in RGBA form. That struct has properties for each of the color channels, red, blue and green.
I'm trying to build an image filter which adjusts a particular color level. This version works fine, but clearly the pixel.COLOR property is hard coded.
func boostColor(inputColor: String) -> UIImage {
let avgColor = "avg" + inputColor
// let color = inputColor.lowercaseString // plan to use this to set the property
for y in 0..<self.inputRGBA.height {
for x in 0..<self.inputRGBA.width {
let index = y * self.inputRGBA.width + x
var pixel = self.inputRGBA.pixels[index]
// see how far this pixel's chosen color varies from the average
let colorDiff = Int(pixel.red) - Int(self.pixelColorAverages[avgColor]!)
// if less than average red,
if(colorDiff>0){
pixel.red = UInt8( max(0,min(255,Int(self.pixelColorAverages[avgColor]!) + colorDiff*100 ) ) )
// write the adjusted pixel back to the image object
self.inputRGBA.pixels[index] = pixel
}
}
}
// write the filtered RGBA image to a UIImage
return self.inputRGBA.toUIImage()!
}
This loop's function takes in a string value of either "red", "blue" or "green". What I would like to do is replace instances of
pixel.red
with
pixel.[ONE OF THE INPUT COLORS]
Thanks!
(This is an academic playground project. I realize I'm probably re-inventing the wheel by building a color filter. It isn't the color filter itself that I'm interested in, but how to solve this property problem in Swift.)
Here is the struct:
public struct Pixel {
public var value: UInt32
public var red: UInt8 {
get {
return UInt8(value & 0xFF)
}
set {
value = UInt32(newValue) | (value & 0xFFFFFF00)
}
}
public var green: UInt8 {
get {
return UInt8((value >> 8) & 0xFF)
}
set {
value = (UInt32(newValue) << 8) | (value & 0xFFFF00FF)
}
}
public var blue: UInt8 {
get {
return UInt8((value >> 16) & 0xFF)
}
set {
value = (UInt32(newValue) << 16) | (value & 0xFF00FFFF)
}
}
public var alpha: UInt8 {
get {
return UInt8((value >> 24) & 0xFF)
}
set {
value = (UInt32(newValue) << 24) | (value & 0x00FFFFFF)
}
}
}
Implementing Key Value Coding is possible with reflecting but it is very un-Swift. In your case it is also just a bad idea since there are much more powerful and useful alternatives.
I would go for an OptionSetType since there are only a fixed number of possibilities (RGBA). An enum would be fine too but an OptionSetType has the extra benefit of being a "set". So you can choose to alter RGB and not A in a very convenient way.
interesting read on OptionSetType
This is an enum to store the rawValues for the OptionSetType. Can be used on it's own.
public enum RGBAColor : Int, CustomStringConvertible {
case Red = 1, Green = 2, Blue = 4, Alpha = 8
public var description : String { // if you still want to have a String value for each color
var shift = 0
while (rawValue >> shift != 1) { shift++ }
return ["Red","Green","Blue","Alpha"][shift]
}
}
This is the OptionSetType. I create snippets of these kind of structures and copy / paste / modify them when needed. No need to reinvent the wheel when it will always be the same pattern.
public struct RGBAColors : OptionSetType, CustomStringConvertible {
public let rawValue : Int
public init(rawValue:Int) { self.rawValue = rawValue}
private init(_ color:RGBAColor) { self.rawValue = color.rawValue }
static let Red = RGBAColors(RGBAColor.Red)
static let Green = RGBAColors(RGBAColor.Green)
static let Blue = RGBAColors(RGBAColor.Blue)
static let Alpha = RGBAColors(RGBAColor.Alpha)
public var description : String {
var result = ""
var shift = 0
while let currentcolor = RGBAColor(rawValue: 1 << shift++){
if self.contains(RGBAColors(currentcolor)){
result += (result.characters.count == 0) ? "\(currentcolor)" : ",\(currentcolor)"
}
}
return "[\(result)]"
}
}
Now you can add a function to your Pixel struct that will return the color value based on an enum case. You can also choose to pass the OptionSetType directly to this function.
public struct Pixel {
...
public func getValueForColor(color:RGBAColor) -> UInt8 {
switch color {
case .Red : return self.red
case .Green : return self.green
case .Blue : return self.blue
case .Alpha : return self.alpha
}
}
}
This is just a control flow function. You can now do different things based on which color that needs to be altered. (or apply the same to all)
This is also the only reason to choose for an OptionSetType, if you don't need this, just go for an enum. Since the OptionSetType builds on the enum you can always add it later.
func someFuncWithOptions(colors:RGBAColors) {
if colors.contains(.Red) {
someFunc(.Red)
}
if colors.contains(.Blue) {
someFunc(.Blue)
}
if colors.contains(.Green) {
someFunc(.Green)
}
if colors.contains(.Alpha) {
someFunc(.Alpha)
}
}
This will be your actual function
func someFunc(color:RGBAColor) {
// do something with pixel.getValueForColor(color)
print(color)
}
This will be exposed to other parts of your code. So the actual usage of all this will be really simpel. Just input .SomeColor.
The best thing is that the compiler will warn you if you change all this to CMYK for example. Key Value Coding will never generate warnings, it will just crash.
Because it is a "set" and not per definition one color, you pass a collection of options. [.option1,.option2,...] or you pass nothing []
someFuncWithOptions([.Red]) // red
someFuncWithOptions([.Green,.Red]) // red green
You can also add convenient collections to the OptionSetType. This one will be a set of all RGB colors but without the Alpha channel.
static let RGB : RGBAColors = [.Red,.Green,.Blue]
someFuncWithOptions([.RGB]) // red blue green
One approach would be to add a KVC-like syntax to Swift using Swift's built-in reflection capabilities. You can learn how to do that here, although it's serious overkill for this problem:
http://blog.shiftybit.net/2015/07/kvc-in-swift/
A more narrow and suitable solution would just be to write a function for your struct that takes a String argument, switches over it, and returns the desired value. You'd also want to write another function for your struct that takes a String and a value, and sets the value on your struct.
Examples:
struct Pixel
{
// ... rest of struct definition ...
func getColor(color:String) -> UInt8
{
switch color
{
case "red":
return self.red
case "green":
return self.green
case "blue":
return self.blue
case "alpha":
return self.alpha
}
}
func setColor(color:String, value:UInt8)
{
switch color
{
case "red":
self.red = value
case "green":
self.green = value
case "blue":
self.blue = value
case "alpha":
self.alpha = value
}
}
}
If you wanted, you could take it a step further and use an enum instead of a String for improved clarity and type safety.
If you want to pass the color name as string, why don't you define a subscript for your structure? It's awesome and very flexible.
Classes, structures, and enumerations can define subscripts, which are shortcuts for accessing the member elements of a collection, list, or sequence. You use subscripts to set and retrieve values by index without needing separate methods for setting and retrieval.
struct Pixel {
// ...
subscript(color: String) -> UInt8? {
get {
switch color {
case "red":
return red
case "green":
return green
case "blue":
return blue
case "alpha":
return alpha
default:
return nil
}
}
set {
if newValue != nil {
switch color {
case "red":
red = newValue!
case "green":
green = newValue!
case "blue":
blue = newValue!
case "alpha":
alpha = newValue!
default:
break
}
}
}
}
}
var pixel = Pixel(value: 0)
pixel["red"] = 128
Note that it will fail silently in case a wrong color is set like in pixel["yellow"] = 155. To avoid situations like that you could implement a enum and use it as key.
enum Color {
case Red
case Green
case Blue
case Alpha
}
extension Pixel {
subscript(color: Color) -> UInt8 {
get {
switch color {
case .Red:
return red
case .Green:
return green
case .Blue:
return blue
case .Alpha:
return alpha
}
}
set {
switch color {
case .Red:
red = newValue
case .Green:
green = newValue
case .Blue:
blue = newValue
case .Alpha:
alpha = newValue
}
}
}
}
var pixel = Pixel(value: 0)
pixel[.Red] = 128
I am learning Swift and am writing a basic card game init function where I want to use a function to setup some decks.
Swift keeps complaining that I'm missing an argument in parameter #1, but there aren't any parameters, nor am I wanting any.
Game class is as follows
class Game
{
// MARK: ** Private vars **
private var gameState: GameState?
private var playerOnTurn: Player?
private var seedCash:Int?
// MARK: ** Public vars **
lazy var players = [Player]()
var chequesDeck:Deck = Deck()
var propertiesDeck:Deck = Deck()
init()
{
self.gameState = .Initialize
self.playerOnTurn = nil // No player on turn when game is initialized
self.seedCash = kInitialSeedCash
}
func setup(numberOfPlayers:Int)
{
// Create decks of properties and cheques
self.propertiesDeck = Deck.createProperties()
self.chequesDeck = Deck.createCheques()
}
}
Deck class is as follows
// Deck of cards
// Two deck types in the game - (1) Properties & (2) Cheques
class Deck
{
private var cards:[Card] = [] // Empty Array
// #return: An array of cards
func createProperties() -> [Card]
{
var propertyDeck:[Card] = []
// TODO: - Needs Local JSON reader
let prop1 = Card.init(name:"Cardboard box", value:1)
propertyDeck.append(prop1)
let prop2 = Card.init(name:"Outhouse", value:2)
propertyDeck.append(prop2)
let prop3 = Card.init(name:"Outhouse", value:3)
propertyDeck.append(prop3)
return propertyDeck
}
// #return: An array of cards
func createCheques() -> [Card]
{
var chequeDeck:[Card] = []
// create 2 copies of each card, but skip 1s
for var i:Int = 0; i<=15; i++
{
if (i != 1)
{
let chequeCard = Card.init(name: "Cheque", value: i * 1000)
chequeDeck.append(chequeCard)
}
}
return chequeDeck
}
func addCard()
{
}
func shuffle()
{
}
}
Deck() is a class
func setup() {
var propertiesDeck:Deck = Deck()
// Create property deck
self.propertiesDeck = Deck.createProperties()
}
// Deck.createProperties file
// #return: An array of cards
func createProperties() -> [Card]
{
var propertyDeck:[Card] = []
let prop1 = Card.init(name:"Penthouse", value:1)
propertyDeck.append(prop1)
return propertyDeck
}
But Swift keeps complaining that;
Missing argument for parameter #1 in call
But there aren't any arguments or parameters.
Perhaps I'm doing something wrong/silly?
This error would generally say that Deck is expecting some constructor parameters. Could you please post your Deck class so I can see if there are any?
Also some more suggestions. You seem to be creating the Deck variable propertiesDeck, but then statically accessing createProperties by stating Deck.createProperties(). Should you not be calling propertiesDeck.createProperties()? Also createProperties is returning an Array of the Card object, but propertiesDeck is a Deck class.
Since you're accessing your function like this:
Deck.createProperties()
you probably want a static method instead:
static func createProperties() -> [Card] {
...
}
Which shouldn't give you an error anymore.
Another way to make it work is by calling createProperties() on your already defined Deck like this (not recommended):
self.propertiesDeck = propertiesDeck.createProperties()
The reason for the missing parameter comes from the fact that methods take the class instance as their first parameter, so you could actually call it like Deck.createProperties(propertiesDeck)().
I believe you've got some other flaws in your code, I will try to make a better example for you:
struct Card {
let name : String
let value : Int
}
class Deck {
var cards : [Card]
init() {
cards = [
Card(name: "Penthouse", value: 1)
]
}
}
Try This,
func createProperties() -> [Card]
{
var propertyDeck:[Card] = []
let prop1 = Card(name:"Penthouse", value:1)
propertyDeck.append(prop1)
return propertyDeck
}
If this does not works then show the code for the class Deck and Card.
We can't answer your question without the complete code. We need the code of your Deck class.
But you can try class funcs...
public class Cards {
class func createProperties() -> [Card]
{
var propertyDeck:[Card] = []
let prop1 = Card.init(name:"Penthouse", value:1)
propertyDeck.append(prop1)
return propertyDeck
}
}
You can call the function with:
Cards.createProperties()