在Swift中从Facebook SDK创建对象数组 [英] Creating an Array of objects from the Facebook SDK in Swift

查看:65
本文介绍了在Swift中从Facebook SDK创建对象数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一般来说,我是Swift和IOS编程的新手,所以也许我只是在谷歌搜索错误的内容

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

我让Facebook SDK工作并返回相册.现在,我想要名为Album的对象中的数据.这些相册对象将成为我的收藏夹视图单元格的数据源

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的值用作对象名称.

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

像这样:

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

在尝试执行此操作时,我在i++规则上收到以下错误: 专辑"与"CGFloat"不同

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?

推荐答案

您正在重新定义i变量-我想您可能想将其命名为test.

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 {

为:

if let jsonFeed = rawFeed as? FBGraphObject {

这篇关于在Swift中从Facebook SDK创建对象数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆