If you don’t know if the array index you are calling exists, here is a nice way to just return nil instead of an error. I grabbed this from StackOverflow but unfortunately lost the link. I am putting it here because I use it once in a while and get tired of searching for it.… Continue reading Prevent “Array index out of range” Error in Swift
Month: February 2016
Xcode 7 Archive Button Grayed Out
One reason the Archive button may be grayed out in Xcode is that you need to be connected to a device, and choose that device. See here: http://stackoverflow.com/questions/16050640/xcode-product-archive-disabled/18791703#18791703
Scroll to the Bottom of a Collection View
private func scrollToBottom() { let lastSectionIndex = (collectionView?.numberOfSections())! – 1 let lastItemIndex = (collectionView?.numberOfItemsInSection(lastSectionIndex))! – 1 let indexPath = NSIndexPath(forItem: lastItemIndex, inSection: lastSectionIndex) collectionView!.scrollToItemAtIndexPath(indexPath, atScrollPosition: UICollectionViewScrollPosition.Bottom, animated: false) }
NSDateFormatter Styles
Here is a great guide for how to format the string for the dateFormat method (like “yyyy-MM-dd”): http://www.codingexplorer.com/swiftly-getting-human-readable-date-nsdateformatter/