Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import UIKit
class Content
{
var name:String = "DEFAULT"
func setup(_ name:String)
{
self.name = name
}
}
class ContentCollection
{
var array:[Content] = []
}
func printContent(_ contentArray:[Content])
{
for content in contentArray
{
print("content.name \(content.name)")
}
}
var contentCollections:[ContentCollection] = []
let collection1 = ContentCollection();
let collection2 = ContentCollection();
contentCollections.append(collection1)
contentCollections.append(collection2)
var words:[String] = ["is", "this", "copied"]
var array:[Content] = []
for word in words
{
let content = Content();
content.setup(word)
array.append(content)
}
for contentCollection in contentCollections
{
contentCollection.array = array
}
print("ARRAY1")
printContent(contentCollections.first!.array)
print("ARRAY2")
printContent(contentCollections.last!.array)
var omg = Content();
omg.setup("omg")
//contentCollections.first!.array.append(omg) <-kill me
contentCollections[0].array.append(omg)
print("ARRAY1")
printContent(contentCollections.first!.array)
print("ARRAY2")
printContent(contentCollections.last!.array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment