Jep I implemented the collection View and managed to fill it with the photos in Core Data. I still have to create thumbnails as you suggested. Was the idea though. I'm still struggling with something however. I was trying to make the photos oval instead of rectangular. For some reason this isn't working. The code is:Displaying multiple images is something a collection view was designed to do. Most users are already familiar with it. I suggest putting all the images in a collection view, and then when the user taps on an image, make that one image full screen in a scroll view so that the user can zoom in and out.
import UIKit
class GalleryItemCollectionViewCell: UICollectionViewCell {
@IBOutletweakvar itemImageView: UIImageView!
func setCellWithGalleryItem(item: Photo) {
// Setting a photo is done in a queue
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), { () -> Voidin
if let photoData = item.photo {
let photoImage = UIImage(data: photoData)
dispatch_async(dispatch_get_main_queue(), { () -> Voidin
self.itemImageView.layer.cornerRadius = 30.0
self.itemImageView.clipsToBounds = true
self.itemImageView.image = photoImage
self.itemImageView.layer.cornerRadius = 30.0
self.itemImageView.clipsToBounds = true
})
}
})
}
}
Core Data has this option use external storage. This would store the images in a folder, not in the DB. Still have to find out how it factually operates. How do you create a unique id for your pictures then: a class count? Yes, it stays rectangular.Why save an image to core data in the first place? Core data is not a good place to store image data. Instead I would suggest saving the images as jpegs or pngs in the device file system and simply maintaining a reference to the file using its filename (i.e. the image belonging to userX is userX0.jpg).
About creating the oval display effect, what is happening instead? They're just showing up as regular rectangle image views as if the cornerRadius property is having no effect?
The best way I've found is to generate a completely random long string of characters then append the string with UNIX time in milliseconds. The chance of another file name out there ever matching is less than 1 in 100 trillion.Core Data has this option use external storage. This would store the images in a folder, not in the DB. Still have to find out how it factually operates. How do you create a unique id for your pictures then: a class count? Yes, it stays rectangular.
it's done in the collection View datasource. I moved the func to viewDidLayoutSubViews but without any result.The best way I've found is to generate a completely random long string of characters then append the string with UNIX time in milliseconds. The chance of another file name out there ever matching is less than 1 in 100 trillion.
Also, when and where is this code getting called from? What is the originating method that starts it all? If you try to set properties like cornerRadius in viewDidLoad or any other method that happens too early in the view controller lifecycle you will often encounter strange results. You should instead ensure that the cornerRadius is set in view controllers' viewDidLayoutSubviews method so that it only gets called after auto layout has done its magic and the su views have a real actual frame.
I've dealt with this problem before. You will want to create a custom .xib file for the view inside the collection view, and subclass it. Then in the didMoveToSuperview method, set the cornerRadius there. That will work.it's done in the collection View datasource. I moved the func to viewDidLayoutSubViews but without any result.
Hmm in that case I will use a static count to increase an ID for the photos. Then store the photos in a folder. If this external storage is still being stored in the database it could ruin performance?I think AN's suggestion hit the nail on the head.
Core Data's external storage was temperamental the last time I had the opportunity to use it (that was several generations ago, but am still weary), so I would just avoid usage of it - it's important to take into consideration the type of data and how they're externally stored, too (<100kb is stored in DB, <1mb is stored in DB on another table, 1+mb is only what is stored externally).
Do you have an example by any chance? I did not build my own views yet.I've dealt with this problem before. You will want to create a custom .xib file for the view inside the collection view, and subclass it. Then in the didMoveToSuperview method, set the cornerRadius there. That will work.
Hmm in that case I will use a static count to increase an ID for the photos. Then store the photos in a folder. If this external storage is still being stored in the database it could ruin performance?
Do you have an example by any chance? I did not build my own views yet.