Make writing a habit together! This is the third day of my participation in the “Gold Digging Day New Plan · April More text Challenge”. Click here for more details.

After the National Day of 2017, Lucio began to switch from Android development to iOS development. Before this, Lucio was a small white who had never used any Apple products. Here is a small white iOS development learning process, including reading books, videos and articles. See how Lucio goes from small white fast (not fast BILL (´∀ ‘) back to iOS development actually).

1. Objective-c language introduction

Objective-c Basics tutorial. Good. Here are the study notes for the following chapters for easy review.

Foundation Kit is introduced in Chapter 8 of Objective-C Basics

Objective-c Basics tutorial, chapter 9, Memory management

Objective-c Basics tutorial. Chapter 10. Object initialization

Objective-c Basics tutorial chapter 11 properties

Objective-c Basics tutorial. Chapter 12 categories

Objective-c Basics tutorial chapter 13 protocols

Code blocks and Concurrency. Chapter 14 in Objective-C Basics

2. Introduction to iOS development

(1) Stanford white beard iOS8 video

Stanford Open Course: iOS 8 Development

So this is an open course for every iOS version, so basically there’s a demo for iOS development, and every version of the demo is different, and iOS7 is objective-C, and I didn’t know that until I saw it, but if YOU look at iOS8 you can do it in Objective-C at the same time, The method names are exactly the same on both sides, except for the syntax differences.

Post an explanation of the MVC pattern inside

The MVC pattern

  1. The Model and View cannot communicate: The Model is completely separate from the UI, and the UI components are generic, requiring the Controller to translate and format the Model’s information for display.
  2. Controller->View: The UI components in the View exist in the Controller as outlets.
  3. View->Controller: The Controller registers the target itself and tells the View to send the action to me when a specific action (such as a button click) occurs. The View delegate assigns responses to actions like should, will, and DID to the Controller. The View doesn’t own the data it displays, it gets the data from the Controller via a data source (also known as a special delegate), and the data comes from the Model.
  4. Model->Controller: The Model broadcasts its property changes to interested subscribers (typically Controllers), Notification & KVO, and the Controller then goes to the Model to fetch new data.

(2) “Crazy iOS Handout”

Read the source code with the book can quickly understand the use of various controls, as well as graphics, animation related knowledge.

3. Read and think

Part 1 – Code specification

(1) Code style

Round 1-Raywenderlich.com Official Code Style Guide :]

The official raywenderlich.com Objective-C style guide.

English translation: blog.it985.com/10771.html

Need to pay more attention to some of the details:

  1. Choice between copy and strong: Assign an object to a property variable. When the object changes, use the strong property if you want the property variable to change, and use the copy property if you want the property variable not to change.
  2. It is recommended to use macros defined in code hintsNS_ENUM()Enumeration module, which provides more rigorous type detection and code completion.
  3. Private changes should be in the private category of the class and do not need to be addedprivateAnd so on.
  4. Private categories can be created under the name<headerfile>+Private.hIs provided in the document.
  5. initMethod to return a valueinstancetypereplaceidAs a return.[because]
  6. Singletons must be thread-safe.
  7. :]
Round 2 – Summarize your own View layer organization specifications

Summarize a set of own View code specification, need to be gradually improved in the future.

#pragma mark-lifecycle Menthod - (void)viewDidLoad {[super viewDidLoad]; [self initView()]; [self initData()]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } - (instancetype)init {} - (void)dealloc {} #pragma mark - Delegate Menthod #pragma mark - Event response - (void)xxxClick(){ } #pragma mark - Public #pragma mark - Private - (void)initView{ //DO initView [self initConstrains()]; } - (void)initConstrains{ //DO initConstrains } - (void)initData{ //DO initData } #pragma mark - getter && setter // 1. The initialization of properties (especially views) is in the getter, and in initView only addSubview. // 2. With regard to lazy initialization (1), you need to consider attributes related to nulling, thread insecurity, and automatic optimization. InitConstrains is used to initialize constraints. Use makeConstraints whenever possible, and if the constraint needs to be updated dynamically, overwrite updateViewConstraints or updateConstraintsCopy the code

On note 2:

Round 3 – Pros and cons of lazy initialization

Good or bad practice? Initializing objects in getter

Lazy initialization. Attributes related to nulling, thread insecurity, and automatic optimization need to be considered for the above reasons.

(2) iOS project directory structure

Round 1-ios project engineering and directory structure

IOS project engineering and directory structure

Distinguish common components at different levels.

  • The General Level, the most common component, can be reused across different projects.
  • Project Level, which can be reused in this Project.
  • Section Level, which can be reused within a functional module.
Round 2 – Reference examples

The directory structure of your iOS project is an indicator of your development experience

Two examples can be roughly referenced.

Part 2 – Third Party libraries

(1) iOS development package management

CocoaPods

CocoaPods Installation and Use tutorial

Carthage

Carthage package management tool, another agile and brisk iOS & MAC development experience

CoaoaPods is a holistic solution where we specify the third-party libraries we need in our Podfile. CocoaPods will then download, integrate, and then modify or create the workspace file for our project.

Carthage, by contrast, is much lighter. It also has a description file called Cartfile, but Carthage doesn’t make any changes to our project structure, let alone create a workspace. It simply takes the third-party libraries configured in our description file, downloads them locally, and builds the framework file using XcodeBuild. We then integrate these libraries into the project ourselves. Carthage uses a non-invasive philosophy.

(2) Commonly used third-party libraries

Masonry

Navigation is a lightweight layout framework with its own description syntax. It uses elegant chained syntax to enable automatic layout. It also supports iOS and Max OS X NAVIGATION

AFNetworking

AFNetWorking is a lightweight open source framework for iOS network requests. AFNetWorking is a high-performance framework for iOS network requests based on iOS and MAC OS network extensions

FMDB

FMDB is the SQLite database framework of iOS platform. FMDB encapsulates THE C language API of SQLite in the way of OC [iOS] database third-party framework FMDB explains how to use FMDB in detail

libextobjc

Libextobjc a library that provides a variety of small functions at the language level

FLEX in-app debugger

SDWebImage Image loading framework

Reachability Checks mobile phone network status

MJRefresh pulls down to refresh and pull up to load more components

Toast Toast

MBProgressHUD translucent prompt box

DateTools is used to improve the efficiency of date and time operations in Objective-C. DateTools uses the Date Library.

More:

IOS development uses tripartite libraries, plugins, popular blogs, etc

IOS third-party libraries, plug-ins, summaries of well-known blogs

Part 3 – Tips

(1) Automatic layout

Round 1 – UIScrollview and Autolayout

UIScrollview and Autolayout

ScrollView is special because it has a contentSize property. The contentSize of a ScrollView is determined by the constraints of its subview.

To display properly, use a single containerView and add all subViews to containerView. (kiss)

Round 2 – Constrains where the code is placed

Where should I be setting autolayout constraints when creating views programmatically?

**How to Use updateConstraints? **

UpdateViewConstraints and updateConstraints can be overridden when a large number of constraints need to be updated, and for constraints that are initialized only once and do not need to be modified, it is better to write them into a method like viewDidLoad.

Round 3 – A pit

The Mystery of the +requiresConstraintBasedLayout

Constraint-based layouts are lazy and only automatically call updateConstraints if a constraint is added. If you put all your constraints in updateConstraints the system will not know that your layout is constraint-based. So rewrite + requiresConstraintBasedLayout returns YES is clearly told system: even though I didn’t add restrictions, but I do is based on the constraints of the layout! This ensures that the system calls the -updateconstraints method to add the constraints correctly.

(2) weakSelf

Thoroughly understand weakSelf and strongSelf in block

__weak __typeof(self)weakSelf = self;
[self.context performBlock:^{
    __strong __typeof(weakSelf)strongSelf = weakSelf;
    [strongSelf doSomething];
}];
Copy the code

WeakSelf is required when a block is held directly or indirectly by self. In other cases, there is no problem with adding weakSelf.

Use the libextobJC library to simplify the code:

#import "EXTScope.h"

@weakify(self)
[self.context performBlock:^{
    @strongify(self)
    [self doSomething];
}];
Copy the code

(3) iOS application data store

IOS local data access, just look here

  1. XML property list (PLIST) archive
  2. Preference
  3. NSKeyedArchiver archive (NSCoding) NSKeyedArchiver– Archive objects
  4. SQLite3
  5. Core Data
// TODO: 2017/10/23 Continue to improve this article until the end of the introductionCopy the code

When they are needed, comments should be used to explain why a particular piece of code does something. Any comments that are used must be kept up-to-date or deleted.

— The Official Raywenderlich.com Objective-C Style Guide

(4) iOS singleton mode

A singleton of JAVA design patterns

Use dispatch_once to create a singleton

(5) UI adaptation

Round 1 – Layout of the ViewController

Several properties of the ViewController: edgesForExtendedLayout, automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars

www.jianshu.com/p/ea9e19b7d…

www.jianshu.com/p/9884f1307…

Round 2 – How to layout IOS View

How to do IOS View layout

  • How do I lay out UIViewController’s views
  • The processing of childViewController
  • Autolayout to layout
  • TableView management

Layout principles:

  • Adaptive to screen size changes, such as different size devices, screen rotation, hot spots, phones, etc.
  • NavigationBar or tabBar is displayed with or without it, and you don’t need to check for navigationBar or tabBar yourself
  • Try to avoid hard code spacing, such as 20,44,49, etc

52 Effective ways to write high quality iOS and OS X code

Effective Objective-C 2.0:52 Effective Ways to Write Quality iOS and OS X Code