0

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?

Warren Sergent
  • 2,542
  • 4
  • 36
  • 42
Twizzler
  • 491
  • 1
  • 7
  • 25

1 Answers1

0

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 {
Antonio
  • 71,651
  • 11
  • 148
  • 165
  • i wanted to name the object album the value of i: like this| i=0| var i.value = album| – Twizzler Nov 13 '14 at 10:48
  • Sorry I don't understand. `i` is already defined as an `Int` variable, and you're using it to count the number of objects that are added to the `arrayOfAlbums` array. Why do you want to reuse the same variable name for a different purpose? – Antonio Nov 13 '14 at 10:55
  • I want to use the value of i as an unique name for my object – Twizzler Nov 13 '14 at 10:57
  • `i` is defined as integer, then you redefine it locally as `Album`, so how would it be a name? However, ok if you want that to be called `i`, then rename the outer integer variable to something else, like `var counter = 0`, and update the increment line to `counter++`. – Antonio Nov 13 '14 at 11:03
  • well i thought as newbie to Swift i could make an object album with the value of i and append that to my arrayOfAlbums to create an unique name for my object. But thats not possible (i think i can make that up from you answer) shall edit the question – Twizzler Nov 13 '14 at 11:09