17

When you’ve been stuck on the same issue with your code for 4 days šŸ˜”

Comments
  • 2
    What type of issue are we talking about? I know iOS development, if its Swift, maybe I can at least help narrow down the issue
  • 2
    @gitpush so I’m using Alamofire for networking for the first time. I can get the JSON fine and even get the code to print to console. But I can’t get the data to store to a dictionary so I can display it in a table. I tried printing the dictionary and it’s coming back nil every time. So naturally when I try to load the tableview with the data it crashes because of the nil value. The data I’m trying to get is an array or dictionaries nested in a JSON object. Sorry for the long explanation lol
  • 0
    lol just press the "fix my bug" button
  • 2
    @IMDownerzac Why don't you use SwiftyJSON, I too use Alamofire, and when I receive my JSON string using responseJSON function, I simply do:

    switch(alamofireResult.result)
    {
    case .success(let val):
    let jsonValue = JSON(val)
    // jsonValue is now a SwiftyJson Object
    // You can get your data as: jsonValue["myVar"].dictionary <-- is an optional
    break
    case .failed(let error):
    print(error.localizedDescription)
    }

    SwiftyJson github link: https://github.com/SwiftyJSON/...
  • 2
    I was trying SwiftyJSON but it isn’t helping (edit: at this point I was just trying to get it into an array, which it did and printed but still wouldn’t load into the table)
  • 2
    @IMDownerzac is your condition valid? I mean is arr count > 0?
    if yes, what does your UITableViewDataSource read from?
    When you implement:
    numberOfRowsForSection
    and cellForRowAtIndex
    which array are they reading from?
  • 2
    @gitpush this is the table source. Next comment will be where t fails every time
  • 2
  • 2
    @IMDownerzac it is failing to get a reference of your table, did you connect it from StoryBoard to your ViewController? is your IBOutlet nil? From the place where it is failing I can only think of tableView being nil
  • 2
    @IMDownerzac if it was because your array is nil, it will fail when it is accessing the array in this case in cellForRowAtIndex and numberOfRowsInSection
  • 2
    And if your IBOutlet is not nil, have you set UITableViewDataSource and UITableViewDelegate of your UITableView?
    (right click + drag from your UITableView in storyboard to the FileOwner object (yellow icon on top of the view in storyboard, it is the left most icon)
  • 2
    @gitpush both are connected
  • 2
    @IMDownerzac but Referencing Outlet is nil, this is your issue, you need to connect your UITableView to your view controller,
    Open both your storyboard and viewcontroller side by side, right click + drag your UITableView to your ViewController code, and create a reference
    the resulting code of the reference should be:

    @IBOutlet weak var NAME: UITableView!
  • 2
    @gitpush so it was in my VC, but not my storyboard?
  • 2
    @IMDownerzac On the left of the code page, there should be a circle is it an empty circle or a filled circle?
    if empty then it is not connected to anything if a filled circle then check to which tableView it is connected
  • 3
    @gitpush it was filled in but linked to another tableview on a different view (not sure how it happened) but I deleted it and reworked it and now the code runs. You are a genius! Thank you so much!!!
  • 4
    @IMDownerzac Great happy I was being able to help :D
    Good luck on your project :))
  • 3
    Ah, this is one of the reasons why I love devRant (unlike SO), haha
  • 3
    @hacker yup true spirit of devRant :D
  • 3
  • 2
    Hello brother from another background color mother
  • 1
    More ++ for everyone for this great rant :)
Add Comment