Posts

Post not yet marked as solved
0 Replies
2.0k Views
Hello everyone, I am trying to fetch a list of photo albums from the photo library and present it to the user to select one of them. I have the following code below which fetches the list of photo albums. I can see all the photo albums list in the output on xcode but it's not presenting to the user. How can I get it to present to the user?func getPhotosFromAlbum(albumName: BeenThereItem) { var photoLibraryImages = [UIImage]() var photoLibraryAssets = [PHAsset]() let finalPhotos = albumName.photoAlbum DispatchQueue.global(qos: .userInteractive).async { let fetchOptions = PHFetchOptions() fetchOptions.predicate = NSPredicate(format: "mediaType = %d", PHAssetMediaType.image.rawValue) let smartAlbums = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .any, options: nil) let customAlbums = PHAssetCollection.fetchAssetCollections(with: .album, subtype: .any, options: nil) [smartAlbums, customAlbums].forEach { $0.enumerateObjects { collection, index, stop in let imgManager = PHImageManager.default() let requestOptions = PHImageRequestOptions() requestOptions.isSynchronous = true requestOptions.deliveryMode = .highQualityFormat // let photoInAlbum = PHAsset.fetchAssets(in: collection, options: fetchOptions) let photoInAlbum = PHAsset.fetchAssets(in: collection, options: fetchOptions) if let title = collection.localizedTitle { if photoInAlbum.count > 0 { print("\n\n \(title) --- count = \(photoInAlbum.count) \n\n") } if title == albumName.photoAlbum { if photoInAlbum.count > 0 { for i in (0..<photoInAlbum.count).reversed() { imgManager.requestImage(for: photoInAlbum.object(at: i) as PHAsset , targetSize: CGSize(width: 150, height: 150), contentMode: .aspectFit, options: requestOptions, resultHandler: { image, error in if image != nil { photoLibraryImages.append(image!) photoLibraryAssets.append(photoInAlbum.object(at: i)) } }) } } } } } } } }
Posted
by hhavens.
Last updated
.
Post not yet marked as solved
3 Replies
371 Views
Hello everyone,I am wanting to create a collection view that pulls photos from a custom photo library. I have a detail view from a list and I want it to show the same custom photo library every time. I already store data in CoreData so I'm sure that is were I would store the information. I don't want to store the images themselves just a link to the custom photo library.I know how to make the collection view but I don't know how to search for the particular custom photo library and call upon it.Is this possible to do with SwiftUI? I've done multiple searches but could only find for older Swift versions and can't make them seem to work. Any help would be appreciated. I am willing to pay someone to teach me how to do this. I've looked at several training classes as well but can't find anything specific to what I am looking for.
Posted
by hhavens.
Last updated
.
Post marked as solved
7 Replies
974 Views
Hello everyone and thanks in advance. This is my first time posting so forgive me if it's not correct.I am very new when it comes to coding. Learning as I go.I am using CoreData and have that part setup.@Environment(\.managedObjectContext) var managedObjectContext @Environment (\.presentationMode) var presentationMode var dateFormatter: DateFormatter { let formatter = DateFormatter() formatter.dateStyle = .long return formatter } @State var title = "" @State var location = "" @State var when = Date()I also have a DatePicker setup.DatePicker(selection: $happenedOn, in: ...Date(), displayedComponents: .date, label: {Text("Happened On")})What I can't seem to figure out is how to pass the date to another view. I tried many things but can't seem to get it to work. The rest of the CoreData works fine, it's just the date.Button("Add", action: { let newItem = BeenThereItem(context: self.managedObjectContext) newItem.title = self.title newItem.location = self.location newItem.id = UUID() newItem.happenedOn = self.when do { try self.managedObjectContext.save() print("Item saved") self.presentationMode.wrappedValue.dismiss() } catch { print(error.localizedDescription) } })This is where I'm trying to get it to go.ForEach(beenThereItems) { beenThere in NavigationLink(destination: BeenThereDetailsView(beenThere: beenThere)) { BeenThereRowView(title: beenThere.title, location: beenThere.location) //Text("\(beenThere.happenedOn, formatter: self.dateFormatter)") }
Posted
by hhavens.
Last updated
.