This file contains 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
// | |
// Anchor.swift | |
// AppStore | |
// | |
// Created by Tifo Audi Alif Putra on 27/07/19. | |
// Copyright © 2019 BCC FILKOM. All rights reserved. | |
// | |
import UIKit |
This file contains 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
class Node<Value> { | |
var value: Value | |
var next: Node<Value>? | |
init(value: Value, next: Node<Value>? = nil ) { | |
self.value = value | |
self.next = next | |
} | |
} |
This file contains 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
public struct Linkedlist<Value> { | |
public var head: Node<Value>? | |
public var tail: Node<Value>? | |
public var isEmpty: Bool { | |
return head == nil | |
} | |
init() {} | |
public mutating func push(_ value: Value) { | |
head = Node(value: value, next: head) |
This file contains 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 getCharacterFromString(str: String) -> Dictionary<Character,Int> { | |
var stringDictionary = Dictionary<Character, Int>() | |
for (_,char) in str.enumerated() { | |
if !stringDictionary.keys.contains(char) { | |
stringDictionary[char] = 1 | |
} else { | |
stringDictionary[char]! += 1 | |
} |
This file contains 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
fileprivate func createOnGoingMovieSection() -> NSCollectionLayoutSection { | |
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalWidth(2/3)) | |
let item = NSCollectionLayoutItem(layoutSize: itemSize) | |
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalWidth(1.0)) | |
let group = NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitem: item, count: 3) | |
group.contentInsets = .init(top: 5, leading: 0, bottom: 5, trailing: 20) | |
let headerSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), | |
heightDimension: .estimated(44)) | |
let sectionHeader = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerSize, elementKind: MovieViewController.sectionHeaderElementKind, alignment: .top) |
This file contains 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
class Node<Value> { | |
var value: Value | |
var next: Node<Value>? | |
init(value: Value, next: Node<Value>? = nil ) { | |
self.value = value | |
self.next = next | |
} | |
} |
This file contains 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 layout = UICollectionViewCompositionalLayout { (sectionIndex: Int, _ ) -> NSCollectionLayoutSection? in | |
let movieSections = MovieSection.allCases[sectionIndex] | |
switch movieSections { | |
case .topRated: return self.createTopRatedMovieSection() | |
case .onGoing: return self.createOnGoingMovieSection() | |
case .upcoming: return self.createUpcomingMovieSection() | |
case .popular: return self.createPopularMovieSection() | |
} | |
} | |
return layout |
This file contains 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
movieDataSource = UICollectionViewDiffableDataSource<MovieSection, Movie>(collectionView: movieCollectionView, cellProvider: { (collectionView, indexPath, movie) -> UICollectionViewCell? in | |
let movieSections = MovieSection.allCases[indexPath.section] | |
switch movieSections { | |
case .topRated: | |
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: TopRatedMovieCell.cellIdentifier, for: indexPath) as? TopRatedMovieCell else { | |
return TopRatedMovieCell() | |
} | |
cell.movie = movie | |
return cell | |
case .onGoing: |
This file contains 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 = NSDiffableDataSourceSnapshot<MovieSection, Movie>() | |
snapshot.appendSections([MovieSection.topRated]) | |
snapshot.appendItems(viewModel.topRatedMovies) | |
snapshot.appendSections([MovieSection.onGoing]) | |
snapshot.appendItems(viewModel.ongoingMovies) | |
snapshot.appendSections([MovieSection.upcoming]) | |
snapshot.appendItems(viewModel.upcomingMovies) |
This file contains 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
//1 | |
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .fractionalWidth(1.0)) | |
let item = NSCollectionLayoutItem(layoutSize: itemSize) | |
//2 | |
let groupSize = NSCollectionLayoutSize(widthDimension: .absolute(140), heightDimension: .absolute(220)) | |
let group = NSCollectionLayoutGroup.vertical(layoutSize: groupSize, subitem: item, count: 1) | |
group.contentInsets = .init(top: 5, leading: 5, bottom: 5, trailing: 5) | |
//3 |
OlderNewer