Questions about this format, send me a message: https://www.linkedin.com/in/hectorddmx
For technical interviews, let's ask candidates to refresh the following:
- reply brief answers on iOS topics to share your understanding
Questions about this format, send me a message: https://www.linkedin.com/in/hectorddmx
For technical interviews, let's ask candidates to refresh the following:
In iOS 16, Apple added UIHostingConfiguration, making it straightforward to use a SwiftUI view in instances of UICollectionViewCell and UITableViewCell. This gist shows how UIHostingConfiguration can be backported to iOS 14 by implementing a type that conforms to UIContentConfiguration.
Starting from iOS 16, we can use SwiftUI views in an instance of UICollectionView or UITableViewCell like this:
cell.contentConfiguration = UIHostingConfiguration {
ExampleCellContentView(color: Color(item.color), text: item.text)
}
import SwiftUI | |
import UIKit | |
class MyViewController: UIViewController { | |
// this is how you embed a SwiftUI View | |
lazy var host: UIViewController = { | |
return UIHostingController(rootView: MySwiftUIView()) | |
}() | |
struct AutoHeightLabelView: View { | |
var attributedString: NSAttributedString | |
var body: some View { | |
HorizontalGeometryReader { width in | |
UILabelView( | |
attributedString: attributedString, | |
preferredMaxLayoutWidth: width | |
) | |
} |
import Foundation | |
var json = """ | |
{ | |
"lastSyncDate": "2018-10-28T09:03:59+0000", | |
"posts": [ | |
{ | |
"id": 0, | |
"title": "Swift 4 Codable: tips and tricks", | |
"link": "https://medium.com/@MarioIannotta/swift-4-codable-tips-and-tricks-7ab4674736d2", |
import Foundation | |
public struct Log | |
{ | |
public static var isEnabled = true | |
public static func debug(_ m: @autoclosure ()->String, _ file: Any? = #file, _ f: String = #function, _ line: UInt = #line) { | |
print(m(), file ?? "", f, line) | |
} |
/// A type that has an "empty" representation. | |
public protocol EmptyRepresentable { | |
static func empty() -> Self | |
} | |
extension Array: EmptyRepresentable { | |
public static func empty() -> Array<Element> { | |
return Array() | |
} | |
} |
import Foundation | |
protocol Completable { | |
func addCompletionOperation(on queue: OperationQueue, complete: @escaping (Self) -> Void) -> Operation | |
} | |
extension Completable where Self: Operation { | |
func addCompletionOperation(on queue: OperationQueue, complete: @escaping (Self) -> Void) -> Operation { | |
let completionOperation = BlockOperation { |