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 x: String? = "Hello Optional" | |
switch x { | |
case .some(let value): print("Optional has an value of \(value)") | |
case .none: print("nothing stored inside the enum") | |
} |
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 < <T : Comparable>(lhs: T?, rhs: T?) -> Bool { | |
switch (lhs, rhs) { | |
case let (l?, r?): | |
return l < r | |
case (nil, _?): | |
return true | |
default: | |
return false | |
} | |
} |
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
// Won't work | |
let x: String? = nil | |
let y: String? = "Hello Optional" | |
switch (x,y) { | |
case .some(let a),.some(let b): print("Optional has an value of \(unwrappedX)") | |
case .none: print("nothing stored inside the enum") | |
} |
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 x: String? = "Hello Optional" | |
let y: String? = "Hello Optional" | |
switch (x,y) { | |
case let (x?,y?): print("Values: \(x) & \(y)") | |
default: print("Error") | |
} |
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
import Foundation | |
internal final class MulticastDelegate<T> { | |
private var delegates = [Weak]() | |
func add(_ delegate: T) { | |
if Mirror(reflecting: delegate).subjectType is AnyClass { | |
let weakValue = Weak(value: delegate as AnyObject) | |
guard delegates.index(of: weakValue) == nil else { | |
return |
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
UIModalPresentationStyle | iPhone | iPad | |
---|---|---|---|
.fullScreen | YES | YES | |
.pageSheet | YES | NO | |
.formSheet | YES | NO | |
.currentContext | YES | YES | |
.custom | NO | NO | |
.overFullScreen | NO | NO | |
.overCurrentContext | NO | NO | |
.blurOverFullScreen | only on tvOS - N/A | N/A | |
.popover | YES | NO |
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 cellProvider: (UICollectionView, IndexPath, Item) -> UICollectionViewCell? = { collectionView, indexPath, item in | |
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) | |
cell.backgroundColor = item.color | |
return cell | |
} |
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
enum Section { | |
case section1 | |
case section2 | |
} | |
struct Item: Hashable { | |
let name: String | |
} |
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 ViewController: UIViewController { | |
@IBOutlet var collectionview: UICollectionView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
} | |
} |
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 ViewController: UIViewController { | |
@IBOutlet var collectionview: UICollectionView! | |
lazy var dataSource = UICollectionViewDiffableDataSource<Section, Item>(collectionView: self.collectionview, | |
cellProvider: self.cellProvider) | |
lazy var cellProvider: (UICollectionView, IndexPath, Item) -> UICollectionViewCell? = { collectionView, indexPath, item in | |
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) | |
cell.backgroundColor = item.color | |
return cell | |
} | |
OlderNewer