AppDelegate.swift文件中的@UIApplicationMain为啥显式的写出来呢

API 在 Runtime 里都是存在的,为啥你还要写程序呢?不能只靠声明定义么?
■网友
swift的一大亮点是号称没有main函数。但是所有的app都得有一个入口啊,以前objc是main函数。换成swift后没发用main函数指定了,于是就搞这么一个标志来告诉编译器程序的入口在这
■网友
举个例子,使用remote control功能进行耳机线控时就有必要自定义UIApplication这个入口(remote control 不仅仅体现在耳机线控),因为线控接口是所有应用共用的,所以就有 支持remote control的应用之间 争夺耳机线控权 的问题,so,这个控制权响应者设置在应用入口比较方便。贴一段代码:CustomApplication.m@implementation CustomApplication-(void)startRespondRemoteControl{ UIDevice *device = ; BOOL backgroundSupported = NO; if (){ backgroundSupported = device.multitaskingSupported; } if (backgroundSupported == YES){ beginReceivingRemoteControlEvents]; ; }}-(void)stopRespondRemoteControl{ Class playingInfoCenter = NSClassFromString(@"MPNowPlayingInfoCenter"); if (playingInfoCenter){ setNowPlayingInfo:nil]; } endReceivingRemoteControlEvents]; ;}-(void)remoteControlReceivedWithEvent:(UIEvent *)event{ if (event.type == UIEventTypeRemoteControl) { .currentEvent = event; switch (event.subtype) { case UIEventSubtypeRemoteControlPreviousTrack: previous]; break; case UIEventSubtypeRemoteControlNextTrack: next]; break; case UIEventSubtypeRemoteControlPlay: play]; break; case UIEventSubtypeRemoteControlPause: pause]; break; case UIEventSubtypeRemoteControlTogglePlayPause: if ( player].isPlaying) { pause]; }else{ play]; } break; default: break; } if (self.remote_control_event) { self.remote_control_event(event); } }}-(BOOL)canBecomeFirstResponder{ return YES;}


    推荐阅读