我的用户界面中有标签,它们始终显示为“可选(xxxxxxx)”。我该怎么解决?
在这里,我从JSON数据生成本地对象:

func populateCurrentIssue() {
    if populatingCurrentIssue {
        return
    }

    populatingCurrentIssue = true

    Alamofire.request(GWNetworking.Router.Issue).responseJSON() { response in
        if let JSON = response.result.value {

            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)) {

                var nodeIDArray : [Int]

                if (JSON .isKindOfClass(NSDictionary)) {

                    for node in JSON as! Dictionary<String, AnyObject> {

                        let nodeIDValue = node.0
                        var lastItem : Int = 0

                        if let issueElement : IssueElement = IssueElement(title: "init", nodeID: 0, timeStamp: 0, imageURL: "init", author: "init", issueNumber: "init", volumeNumber: "init", articleContent: "init", coverImageInteger: "init", coverImage: UIImage()) {

                            issueElement.title = node.1["title"] as! String
                            issueElement.nodeID = Int(nodeIDValue)!


                            issueElement.author = String(node.1["author"])

                            lastItem = self.currentIssueObjects.count


                            self.currentIssueObjects.addObject(issueElement)

                            // Sorting with decreasing timestamp from top to bottom.
                            let timestampSortDescriptor = NSSortDescriptor(key: "timeStamp", ascending: false)

                            let indexPaths = (lastItem..<self.currentIssueObjects.count).map {
                                NSIndexPath(forItem: $0, inSection: 0) }
                            }
                        }

                    }

                dispatch_async(dispatch_get_main_queue()) {
                    self.currentIssueTableView.reloadData()

                }

            }

        }

        self.populatingCurrentIssue = false
}
}

在这里,我用数据填充表视图单元格:
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell {

    let row = indexPath.row

    guard let cell = tableView.dequeueReusableCellWithIdentifier(CurrentIssueArticlesTableCellIdentifier, forIndexPath: indexPath) as? CurrentIssueArticlesTableViewCell else {

        return tableView.dequeueReusableCellWithIdentifier(CurrentIssueArticlesTableCellIdentifier, forIndexPath: indexPath) as! EditorialsTableViewCell
    }

    if let currentIssueObject = currentIssueObjects.objectAtIndex(indexPath.row) as? IssueElement {

        let author = currentIssueObject.author

        let nodeID = currentIssueObject.nodeID ?? 0

        cell.currentIssueArticlesAuthorLabel!.font = UIFont.preferredFontForTextStyle(UIFontTextStyleSubheadline)
        cell.currentIssueArticlesAuthorLabel!.text = author


        else {
                    }
                }
            }
        }

        else {
        }
    }
    return cell
}

ios - 如何解开我用于标签的字符串?-LMLPHP
JSON数据:
"637": {
"title": "Syd Editorial: The Truth Behind Disney Princesses",
"nid": "637",
"type": "article",
"created": "1444923059",
"revision_timestamp": "1444923059",
"disqus": {
"domain": "****domainname*****
"url": "****the API URL***",
"title": "Syd Editorial: The Truth Behind Disney Princesses",
"identifier": "node/637",
"status": false
},
"image_url": null,
"video_url": null,
"author": "Sydney Wilson",
"issue": "Issue 6",
"volume": "Volume 50",
"issue_int": "6",
"volume_int": "50",
"html_content": "<p>Earlier this week I was spending my time perusing facebook and generally wasting valuable time I could be using to better my life and came across a BuzzFeed article a ‘friend’ had shared: Belle Was Literally the Fucking Worst. After immediately unfriending that anonymous friend (sorry, Mom), because I don’t need that kind of negativity in my life, I carried on with my mindless internet clicking. But it nagged at the back of my mind - what could Belle, the princess praised for her smarts, and more importantly, beauty, have done to make her so hated? So I held my breath, bracing myself for the worst kind of bullshit and clicked the clickbait article, like a fish, I was hooked and they reeled me in. I’ve never spent so much time researching Disney Princesses since I wished I was one (who am I kidding, I still wish I was one).&nbsp;<br />\r\n\tGet this, Belle was actually a rich little overdramatic brat who doesn’t care at all who she hurts, and they got all that incredible insight just from the first song. She uses her beauty to get books and bully farm animals - who does she think she is, making fun of poor illiterate sheep. She is horrible to the furniture, who only want to make her stay pleasant, and then has the gall to feel victimized for getting in trouble for ignoring the rest of the giant castle to explore literally the only room she was asked to avoid. Belle is actually the fucking worst, or is she?<br />\r\n\tSo that got me wondering, are all the Disney Princesses actually horrible people in disguise. I can’t imagine there being anything wrong with them at all, but even still I decided to revisit my personal favourite Disney Princess and see if perhaps she wasn’t exactly the role model I thought she was.&nbsp;<br />\r\n\tAriel: &nbsp;“I’m, like, sixteen Dad, I’m an adult. I can do whatever I want.”&nbsp;<br />\r\n\tI’ve heard that once you start agreeing with the parents in Disney films your childhood is officially over. I must have reached that point, because if you really think about it, Ariel is just some whiney guppy who actually has no understanding of how life really works. She misses the party dedicated entirely to her, so she could ‘find treasure’ with her ‘friend’. Looks like someone ditched a family occasion to score some drugs. While high on the latest swamp drug ‘C Weed’ she falls in love with a man who belongs to an entirely different species and is surprised when her dad gets pissed of and destroys her paraphernalia.&nbsp;<br />\r\n\tI’m sure I could go on for pages about how disney princesses are actually shit, and mayhaps one day I will, but fortunately for you today is not that day. Just heed my warning, if you still want to be a disney princess, while I commend you, your priorites are shit and you should probably seek some kind of professional for your mental or drug related issues. &nbsp;&nbsp; &nbsp;</p>",
"article_category": {
"name": "Editorials",
"machine_name": "editorials"
},
"cover_image": "0",
"slider_item": "0",
"tags": [
"Disney",
"Role Models"
]
},

最佳答案

访问字典返回一个可选的。
这就是你的node.1["author"]String()populateCurrentIssue()中的情况。
解决方案:

if let author = node.1["author"] as? String {
    issueElement.author = author
}

10-08 01:03