ActionClosurable 开源项目教程

ActionClosurable 开源项目教程

ActionClosurableExtensions which helps to convert objc-style target/action to swifty closures项目地址:https://gitcode.com/gh_mirrors/ac/ActionClosurable

1、项目的目录结构及介绍

ActionClosurable 项目的目录结构如下:

ActionClosurable/
├── ActionClosurable.xcodeproj
├── ActionClosurable
│   ├── ActionClosurable.swift
│   └── ...
├── ActionClosurableTests
│   └── ...
├── .gitignore
├── ActionClosurable.podspec
├── LICENSE
├── Package.swift
├── README.md
└── ...

目录介绍

  • ActionClosurable.xcodeproj: Xcode 项目文件。
  • ActionClosurable: 包含主要源代码文件,如 ActionClosurable.swift
  • ActionClosurableTests: 包含测试文件。
  • .gitignore: Git 忽略文件配置。
  • ActionClosurable.podspec: CocoaPods 配置文件。
  • LICENSE: 项目许可证文件。
  • Package.swift: Swift Package Manager 配置文件。
  • README.md: 项目说明文档。

2、项目的启动文件介绍

项目的启动文件是 ActionClosurable.swift,位于 ActionClosurable 目录下。该文件主要包含扩展代码,帮助将 Swift 闭包转换为 Objective-C 风格的 target/action。

// ActionClosurable.swift
import UIKit

public protocol ActionClosurable: AnyObject {}

extension ActionClosurable where Self: NSObject {
    public func convert(closure: @escaping (Self) -> Void, to action: Selector) -> AnyObject {
        // 实现代码
    }
}

extension UIControl: ActionClosurable {
    public func on(_ controlEvents: UIControl.Event, closure: @escaping (Self) -> Void) {
        // 实现代码
    }
}

// 其他扩展

3、项目的配置文件介绍

CocoaPods 配置文件

ActionClosurable.podspec 文件用于配置 CocoaPods 依赖管理工具。

Pod::Spec.new do |s|
  s.name = "ActionClosurable"
  s.version = "2.0.0"
  s.summary = "Extensions which helps to convert swifty closure to objc-style target/action."
  s.description = <<-DESC
    * Think: What does it do? Why did you write it? What is the focus?
    * Try to keep it short, snappy and to the point.
    * Write the description between the DESC delimiters below.
    * Finally, don't worry about the indent, CocoaPods strips it.
  DESC
  s.homepage = "https://github.com/takasek/ActionClosurable"
  s.license = { :type => "MIT", :file => "LICENSE" }
  s.author = { "takasek" => "your-email@example.com" }
  s.source = { :git => "https://github.com/takasek/ActionClosurable.git", :tag => s.version.to_s }
  s.ios.deployment_target = "8.0"
  s.source_files = "ActionClosurable/**/*.swift"
end

Swift Package Manager 配置文件

Package.swift 文件用于配置 Swift Package Manager。

import PackageDescription

let package = Package(
    name: "ActionClosurable",
    products: [
        .library(name: "ActionClosurable", targets: ["ActionClosurable"]),
    ],
    dependencies: [],
    targets: [
        .target(name: "ActionClosurable", dependencies: []),
        .testTarget(name: "ActionClosurableTests", dependencies: ["ActionClosurable"]),
    ]
)

以上是 ActionClosurable 开源项目的教程,包含了项目的目录结构、启动文件和配置文件的介绍。希望对你有所帮助!

ActionClosurableExtensions which helps to convert objc-style target/action to swifty closures项目地址:https://gitcode.com/gh_mirrors/ac/ActionClosurable

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

白来存

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值