Skip to content

Instantly share code, notes, and snippets.

View KrauserHuang's full-sized avatar
:bowtie:
Learning iOS right now!

Krauser Huang KrauserHuang

:bowtie:
Learning iOS right now!
  • Taiwan
View GitHub Profile
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalWidth(2/3))
let fullPhotoItem = NSCollectionLayoutItem(layoutSize: itemSize)
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),
var snapshot = Snapshot()
// 要裝入sections/items
snapshot.appendSections([.main])
snapshot.appendItems(videoList)
// snapshot.appendItems(list, toSection: .main)
dataSource.apply(snapshot, animatingDifferences: animatingDifferencecs)
typealias Snapshot = NSDiffableDataSourceSnapshot<Section, Item>
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
}
typealias DataSource = UICollectionViewDiffableDataSource<Section, Item>
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)
struct CategoryCellModel { //CellModel儲存category跟isSelected參數
let category: Category
var isSelected: Bool = false
}
var categories = [CategoryCellModel]() {
didSet {
DispatchQueue.main.async {
self.categoryCollectionView.reloadData()
}
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()
}
filteredItems.removeAll()
for item in items {
if item.product_type == categories[indexPath.item].productType {
filteredItems.append(item)
}
}