devedup / FlickrKit

An iOS Flickr Framework, written in Objective-C
http://www.devedup.com
219 stars 71 forks source link

How to replicate in Swift #37

Closed tonespy closed 8 years ago

tonespy commented 9 years ago

I am trying to replicate this in swift

FlickrKit *fk = [FlickrKit sharedFlickrKit];
FKFlickrInterestingnessGetList *interesting = [[FKFlickrInterestingnessGetList alloc] init];
[fk call:interesting completion:^(NSDictionary *response, NSError *error) {
    // Note this is not the main thread!
    if (response) {             
        NSMutableArray *photoURLs = [NSMutableArray array];
        for (NSDictionary *photoData in [response valueForKeyPath:@"photos.photo"]) {
            NSURL *url = [fk photoURLForSize:FKPhotoSizeSmall240 fromPhotoDictionary:photoData];
            [photoURLs addObject:url];
        }
        dispatch_async(dispatch_get_main_queue(), ^{
            // Any GUI related operations here
        });
    }   
}];
devedup commented 9 years ago

There is a swift demo project too

tonespy commented 9 years ago

I tried this

self.photoURLs = []
        let fk = FlickrKit.sharedFlickrKit()
        let interesting = FKFlickrInterestingnessGetList()
        interesting.per_page = "5"
        fk.call(interesting) {(response, error) -> Void in

            dispatch_async(dispatch_get_main_queue(), { () -> Void in

                if (response != nil) {
                    // Pull out the photo urls from the results
                    print(response)
                    let topPhotos = response["photos"] as! [NSObject: AnyObject]
                    let photoArray = topPhotos["photo"] as! [[NSObject: AnyObject]]
                    for photoDictionary in photoArray {
                        let photoURL = FlickrKit.sharedFlickrKit().photoURLForSize(FKPhotoSize.init(2), fromPhotoDictionary: photoDictionary)
                        print(photoURL)
                        self.photoURLs.append(photoURL)
                    }
                    //print(self.photoURLs)
                } else {
                    print(error)
                    switch error.code {
                    case FKFlickrInterestingnessGetListError.ServiceCurrentlyUnavailable.rawValue:
                        break;
                    default:
                        break;
                    }
                    let alert = UIAlertView(title: "Error", message: error.localizedDescription, delegate: nil, cancelButtonTitle: "OK")
                    alert.show()
                }
            })
        }

This line let photoURL = FlickrKit.sharedFlickrKit().photoURLForSize(FKPhotoSize.init(2), fromPhotoDictionary: photoDictionary)

This is what's in the documentation for getting a particular image size let photoURL = FlickrKit.sharedFlickrKit().photoURLForSize(FKPhotoSizeSmall240, fromPhotoDictionary: photoDictionary)

and FKPhotoSizeSmall240 gives me Ambigous reference to FKPhotoSize @devedup

devedup commented 9 years ago

So do you get this when you try and compile the FlickrKitSwiftDemo app? Maybe you need to do a clean of your derived data directory.