Skip to content

Commit

Permalink
Merge branch release/1.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
rakuyoMo committed Apr 21, 2024
2 parents 9f26582 + 6e6fa67 commit 08bf4dc
Show file tree
Hide file tree
Showing 21 changed files with 404 additions and 308 deletions.
4 changes: 3 additions & 1 deletion Demo/RaLogDemo/AnotherController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
// Copyright © 2024 Rakuyo. All rights reserved.
//

import UIKit
import RaLog
import UIKit

// MARK: - AnotherController

class AnotherController: UIViewController {

Expand Down
15 changes: 6 additions & 9 deletions Demo/RaLogDemo/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,33 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow? = UIWindow(frame: UIScreen.main.bounds)

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
window?.rootViewController = UINavigationController(rootViewController: ViewController(style: .grouped))
window?.makeKeyAndVisible()

return true
}

func applicationWillResignActive(_ application: UIApplication) {
func applicationWillResignActive(_: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
func applicationDidEnterBackground(_: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
func applicationWillEnterForeground(_: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(_ application: UIApplication) {
func applicationDidBecomeActive(_: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

func applicationWillTerminate(_ application: UIApplication) {
func applicationWillTerminate(_: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

34 changes: 15 additions & 19 deletions Demo/RaLogDemo/LogListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,30 @@
// Copyright © 2024 Rakuyo. All rights reserved.
//

import UIKit
import RaLog

import Then
import SnapKit
import Then
import UIKit

// MARK: - LogListViewController

class LogListViewController: UITableViewController {
private let logs: [Log]

private lazy var label = UILabel().then {
$0.text = "Empty Data"
}

init(logs: [Log]?) {
self.logs = logs ?? []
super.init(nibName: nil, bundle: nil)
}

required init?(coder: NSCoder) {
@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private let logs: [Log]

private lazy var label = UILabel().then {
$0.text = "Empty Data"
}

deinit {
Log.deinit(self)
}
Expand All @@ -46,7 +47,6 @@ extension LogListViewController {
tableView.tableFooterView = UIView()

if logs.isEmpty {

view.addSubview(label)

label.snp.makeConstraints {
Expand All @@ -58,7 +58,6 @@ extension LogListViewController {
label.setContentHuggingPriority(.required, for: .horizontal)

} else {

tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 100

Expand All @@ -83,20 +82,18 @@ extension LogListViewController {

extension LogListViewController {

open override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return logs.count
override open func tableView(_: UITableView, numberOfRowsInSection _: Int) -> Int {
logs.count
}

open override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

override open func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell", for: indexPath)

cell.textLabel?.do {

var string = logs[indexPath.row].logedStr

if string.hasPrefix("\n") { string.removeFirst() }
if string.hasSuffix("\n") { string.removeLast() }
if string.hasSuffix("\n") { string.removeLast() }

$0.text = string
$0.numberOfLines = 0
Expand All @@ -107,4 +104,3 @@ extension LogListViewController {
return cell
}
}

16 changes: 7 additions & 9 deletions Demo/RaLogDemo/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,25 @@
import RaLog

extension Log.Flag {

static let curry: Log.Flag = "⭐️ Curry"
static let note : Log.Flag = "💥 Note"
static let note: Log.Flag = "💥 Note"
}

public extension Printable {

extension Printable {
@inline(__always) @discardableResult
static func note(
public static func note(
_ kLog: Any?, module: String? = nil, file: String = #file, function: String = #function, line: Int = #line
) -> Log {
return p(kLog, module: module, file: file, function: function, line: line)(.note)
p(kLog, module: module, file: file, function: function, line: line)(.note)
}
}

// MARK: - Logger

enum Logger: Printable, Storable, Filterable {

static func format(_ log: LogModelProtocol) -> String {

// Custom print style
return """
"""
[\(log.module)][\(log.file)_\(log.function):\(log.line)] \(log.formatTime) <\(log.flag)>: \(log.safeLog)
"""
Expand Down
22 changes: 12 additions & 10 deletions Demo/RaLogDemo/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,31 @@

import UIKit

// MARK: - SectionDataSource

public struct SectionDataSource {
public let title: String

public let dataSource: [DataSource]

public init(title: String, dataSource: [DataSource]) {
self.title = title
self.dataSource = dataSource
}

public let title: String

public let dataSource: [DataSource]
}

// MARK: - DataSource

public struct DataSource {

public init(title: String, action: @escaping (IndexPath) -> (UIViewController?, Bool)) {
self.title = title
self.action = action
}

public let title: String

/// Execute on click
///
/// Returns the controller to be displayed and whether it is displayed in `push` mode
public let action: (IndexPath) -> (UIViewController?, Bool)

public init(title: String, action: @escaping (IndexPath) -> (UIViewController?, Bool)) {
self.title = title
self.action = action
}
}
30 changes: 14 additions & 16 deletions Demo/RaLogDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
// Copyright © 2024 Rakuyo. All rights reserved.
//

import UIKit
import RaLog
import UIKit

// MARK: - ViewController

class ViewController: UITableViewController {

/// ViewModel
private lazy var viewModel = ViewModel()

Expand All @@ -22,7 +23,8 @@ class ViewController: UITableViewController {
// MARK: - The life cycle

extension ViewController {

override var preferredStatusBarStyle: UIStatusBarStyle { .default }

override func viewDidLoad() {
super.viewDidLoad()

Expand All @@ -33,7 +35,7 @@ extension ViewController {
Log.debug("Note the output of the console")
}

open override func viewWillAppear(_ animated: Bool) {
override open func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

guard let indexPath = tableView.indexPathForSelectedRow else { return }
Expand All @@ -51,16 +53,13 @@ extension ViewController {

Log.disappear(self)
}

override var preferredStatusBarStyle: UIStatusBarStyle { .default }
}

// MARK: - UITableViewDelegate

extension ViewController {

open override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

override open func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let dataSource = viewModel.dataSource[indexPath.section].dataSource

let tuple = dataSource[indexPath.row].action(indexPath)
Expand All @@ -84,20 +83,19 @@ extension ViewController {

extension ViewController {

open override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return viewModel.dataSource[section].title
override open func tableView(_: UITableView, titleForHeaderInSection section: Int) -> String? {
viewModel.dataSource[section].title
}

open override func numberOfSections(in tableView: UITableView) -> Int {
return viewModel.dataSource.count
override open func numberOfSections(in _: UITableView) -> Int {
viewModel.dataSource.count
}

open override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return viewModel.dataSource[section].dataSource.count
override open func tableView(_: UITableView, numberOfRowsInSection section: Int) -> Int {
viewModel.dataSource[section].dataSource.count
}

open override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

override open func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "UITableViewCell", for: indexPath)

let dataSource = viewModel.dataSource[indexPath.section].dataSource
Expand Down
Loading

0 comments on commit 08bf4dc

Please sign in to comment.