Skip to content

Instantly share code, notes, and snippets.

@DominikPetho
DominikPetho / 0-InfinitePageView for SwiftUI.md
Created January 23, 2024 16:34 — forked from beader/0-InfinitePageView for SwiftUI.md
Create a InfinitePageView for SwiftUI using UIViewControllerRepresentable by the help of ChatGPT

InfinitePageView for SwiftUI

Create a Bi-directional Infinite PageView for SwiftUI using UIViewControllerRepresentable & UIPageViewController by the help of ChatGPT.

Checkout the video demo in the comment.

The code is generated by ChatGPT through multiple rounds of conversations. Checkout the conversations between ChatGPT and me if you are interested in.

func isLeap(year: Int) -> Bool {
let isDivisibleBy4 = year % 4 == 0
let isDivisibleBy100 = year % 100 == 0
let isDivisibleBy400 = year % 400 == 0
let isLeapYear = (isDivisibleBy4 && !isDivisibleBy100) || ( isDivisibleBy4 && isDivisibleBy400)
return isLeapYear
}
@DominikPetho
DominikPetho / .swift
Last active September 15, 2020 07:36
Sample of Swift property wrappers for unit testing
import UIKit
@propertyWrapper
struct Printer<T> {
public var currentValue: T?
var wrappedValue: T? {
get {
print("Property wrapper value printed", currentValue)
struct User {
let name: String
let surname: String
let photo: UIImage
}
class ViewControllerHeaderView: UIView {
@IBOutlet weak var userImageView: UIImageView!
@IBOutlet weak var messageButton: UIButton!
@DominikPetho
DominikPetho / .swift
Created October 10, 2018 05:08
Simple Controller with outlets
class ViewController: UIViewController {
@IBOutlet weak var userImageView: UIImageView!
@IBOutlet weak var messageButton: UIButton!
@IBOutlet weak var followButton: UIButton!
@IBOutlet weak var userNameLabel: UILabel!
@IBOutlet weak var phoneNameButton: UIButton!
@IBOutlet weak var phoneNameLabel: UILabel!
@IBOutlet weak var phoneNameRightImageView: UIImageView!
@DominikPetho
DominikPetho / .swift
Last active October 1, 2018 13:03
SimpleViewController using enum
// Right now you can delete SimpleViewCellType protocol
struct Person {
var name: String
var surname: String
}
struct Advertisement {
var brandName: String
}
@DominikPetho
DominikPetho / .swift
Created October 1, 2018 11:32
Simple CellType
extension SimpleViewController {
enum CellType {
case advertisement(Advertisement)
case person(Person)
}
}
@DominikPetho
DominikPetho / .swift
Created October 1, 2018 11:11
Disatvantage method
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var dequeuedCell: UITableViewCell?
if peopleWithAdvertisementList[indexPath.row] is Advertisement {
dequeuedCell = tableView.dequeueReusableCell(withIdentifier: "AdvertisementCell")
} else if peopleWithAdvertisementList[indexPath.row] is Person {
dequeuedCell = tableView.dequeueReusableCell(withIdentifier: "PeopleCell")
} else {
// Else what? Do we have other type comforming to SimpleViewCellItem protocol?
}
@DominikPetho
DominikPetho / SimpleViewController.swift
Last active October 1, 2018 13:03
Main implementation of SimpleViewController
public final class SimpleViewController: UIViewController {
@IBOutlet weak var tableView: UITableView!
// List of items, showed in TableView
var peopleWithAdvertisementList: [SimpleViewCellItem]!
public override func viewDidLoad() {
setupTableView()
createDummyList()