Creating an Array of objects from the Facebook SDK in Swift

让人想犯罪 __ 提交于 2020-01-06 13:59:11

问题


Im new to Swift and IOS programming in general so maybe im just google ing the wrong things

I have the Facebook SDK working and returning the albums. Now i want the data in objects named Album. These Album objects will be the datasource of my collection view cells

When trying to do this i run into the following problem:

i can't get my objects into my object array! here is the code i have so far:

  var i = 0
    var list: [String] = []
    for rawFeed : AnyObject in data {
        if rawFeed is FBGraphObject {
            if var jsonFeed = rawFeed as? FBGraphObject {
                var app = jsonFeed["name"] as String
                list.append(app)

                 var i = Album(albumName: jsonFeed["name"] as String , albumId:jsonFeed["id"] as Int,count: jsonFeed["count"] as Int)
                arrayOfAlbums.append(test)
                i++
            }
        }

I thought i would use the value of i as object name.

like this:

arrayOfAlbums = {
[0] => AlbumObject0,
[1] => albumobject1
}

when trying to do this i get the following error on the i++ rule: 'Album' is not identical to 'CGFloat'

what am i doing wrong and where can i improve my code?


回答1:


You are redefining the i variable - I think you probably wanted to name it test.

Note that you can simplify your code here:

if rawFeed is FBGraphObject {
    if var jsonFeed = rawFeed as? FBGraphObject {

as:

if let jsonFeed = rawFeed as? FBGraphObject {


来源:https://stackoverflow.com/questions/26906856/creating-an-array-of-objects-from-the-facebook-sdk-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!