Downcast from AnyObject to UIImage[] - Swift

Sawyer05

I'm trying to convert the results of a valueForKeyPath into an array of UIImages. When trying to do it I get met with this error

Undefined symbols for architecture i386: "TToFC9TableView19TableViewControllers6photosGSqGSaCSo7UIImage", referenced from: __TFC9TableView29JustPostedTableViewController11fetchPhotosfS0_FT_T_ in JustPostedTableViewController.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Here's my attempt at the code in swift: The propertyListResults is an NSDictionary, and the parameter in valueForKeyPath is a String

var photos : AnyObject = (propertyListResults as AnyObject).valueForKeyPath(flickrFetcher.FLICKR_RESULTS_PHOTOS)

self.photos = photos as? UIImage[]

And the working Objective-C version of the code is

NSArray *photos = [propertyListResults valueForKeyPath:FLICKR_RESULTS_PHOTOS];
self.photos = photos
drewag

If you run swift-demangle on "__TToFC9TableView19TableViewControllers6photosGSqGSaCSo7UIImage__" you get:

@objc TableView.TableViewController.photos.setter : (ObjectiveC.UIImage[])?

That means that the linker is not finding a setter for photos on TableViewController. It seems that you are using a TableViewController instead of your own subclass that has a photos property.

Also, photos as? UIImage[] returns an Optional because it is possible for it to fail. You should do the following:

if let images : [UIImage] = photos as? [UIImage] {
    self.photos = images
}

This checks if photos can be converted to [UIImage]. If it can, it assigns it to self.photos

Edit: Updated UIImage array syntax to the new array syntax in the beta 3

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Downcast from AnyObject?

From Dev

Swift: Unable to downcast AnyObject to SKPhysicsBody

From Dev

Downcast from 'UIImage?' to 'UIImage' only unwraps optionals

From Dev

How to iterate a Swift [AnyObject] array with a downcast?

From Dev

Cannot downcast from an object conforming to Equatable to AnyObject

From Dev

Cannot downcast from an object conforming to Equatable to AnyObject

From Dev

Swift - 'AnyObject!' is not convertible to 'ViewController'; did you mean to use 'as!' to force downcast?

From Dev

Downcast [AnyObject] to [String] and [PFObject]

From Dev

Downcast [AnyObject] to [String] and [PFObject]

From Dev

Swift typecast from AnyObject

From Dev

Downcast element when reading from Dictionary in Swift

From Dev

Siesta Swift Casting from ImplicitlyUnwrappedOptional<Swift.AnyObject> to Array<AnyObject>

From Dev

Swift can print AnyObject, but can't create String from AnyObject

From Dev

Getting CIImage from UIImage (Swift)

From Dev

Swift UIImage from CALayer crash

From Dev

create movie from [UIImage], Swift

From Dev

get UIImage from sender in swift

From Dev

Type '[AnyObject!' cannot be implicitly downcast to 'PFObject'

From Dev

Conditional downcast from 'String' to 'String' always succeeds - Swift Error

From Dev

Swift 2.0 error Downcast from '[NSIndexPath]?' to '[indexpath]' only unwraps optional

From Dev

Swift 2.0 error Downcast from '[NSIndexPath]?' to '[indexpath]' only unwraps optional

From Dev

Swift - AnyObject[] is not a subtype of AnyObject[]?

From Dev

Error casting from AnyObject? to SecKeyRef? in Swift

From Dev

Get Value from AnyObject Response Swift

From Dev

Swift creating JSON data from AnyObject

From Dev

Swift: Downcast to known type

From Dev

SWIFT - Downcast an array to a string

From Dev

Downcast from Any to a protocol

From Dev

Downcast from Any to a protocol

Related Related

  1. 1

    Downcast from AnyObject?

  2. 2

    Swift: Unable to downcast AnyObject to SKPhysicsBody

  3. 3

    Downcast from 'UIImage?' to 'UIImage' only unwraps optionals

  4. 4

    How to iterate a Swift [AnyObject] array with a downcast?

  5. 5

    Cannot downcast from an object conforming to Equatable to AnyObject

  6. 6

    Cannot downcast from an object conforming to Equatable to AnyObject

  7. 7

    Swift - 'AnyObject!' is not convertible to 'ViewController'; did you mean to use 'as!' to force downcast?

  8. 8

    Downcast [AnyObject] to [String] and [PFObject]

  9. 9

    Downcast [AnyObject] to [String] and [PFObject]

  10. 10

    Swift typecast from AnyObject

  11. 11

    Downcast element when reading from Dictionary in Swift

  12. 12

    Siesta Swift Casting from ImplicitlyUnwrappedOptional<Swift.AnyObject> to Array<AnyObject>

  13. 13

    Swift can print AnyObject, but can't create String from AnyObject

  14. 14

    Getting CIImage from UIImage (Swift)

  15. 15

    Swift UIImage from CALayer crash

  16. 16

    create movie from [UIImage], Swift

  17. 17

    get UIImage from sender in swift

  18. 18

    Type '[AnyObject!' cannot be implicitly downcast to 'PFObject'

  19. 19

    Conditional downcast from 'String' to 'String' always succeeds - Swift Error

  20. 20

    Swift 2.0 error Downcast from '[NSIndexPath]?' to '[indexpath]' only unwraps optional

  21. 21

    Swift 2.0 error Downcast from '[NSIndexPath]?' to '[indexpath]' only unwraps optional

  22. 22

    Swift - AnyObject[] is not a subtype of AnyObject[]?

  23. 23

    Error casting from AnyObject? to SecKeyRef? in Swift

  24. 24

    Get Value from AnyObject Response Swift

  25. 25

    Swift creating JSON data from AnyObject

  26. 26

    Swift: Downcast to known type

  27. 27

    SWIFT - Downcast an array to a string

  28. 28

    Downcast from Any to a protocol

  29. 29

    Downcast from Any to a protocol

HotTag

Archive