I have the following methods
var photos = [MWPhoto] = [MWPhoto]()
func numberOfPhotosInPhotoBrowser(photoBrowser: MWPhotoBrowser!) -> UInt {
return self.photos.count
}
func photoBrowser(photoBrowser: MWPhotoBrowser!, photoAtIndex index: UInt) -> MWPhotoProtocol! {
return self.photos[index]
}
However for the first I get Int is not convertible to UInt
(since self.photos.count
is an Int
and for the second UInt is not convertible to Int
- since the self.photos[
can only take an Int for its index.
How can I correctly convert the UInt to Int and back?
Int
instead ofUInt
. Even though the values are never going to be negative, the recommendation from the Swift documentation is essentially to always useInt
unless you have a specific reason to do otherwise (interoperability with C functions, for example). – Nate Cook Sep 28 at 16:44