• One month later, I made up my mind to upgrade the project from 2.2 to Swift 3.0. It took about 10 hours, and there were over 5000 codes. Originally there were 0 warnings, but now there are 32 warnings that have not been removed.

I summarize the differences between 3.0 and 2.2

  • 1. Closures Note that the + @escaping @escaping and @non-escaping callback functions that decorate a closure do not destroy it after return, it is held. Because this closure does not execute until the asynchronous request returns, at which point the function has returned and must be held by another object in order to execute, note that the loop reference @non-escaping: the function returns after the closure completes execution within the function, and the closure is destroyed.

  • 2. Function name _

Class func QueryUserMusicNetGet(_ user: UserModel,net:@escaping (_ objects: [AnyObject]? , _ error: NSError?) -> ()){// Create a userlet user = AVObject(className: "_User", objectId: (user-.objectid)) // Create a querylet query = MusicNet.query()!
        query.whereKey(LYMusicKeyUserList, equalTo:user)
        
        MusicNet.baseNetGet(query) { (objects, error) in
            net(objects, error)
        }

    }
Copy the code
  • 3 System property name changes 1. Property name starts in lower case 2.NS Massive cancellation: Bundle, originally NSBundle

  • 4. Note that entities defined by -open and public are allowed to be accessed by all scopes (including files in the current module or other module files); -internal Applies only to the module defined by the Entity. Other module files cannot be accessed. Ps: The default Access Control Level is Internal; – Fileprivate applies to the current file. Therefore, multiple classes are defined in a file. After a class is marked as Fileprivate, other files in the current module cannot access the class, but other classes defined in the current file can access the class. -private Allows access only to the current scope. — Open only applies to classes and class members. It differs from public in that: — Public and other more restrictive access levels can only be inherited within defined modules; – Public and other more restrictive access levels can only be overridden in defined modules -open can be inherited or overridden in the defined module or other modules

  • 5. If a function returns a value, it must be received with a warning

_=navigationController? .popViewController(animated:true)
Copy the code
  • 6. Asynchrony this code warns
/ / / asynchronous execution DispatchQueue. Global (priority: DispatchQueue. GlobalQueuePriority. Default). The async (execute: {dispatchqueue.main.async (execute: {() -> Voidin})}) dispatchqueue.global ().async {// code dispatchqueue.main.sync {// main thread}}Copy the code
  • 7. Coordinate position
CGRectGetMaxX(cove.frame) cove.frame. MaxY // betterCopy the code
  • SDWebImage cannot be used, error
 imageView.sd_setImage(with: URL(string: newValue.userModel.headImageUrl), placeholderImage: UIImage(named: "Icon")) { (image, err, type, url) in
            }
Copy the code

#### What the fuck keeps giving error messages

  • Error found as follows:
    imageView.sd_setImage(with: URL(string: newValue.userModel.headImageUrl), placeholderImage: UIImage(named: "Icon"), options: SDWebImageOptions.retryFailed) { (image, error, type, url) in
                weakSelf.userHeadBtn.setImage(image, for: UIControlState())
            }
Copy the code

Swift, you have to have a method that takes parameters

# Mom’s archive is seriously buggy

Don’t know what

// archive func encodeWithCoder(aCoder: NSCoder) {acoder.encodeObject (musicName,forKey: "musicName")
        aCoder.encodeDouble(progress, forKey: "progress"Fork required)} / / / solution init (coder aDecoder: NSCoder) {super. The init () musicName = aDecoder. DecodeObjectForKey ("musicName") as? String
         progress=aDecoder.decodeDoubleForKey("progress")// Collapse. I can't get a value out of it. } last solution idea, is all archiving string, first Double first converted to string, archive, unfile: after the string is converted to Double, remember forced unpack. // archive func encode(with aCoder: NSCoder) {acoder.encode (musicName,forKey: "musicName")
        aCoder.encode("\(progress!) ".forKey: "progress")// Remember to add! } /// decode required init(coder aDecoder: NSCoder) {super.init() musicName= adecoder.decodeObject ()forKey: "musicName") as! String      
        progress=Double(aDecoder.decodeObject(forKey: "progress") as! String)
      
    }
Copy the code

Fixed all the bugs I encountered, and removed all the warnings, which took about 15 hours.

good

Personal blog: http://www.liangtongzhuo.com