Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Raed Alahmari
12,966 PointsCould not cast value of type 'nsnull' to 'nsstring'
I'm trying to retrieve images from firebase when I start the simulated it crash and I get this message " Could not cast value of type 'NSNull' (0x10eaf2378) to 'NSString' (0x10eee2b20). " this is my code
class ViewController: UIViewController {
@IBOutlet weak var gameName: UILabel! @IBOutlet weak var videoImage: UIImageView! @IBOutlet weak var uploadImage: UIButton!
var ref = Firebase(url:"https://xxx.firebaseio.com/images/") var imageRef = Firebase(url:"https://xxx.firebaseio.com/images/image/string") var base64String: NSString!
override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib.
imageRef.observeEventType(.Value, withBlock: { (snapshot) -> Void in
self.base64String = snapshot.value as? String
let decodeData = NSData(base64EncodedString: snapshot.value as! String, options: NSDataBase64DecodingOptions())
let decodeImage = UIImage(data: decodeData!)
self.videoImage.image = decodeImage
print(self.base64String)
}) { (error) -> Void in
print(error.description)
}
}