美文网首页
Swift4.2 适配记录

Swift4.2 适配记录

作者: Codepgq | 来源:发表于2018-09-20 08:03 被阅读612次

    大部分都可以在Xcode中find然后replace

    AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.record)
    

    替换为

    if #available(iOS 10.0, *) {
                    try AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback, mode: AVAudioSession.Mode.default, options: [.allowAirPlay, .allowBluetooth])
                } else {
                    // Fallback on earlier versions
                }
    
     
    public override var hashValue: Int {
            return 1
        }
    

    替换为

    public override var hash: Int {
            return 1
        }
    
    UICollectionViewScrollDirection
    

    替换为

    UICollectionViewScroll.Direction
    
    UIEdgeInsetsMake(10,10,10,10)
    

    替换为

    UIEdgeInsets(top:10, left:10, bottom:10, right:10)
    

    考虑到这样子替换会难受死:可以使用extension去做

    extension UIEdgeInsets {
        convenience init(_ top: CGFloat, _ left: CGFloat, _ bottom: CGFloat, _ right: CGFloat) {
            self.init(top: top, left: left, bottom: bottom, right: right)
        }
    }
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
    

    替换为:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
    
    override func didMove(toParentViewController parent: UIViewController?) {
       super.didMove(toParentViewController: parent) 
       ...
    }
    

    替换为

    override func didMove(toParent parent: UIViewController?) {
       super.didMove(toParent: parent) 
       ...
    }
    
    Runloop.Mode.commonModes
    

    替换为

    Runloop.Mode.common
    
    UIViewAnimationOptions
    

    替换为

    UIView.AnimationOptions
    
    UITableViewCellStyle
    

    替换为

    UITableViewCell.CellStyle
    
    childViewControllers
    

    替换为

    children
    
    addChildViewController
    

    替换为

    addChild
    
    removeFromParentViewController
    

    替换为

    removeFromParent
    
    UIImagePickerControllerSourceType
    

    替换为

    UIImagePickerController.SourceType
    
    UICollectionViewScrollPosition
    

    替换为

    UICollectionView.ScrollPosition
    
    UICollectionElementKindSectionHeader
    

    替换为

    UICollectionView.elementKindSectionHeader
    
    UIImageJPEGRepresentation(,)
    

    替换为

    imaeg.jedpData(compressionQuality:)
    
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {...}
    UIImagePickerControllerOriginalImage
    UIImagePickerControllerReferenceURL
    

    替换为

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {...}
    UIImagePickerController.InfoKey.originalImage
    UIImagePickerController.InfoKey.referenceURL
    
    UITableViewAutomaticDimension
    

    替换为

    UITableView.automaticDimension
    

    MJRefresh 适配

    arrowImage = [[UIImage imageWithContentsOfFile:[[self mj_refreshBundle] pathForResource:@"arrow@2x" ofType:@"png"]] imageWithRenderingMode:AlwaysTemplate];
    

    替换为

    arrowImage = [[UIImage imageWithContentsOfFile:[[self mj_refreshBundle] pathForResource:@"arrow@2x" ofType:@"png"]] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
    
    [[NSRunLoop currentRunLoop] addPort:[NSMachPort port] forMode:NSDefault]
    

    替换为

    [[NSRunLoop currentRunLoop] addPort:[NSMachPort port] forMode:NSDefaultRunLoopMode]
    

    相关文章

      网友评论

          本文标题:Swift4.2 适配记录

          本文链接:https://www.haomeiwen.com/subject/iicgnftx.html