This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalWidth(2/3)) | |
| let fullPhotoItem = NSCollectionLayoutItem(layoutSize: itemSize) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func generateLayout() -> UICollectionViewLayout { | |
| let itemSize = NSCollectionLayoutSize( | |
| widthDimension = .fractionalWidth(1.0), | |
| heightDimension = .fractionalHeight(1.0)) | |
| let fullPhotoItem = NSCollectionLayoutItem(layoutSize: itemSize) | |
| fullPhotoItem.contentInsets = NSDirectionalEdgeInsets(top: 2, leading: 2, bottom: 2, trailing: 2) | |
| let groupSize = NSCollectionLayoutSize( | |
| widthDimension = .fractionalWidth(1.0), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var snapshot = Snapshot() | |
| // 要裝入sections/items | |
| snapshot.appendSections([.main]) | |
| snapshot.appendItems(videoList) | |
| // snapshot.appendItems(list, toSection: .main) | |
| dataSource.apply(snapshot, animatingDifferences: animatingDifferencecs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| typealias Snapshot = NSDiffableDataSourceSnapshot<Section, Item> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func configureDataSource() -> DataSoure { | |
| let dataSource = DataSource(collectionView: collectionView) { collectionView, indexPath, video -> UICollectionViewCell? in | |
| let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "VideoCollectionViewCell", for: indexPath) as? VideoCollectionViewCell | |
| cell?.video = video | |
| return cell | |
| } | |
| return dataSource | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| typealias DataSource = UICollectionViewDiffableDataSource<Section, Item> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { | |
| // 紀錄url scheme | |
| print(URLContexts) | |
| guard let url = URLContexts.first?.url else{return} | |
| urlScheme(url.absoluteString) | |
| } | |
| func urlScheme(_ urlStr: String){ | |
| let root = UIApplication.shared.windows.first?.rootViewController as? RootTabBarController | |
| let navi = root?.selectedViewController as? UINavigationController | |
| navi?.popToRootViewController(animated: true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct CategoryCellModel { //CellModel儲存category跟isSelected參數 | |
| let category: Category | |
| var isSelected: Bool = false | |
| } | |
| var categories = [CategoryCellModel]() { | |
| didSet { | |
| DispatchQueue.main.async { | |
| self.categoryCollectionView.reloadData() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var receivedData: Data? | |
| func startLoad() { | |
| loadButton.isEnabled = false | |
| let url = URL(string: "https://www.example.com/")! | |
| receivedData = Data() | |
| let task = session.dataTask(with: url) | |
| task.resume() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| filteredItems.removeAll() | |
| for item in items { | |
| if item.product_type == categories[indexPath.item].productType { | |
| filteredItems.append(item) | |
| } | |
| } |