swift 添加main入口文件 略谈

现在通过  xcode8 创建的swift工程是没有main文件的  因为

在AppDelegate的文件中 

@UIApplicationMain

class AppDelegate: UIResponder, UIApplicationDelegate {

这样进行了注解


那么问题来了,如果想要实现自己的main文件该怎么办呢?

import Foundation

import UIKit

class MyApplication: UIApplication {

    override func sendEvent(_ event: UIEvent) {

        super.sendEvent(event)

        print(event)

    }

}


UIApplicationMain(

    CommandLine.argc,

    UnsafeMutableRawPointer(CommandLine.unsafeArgv)

        .bindMemory(

            to: UnsafeMutablePointer<Int8>.self,

            capacity: Int(CommandLine.argc)),

    NSStringFromClass(MyApplication.self),

    NSStringFromClass(AppDelegate.self)

)

我这里给出一种实现方式

注意:MyApplication的sendEvent在我点击手机屏幕的时候会执行两遍

<UITouchesEvent: 0x6180000e4f80> timestamp: 37129.3 touches: {(

    <UITouch: 0x7fdd03701170> phase: Began tap count: 1 force: 0.000 window: <UIWindow: 0x7fdd06009f10; frame = (0 0; 375 667); autoresize = W+H; gestureRecognizers = <NSArray: 0x600000051d90>; layer = <UIWindowLayer: 0x60000002afe0>> view: <UIView: 0x7fdd03403160; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x61800002b2c0>> location in window: {215, 247.5} previous location in window: {215, 247.5} location in view: {215, 247.5} previous location in view: {215, 247.5}

)}

<UITouchesEvent: 0x6180000e4f80> timestamp: 37130.9 touches: {(

    <UITouch: 0x7fdd03701170> phase: Ended tap count: 0 force: 0.000 window: <UIWindow: 0x7fdd06009f10; frame = (0 0; 375 667); autoresize = W+H; gestureRecognizers = <NSArray: 0x600000051d90>; layer = <UIWindowLayer: 0x60000002afe0>> view: <UIView: 0x7fdd03403160; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x61800002b2c0>> location in window: {215, 247.5} previous location in window: {215, 247.5} location in view: {215, 247.5} previous location in view: {215, 247.5}

)}

这是 两遍打印的结果,从中可以看出这是点击开始 和 结束的两个事件
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值