问题
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