Background: Now more and more companies will try to use Swift for native development, many used to use Objective-C development, when a new project is launched, they will also want to use Swift. Swift is 10 places ahead of Objective-C in terms of popularity if you look at the 2020 programming language rankings. However, the current project of our company is also developed by Swift. Although we have some OC foundation before and can write Swift function, the code is not very elegant and not ‘Swift Style’ enough. If you are not proficient enough, many of the advanced versions of Swift have to read the documentation to know what the meaning is, so I plan to row a Swift project from 0, and Weibo happens to have an open API, so I choose it here.


The home page interface


Expression interface


The project architecture


Project function

  • Original weibo function
  • Forwarding micro-blog function
  • Emoji function
  • Write the micro blog interface
  • New special function
  • Message alert function
  • Multi-graph display function
  • Rich text function
  • Multi-graph display function
  • Slide auto loading function
  • Up/down refresh function
  • OAuth Authorization login function
  • Has been completed
  • Tweeting function (API no longer available)
  • Image upload function (API no longer available)
  • Message function
  • discovery
  • The function of the I
  • SVProgressHUD reminder function


Technical points used

  • TableView high cache
  • SDWebImage fillet processing
  • FMDB data cache
  • Request authorization
  • Single image height calculation
  • Cell scroll automatically loads more
  • Write the animation of the page
  • Publish the Emoji processing of the interface
  • Multi-graph display
  • .

Insufficient points

  • There are too many material pictures in the App package of Weibo. It takes too much time to find a perfect match, so some resources are not quite matched or not the latest
  • This Demo uses FMDB. In fact, weibo is not suitable for local cache because of its high timeliness and political sensitivity. Here is just a simple case of USING FMDB, which is more suitable for updating and not too timely, or apps like QQ that receive messages pushed by the server.
  • This Renaissance version of Weibo (2016), the current weibo has been greatly changed, and many API interfaces are not open now, so temporarily use this nostalgic version.
  • SVProgressHUD crashes in Swift5.0, so there is no toast in this app…
  • Gif picture because now the portal website can only pass < 5M, so it looks fuzzy after all, the actual effect will be much better than Gif picture, it is recommended to run with a real machine to try ~
  • This version was intended to use my poor English to write the whole annotations, but later due to my limited Chinelish skills, after all, the complex logic/business was written in Chinese (O light spray)
  • .

Third-party libraries used

  • AFNetworking
  • SDWebImage
  • YYModel
  • SnapKit
  • FMDB
  • pop
  • HMPhotoViewerController

Tools to share

Image material acquisition: Cartool

Color annotation tool: MarkMan

Database tool: Navicat

Drawing tool: MindNode

.


conclusion

Engaged in Swift development for a period of time, I found that it is not possible without a certain amount of code accumulation (step pit), so I decided to write an entry-level pure Swift App by myself. This project is the first release of the new Swift project, a little rough, but if the novice as a swift start, the entry, in fact, should be ok. The project is basically written in the way of “pure code + pure Swift”, using the new API as far as possible, the new people want to play the feeling or can get started.

Recently found that time management is really important, a lot of things, a began to think that you can’t do that, to back down, but as long as the bullet, challenge your limits, it’s not, this Demo came out ~ (in order to write this lemon, long-term to do acupuncture cervical spondylosis, cheat wave star too much ~ (a joke, As long as everyone is happy 😂))

What do you think is not good or can be improved? If you have time to help with code review or propose PR, you are warmly welcome. Thank you in advance



Demo: MNWeibo


This article thanks sina to provideAPISupport, thank youTianya Knife brother – Fu HongxueThe guidance of