Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

init function is not being called

class Facts {

var networkOperaton = NetworkOperation(url: "http://fact.tayfunturanligil.com")
var factsArray : [String] = []

init () {

    self.networkOperaton.downloadJSONFromURL({

        (a:[String]) -> [String] in

        println(a)

        self.factsArray = a
        return a

        })

    }

in viewcontrooler i initilize Facts by var facts = Facts() but factsArray does not change and stays empty. (I know downloadJSONFromURL works)

1 Answer

Gabe Nadel
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Gabe Nadel
Treehouse Guest Teacher

A few questions:

1) Can you show us the code for the viewcontroller where you call: var facts = Facts() ?

2) If you place a breakpoint after the line "var facts = Facts()" what is the value of the variable facts?

3) If you place a breakpoint on this line: "self.networkOperaton.downloadJSONFromURL({" does the code stop there? The reason I ask this one, is that it's possible the init is being called, but your array just isn't being updated.