IOS Fishing weekly, mainly to share the experience and lessons encountered in the development process and learning content. One purpose of the establishment is to develop knowledge fragmentation, which requires a place to summarize and review; The other is to remind myself of continuous learning, inside the increasingly serious development environment, not to advance is to fall back.
Although it is a weekly newspaper, the current way of contributing content has not been stable. If there is less than one issue of subsequent content, it may be postponed to the next week. So I hope you can share your development tips and bug solving experiences.
The weekly warehouse is here: github.com/zhangferry/… You can see the README for how to contribute.
The development of Tips
Development tips included.
Several useful Git commands
Overrides the last COMMIT
When we have finished developing a part of a feature, we commit it. If we find that the corresponding feature has not changed something, we can make a separate commit flag for this small change, but it is more recommended to merge the two changes into the same command:
$ git commit --amend -m "message"
Copy the code
Merge multiple Commits
If you want to merge multiple commits that have been generated, you can use:
$ git rebase -i [startpoint] [endpoint]
$ git rebase -i HEAD~2 # merge the last two commits
Copy the code
The endpoint defaults to the HEAD node to which the current branch points. The -i parameter indicates interactive. After this command is executed, a VIM interactive editing interface is displayed. The following parameters are described:
Pick: Keep the commit (p) reword: Keep the commit, but I need to modify the comment on the commit (R) Edit: Keep the commit, but I need to stop and modify the commit (not just the comment) (e) Squash: Exec: Execute shell command (x) DROP: discard the commit (d)Copy the code
Permanently delete git binaries
If we forget to add a binary to.gitignore during development and put it in a Git file, it will always be there. For example, the Pod directory, when the introduction of many libraries, git files will become bigger and bigger, even if later added to the.gitignore, git history will have a record, this cannot be deleted. Fortunately, Git provides us with a remedy:
git filter-branch --tree-filter 'rm -f target.file'
Copy the code
Delete statements can be executed in the following commands. Note that this command overwrites git history and should be used with caution when working with multiple people.
Git repository migration
Git repository migration is available on some Git management platforms such as GitLab and Github. It is recommended to use the method provided by the platform. If not, we can use git statement operation:
git clone --bare git@host/old.git Clone the bare warehouse of the original warehouse
cd old.git
git push --mirror git@host/new.git Push to a new repository using the mirror parameter
Copy the code
Internationalization/localization considerations
The distinction between internationalization and localization is subtle but important. Internationalization means a product has the “potential” to be used everywhere; Localization is the addition of features that are more suitable for use in “specific” places. For a product, internationalization only needs to be done once, but localization needs to be done once for different regions. The two are complementary, and together they make a system that works everywhere.
In addition to big head language localization, there are layout, characters, dates, numbers and other localization work, for more information, you can refer to iOS internationalization and localization (a) different language differences processing and testing.
Here are two points, date format and numeric representation:
The date format
The date format in China is YYYY-MM-DD, which is the format of year, month and day. However, it varies by region.
Yyyy-mm-dd: China and Canada
Mm-dd-yyyy: Saudi Arabia
Dd-mm-yyyy: Most countries in Europe, Russia, most countries in Africa, and South America
The U.S. is useful for both MM-DD-YYYY and DD-MM-YYY formats.
Reference: zh.wikipedia.org/wiki/%E5%90…
The figures show that the
Thousandths are written in three different ways, comma, period, and space, and the decimal point is written in two different ways: period, comma. Usually, for the sake of differentiation, the same symbol is not both a thousandth and a decimal point. To avoid ambiguity, international standards recommend using Spaces for thousandths rather than Spaces or decimal points.
For example, one million two hundred and thirty-four thousand five hundred and sixty-seven point eight and nine:
China, United States, Australia: 1,234,567.89
Germany, Netherlands: 1 234 567,89 or 1.234.567,89
France, Italy: 1, 234, 567,89
Reference: zh.wikipedia.org/wiki/%E5%B0…
The bug
Cateogry and Extension use the same name Extension issue
Problem source: L770826421
What do bugs look like?
The same name extension is used when extending a class of the SDK
The Extension Extension
@interface LSDeviceInfo (LSWatch)
@property(nonatomic, assign) LSWatchType type;
@end
Copy the code
The Cateogry extension implements the getter method for Type
@interface LSDeviceInfo (LSWatch)
- (LSWatchType)type;
@end
Copy the code
Errors don’t happen every time. Xcode12.3 starts out as an occasional occurrence and continues to report errors.
Unable to execute command: Segmentation fault: 11 Clang frontend command failed due to signal (use -v to see invocation) Diagnostic msg: Both PLEASE submit a bug report to developer.apple.com/bugreporter… and include the crash backtrace, preprocessed source, and associated run script. Diagnostic msg:
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: Diagnostic msg: /var/folders/tp/4kw93qbn7tb20cbpn14fmwk00000gn/T/RLWifiConfigFailedViewController-243a91.m
How is it solved?
This error is resolved by setting the Cateogry and Extension extensions to be different.
Bug-induced introspection
Extension is defined at compile time, which is part of the class, at compile time and in the @Interface header file and in the implementation file. The name of the extension extension is the same as that of the category. At this time, there may already be data with the corresponding name in the hashTable. When the category is added, an error will occur. May be mistaken thought maintenance at this time of the Xcode hashTable table error, to submit corresponding bug to developer.apple.com/bugreporter…
Programming concepts
What is a Clang
Clang is a compiler front end for C, C++, Objective-C, and Objective-C++ programming languages. It aims to provide an alternative to the GNU compiler suite (GCC), which supports most of the GNU compiler’s compilation Settings as well as extensions to unofficial languages. The author is Chris Lattner.
The ClANG project includes the ClANG front end and the ClANG static analyzer. The implication of the compiler front end is that Clang cannot directly compile source code into machine code, whereas Clange can output an abstract syntax tree of the source code and compile the code into LLVM bitcode.
Clang itself performs well, using only about 20% of the memory used by the AST, compiling Objective-C code three times faster than GCC, and making accurate recommendations for user-generated compilation errors.
What is the LLVM
LLVM (Low Level Virtual Machine) is a free software project that is a compiler infrastructure, written in C++, containing a series of modular compiler components and toolchains for developing compiler front and back ends. It is a program written for any programming language that uses virtual techniques to create compile-time, link-time, run-time, and “idle time” optimizations.
LLVM has two meanings. In the broad sense, LLVM refers to a complete compiler architecture, including front end, back end, optimizer, and so on.
LLVM in a narrow sense only refers to a series of modules and libraries of compiler back-end functions. Middleware compiled by Clange is transformed into the corresponding machine code through LLVM back-end processing.
What are the ld
A Linker is a program that links one or more object files plus libraries generated by a compiler or assembler into an executable file.
Ld is the GNU linker, llvm4 have a linker LLD, but LLD run on macOS and problem (lists.llvm.org/pipermail/c…
Other Linker Flags in Build Setting specifies the ld command parameters.
In Xcode, it has three commonly used arguments:
-Objc: The linker loads all objective-C classes and categories in the static library into the final executable file
-all_load: causes the linker to load all the found object files into the executable, but may encounter duplicate symbol errors
-fore_load: specify the path to load the library file and load all the target files into the executable file.
What is a dyld
Dyld (The Dynamic Link Editor) is apple’s dynamic linker, which is responsible for linking and loading programs. It is an important part of Apple’s operating system.
Dyld differs from LD in that it is mainly used for loading system dynamic libraries. Dynamic libraries relied on, such as Foundation and UIKit, are recorded in MachO, and loaded by DYLD when the application is started. The first load puts the dynamic libraries in the shared cache, and the applications that need to load them can access the shared cache directly to load the dynamic libraries, and then link to the main program.
Dyld belong to the open source project, address: opensource.apple.com/tarballs/dy…
What is a bitcode
Bitcode is the intermediate representation of a compiled program. In Xcode, bitcode corresponds to a configuration that indicates whether bitcode is enabled or not.
Apps that contain bitcode and are uploaded to App Store Connect are compiled and linked on App Store Connect. Including bitcode allows Apple to optimize your App binaries again in the future without submitting a new version of the App. For iOS Apps, Enable bitcode defaults to YES and is optional (it can be changed to NO). Bitcode is mandatory for WatchOS and tvOS. If your App supports Bitcode, all Apps and frameworks in the App Bundle (all targets in the project) need to include Bitcode.
Apple recommends that bitcode be turned on for iOS projects and forces watchOS to turn on Bitcode.
Since projects containing Bitcode are recompiled in App Store Connect, their symbol table files depend on the compiled results, so you need to download the corresponding dSYM files from App Store Connect.
What is a linkmap
The source code we write is compiled, linked, and finally produced into an executable file. At compile time, a corresponding.o file (object file) is generated for each class. In the linking phase, the.o files are linked together with the dynamic library.
Linkmap (Link Map File) is a plain text File that records Link information, including executable File paths, CPU architecture, target files, and symbols. It can be used to analyze the size of each module after iOS compilation, and there are several tools available on the web to help analyze the file directly.
If you search for map in Build Setting, you can see the write Link Map File option, which sets the export path of linkmap file.
Good blog
GitHub 2020 Report: Work-life Balance for Developers worldwide — from Digger: LeviDing
Techo Park – Revolution of Flutter and big Front end — from Nuggets of gold: Love cat de Guo
WWDC20 iOS14 Runtime optimization — from the public number: knowledge small set
How to use Swift to write CLI tools — from the public account: Yigua technology
Ali 10 Years: The Growth of an ordinary technical person — from nuggets: Alibaba Cloud native
2020 has just come to an end, and there are some very well-written year-end summaries to check out:
Written on the last day of 2020 — from the official account: the Path to iOS growth
How to continuously improve yourself — from the official account: Cool Temple of Sorrow
2020 cxuan annual essay – from the nuggets in Denver | nuggets: cxuan
Middle-aged naked resignation, my 2020 | Denver annual essay – from the Denver nuggets: Semo
2020: Maladaptive perfectionism, existentialist philosophy, architecture, fund doubling, effective rest | Nuggets of the Year essay — from nuggets: FeelsChaotic
Learning materials
The wisdom of Questioning
It’s not uncommon to encounter problems during development, and solving them involves asking questions to others or community forums, and how well you ask questions can often determine whether or not you get the answers you want. There’s a Github repository called How-to-ask-questions-the-Smart-Way Star with a whopping 13.7K of how-to-ask-questions-the-Smart-Way Star on How To Ask Questions effectively, and many forums use this as a guideline To remind people of The importance of effective Questions.
A good question, that is, to express their desire for the answer to the question, but also to express respect for the answer.
LeetCode Cookbook
The solution of leetcode algorithm summarized by Halfrost is completed by using go language, and all the codes in the book have been beats 100%.
Development tool
Good development tools are recommended.
A Companion for SwiftUI
Recommended source: AlleniCode
Download: apps.apple.com/cn/app/a-co…
Software status: Paid ¥328.00
A Companion for SwiftUI is an app that records the views, shapes, protocols, scenes and properties of SwiftUI for iOS and macOS platforms. The application also contains examples of each method, many of which are interactive and run embedded in the application. By using the associated controls, you can see how they directly affect your view and how you can modify your code to do so.
Go2Shell – Opens the current Finder directory in the terminal
Source: RayLeeBoy
Download it at zipzapmac.com/go2shell
Software status: Free
Introduction to use:
- Double-click on the downloaded file and drag Go2Shell into the Applications directory
- In Applications, double-click to open Go2Shell and the window below appears
- Click Install Go2Shell to Finder to complete the installation
- Open a Finder window and the Go2Shell icon appears in the toolbar
- Clicking the Go2Shell icon opens the current Finder directory in the terminal
Use Alfred to create shortcuts to open the terminal
This is the one I’m using now, if you need to install Alfred: Select a file, press Command+ T, and you can open the terminal and navigate to that folder. It is similar to the Go2Shell implementation, but it does not rely on Finder and is friendlier to desktop files.
The implementation is as follows:
1. Create HotKeys for Workflows and edit Command + T
2, right-click the HotKeys > Insert After > Actions > Run Script to create a new Script
In the Script editing window, select /usr/bin/osascript(AS), which means Apple Script
4. Enter the following script in the script box and save:
tell application "Finder"
-- get selection path
set pathFile to selection as text
set pathFile to get POSIX path of pathFile
-- fix space problem in the directory
set pathFile to quoted form of pathFile
tell application "iTerm"
create window with default profile
tell current session of current window
write text pathFile
end tell
end tell
end tell
Copy the code
This script is set up for the iTerm terminal.