This profile

  • Topic: Talk to a classmate about your recent interview experience.
  • Tips: Design the OC version of defer to create encrypted files in the Fastlane Match format using existing certificates.
  • Interview module: off-screen rendering related knowledge points.
  • Good blog: Organized articles about Swift closures.
  • Learning materials: Introduce two warehouses, one is everyone easy to misread the development vocabulary summary, one is Microsoft produced by the Internet of things course.
  • Development tools: a free open source cross-platform password management tool: KeeWeb.

This topic

@Zhangferry: The subject of this interview is @Qilixiang Fried rice with egg. He is also a small friend in the communication group. Knowing that he just changed his job recently, from a small company to a large factory, I invited him to talk about some feelings of the interview.

Zhangferry: How long did you prepare for the interview and what was your interview experience like?

The whole interview process lasts about one and a half months. In the early stage, I read some things intermittently, and there are about three weeks to prepare for the interview. Many of them were invited to the interview, but some of them were not interested and did not go. In fact, there were 10 Internet companies participating in the interview, all of which were first and second-tier Internet companies. This side also shows that iOS is not just a joke, there is still a lot of demand for iOS development.

Zhangferry: What are some frequently asked questions based on these interview experiences? Have you encountered many algorithms?

Memory management and multithreading are certainly high frequency questions, basically every interview will ask.

Another is project experience, which is also mandatory. This is generally combined with the resume to ask, especially the focus and difficulties of the project, so we must ensure that the content of the resume is very clear. For the company you like very much, you can also optimize your resume according to their business needs.

In addition, the ability of architecture design and packaging will also be examined sometimes, which cannot be rapidly improved in a short period of time. It needs to be deliberately cultivated in the normal work process.

It’s not that much of an algorithm overall, maybe 30% of the time. Those who test the algorithm are also to investigate relatively simple topics, may also be related to the post I interview, this is for reference only, before the interview, how much algorithm or to prepare.

Zhangferry: now people often say eight-part essay for interview, how do you think about it based on your interview experience?

First of all, it is reasonable to exist. The phenomenon of eight-part essay reflects the lack of preparation of the interviewer. May come from the early stage, everyone’s technical level is general, there is not much to ask things, also did not specially research which aspects, so on the Internet to pick pick to ask. The current experience shows that it is ok to be asked a variety of questions, but this phenomenon may become less and less in the future as the level of the interviewer improves.

At the same time, it is a two-way street. If an interview is full of familiar questions, there is a high probability that the company has not paid enough attention to the technology and can lower its priority.

Zhangferry: any advice on how to deal with people who are interviewing for a job?

There are many reasons for these phenomena. For example, the post is just full, the post demand has changed and so on. Do not deny yourself first. The interview process must be calm, no psychological pressure.

Finally, I wish all ready to find and are looking for a job partners can get a satisfactory Offer.

The development of Tips

Implement the defer feature in Swift in Objective-C

RunsCode, Zhangferry

The desired effect is that before the function exits the stack, it executes what is defined in defer.

- (void)hello:(NSString *)str {
    defer {
        // do something}}Copy the code
The preparatory work

To implement defer, you need instructions for functions to trigger the closures in defer when scoped out of the stack. There are two things you need to do:

__attribute__ : a compiler directive that specifies attributes at declaration time, which allows for more error checking and advanced optimization.

For more information, see: nshipster.cn/__attribute…

cleanup(…) : accepts a function pointer that is fired when the scope ends.

Simple and practical

At this point, we have a general understanding of the function, so let’s practice:

#include <stdlib.h>
#include <stdio.h>

void free_buffer(char **buffer) { printf("3. free buffer\n"); }
void delete_file(int *value) { printf("2. delete file\n"); }
void close_file(FILE **fp) { printf("1. close file \n"); }

int main(int argc, char **argv) {
    // The execution order is the reverse of the pushdown order
    char *buffer __attribute__ ((__cleanup__(free_buffer))) = malloc(20);
    int res __attribute__ ((__cleanup__(delete_file)));
    FILE *fp __attribute__ ((__cleanup__(close_file)));
    printf("0. open file \n");
    return 0;
}
Copy the code

Output result:

0. open file 
1. close file 
2. delete file
3. free buffer
[Finished in 683ms]
Copy the code

But at this point, it’s not convenient for us to use, let alone ios, which is not friendly. So let’s go ahead and make it objective-C exclusive.

Practical optimization

What else do you need to achieve that ideal?

  • Code block, that has to beNSBlock
typedef void(^executeCleanupBlock)(void);
Copy the code
  • Macros or global functions? The thought ofObjective-CSince there is no such thing as a trailing closure, global functions will not work, so only global macros will work
#ifndef defer
#define defer \
__strong executeCleanupBlock blk __attribute__((cleanup(deferFunction), unused)) = ^
#endif./ / m file
void deferFunction (__strong executeCleanupBlock *block) {
    (*block)();
}
Copy the code

OK, we’re done. Run

defer {
    NSLog(@"defer 1");
};
defer { // error: Redefinition of 'blk'
    NSLog(@"defer 2");
};
defer { // error: Redefinition of 'blk'
    NSLog(@"defer 3");
};
NSLog(@"beign defer");
Copy the code

Error: Redefinition of ‘BLK’ error: Redefinition of ‘BLK’ (Think about it)

There are two things you need to know about the final solution

  • __LINE__: Gets the current line number
  • # #: Joins two characters
#define defer_concat_(A, B) A ## B
#define defer_concat(A, B) defer_concat_(A, B).// Why is there an underline macro, because only one macro can be expanded at a time, and the correct line number of __LINE__ is unwrapped at the second level
Copy the code

Final plan

Okay, that’s it. It’s time to show some real kung fu

#define defer_concat_(A, B) A ## B
#define defer_concat(A, B) defer_concat_(A, B)

typedef void(^executeCleanupBlock)(void);

#if defined(__cplusplus)
extern "C" {
#endif
void deferFunction (__strong executeCleanupBlock _Nonnull *_Nonnull block);
#if defined(__cplusplus)
}
#endif

#ifndef defer
#define defer \
__strong executeCleanupBlock defer_concat(blk, __LINE__) __attribute__((cleanup(deferFunction), unused)) = ^
#endif
/ / m file
void deferFunction (__strong executeCleanupBlock *block) {
    (*block)();
}
Copy the code

That’s all there is to implement the OC version of Defer.

This is the end of the story, but one more note: this is a bit different from Justin Spahr-Summers’ implementation in Libextobj (@onexit {}). The current implementation is simpler and the functionality in libextobJ is a bit richer.

Create an encrypted file in Fastlane Match format using an existing certificate

It encrypts the certificate file to git repository, uses the clone repository to decrypt the certificate file, and then installs the certificate into the local keychain. This way certificates can be happily shared across different devices.

Match creates a certificate in either of the following ways:

  • fastlane match nukeRevoke the original certificate to create a new one. This will render the original certificate unusable. This is not recommended if you have multiple App accounts.
  • Using an existing certificate, export asmatchFormat encrypted files for maintenance.

The second scheme does not affect the use of the original certificate and is recommended. However, there are very few online introductions of this kind of scheme, so I will simply summarize:

1. Export the file

You need to export the certificate and p12 files and put them in a specific folder. Assume their names are cert.cer and cert.p12 respectively.

2. Use OpenSSL for encryption

A default password is required, which can be customized as a specific parameter for encryption and decryption.

$ openssl enc -aes-256-cbc -k {password} -in "cert.cer" -out "cert.enc.cer" -a -e -salt
$ openssl enc -aes-256-cbc -k {password} -in "cert.p12" -out "cert.enc.p12" -a -e -salt
Copy the code

3. Push the certificate to git repository

Each certificate file has a specific ID, and we need to change the file name of the encrypted certificate before pushing it. This ID is displayed at the bottom of the developer website’s certificate details page. The one where the lower part of the code is obscured:

We then put those two files under the corresponding type (development/distribution) in the certs directory of the Git repository and push them.

4, the use of

Env is a global variable. It has a specific variable name MATCH_PASSWROD. To download and install the certificate, use the following statement:

$ fastlane match development
$ fastlane match adhoc
Copy the code

Reference: docs. Fastlane. Tools/actions/mat…

Parsing the interview

Edited by FBY Zhan Fei

This interview explains the relevant knowledge points of off-screen rendering.

Why do rounded corners and clipped iOS draws trigger off-screen rendering?

By default, each view is drawn and rendered completely independently. When a parent view has rounded corners and clipping and has child views, the parent view will only clipping and rendering itself.

When the subview is drawn, it is necessary to consider the rendering and rendering processing of the clipping part of the parent view, so it is necessary to recursively recall and copy the rendering context and clipping information of the parent view repeatedly, and then merge it with the subview to complete the final clipping effect. This is bound to produce a large amount of time and memory overhead.

The solution is to create a separate drawing context when the parent view is clipped and has rounded corners and child views. The content of the parent view and all child views are drawn in this context. In this way, the view does not need to be drawn separately, and all clipping is handled in the same way. The buffer context is copied to the screen context when the superview is drawn. This process is called off-screen rendering!!

So off-screen rendering is actually very similar to the dual-cache technique where we first draw the content in bitmap memory context and then uniformly copy it into the on-screen context. Off-screen rendering is a technique that had to be used due to some of the limitations of the view-independent rendering technology within iOS.

Recommended reading: An in-depth look at iOS off-screen rendering

Good blog

Edit: King Pilaf here, FBY exhibition

The subject of this installment: Swift closures

Swift closure based type erasure — from public account: Swift community

This article focuses on one situation that can occur when dealing with generics in Swift, and how closure based type erasure techniques are commonly used to address this situation.

Swift closures (closure expressions, trailing closures, escape closures, automatic closures) — From nuggets: NewBoy

A primer on Swift closures that integrates nearly all of the concepts and usage of Swift closures. More suitable for Swift beginners or from OC to Swift students.

Day6-swift closure details — from wechat public number: iOS growth refers to north

Day7-swift closure details — from wechat public number: iOS growth refers to north

Swift closure learning two articles, also contains the concept and usage of Swift, part of the usage and concept more detailed. The two articles are the results of the author’s learning and thinking, so there is some understanding of the author in the article, which is more important for our learning, and relatively easy to understand.

Closures — From: Swift Document

Zhangferry: The official documentation is very necessary to understand the concept. Closures in Swift have a similar meaning to blocks in C/OC and Lambda in other languages. Closures and blocks are fully compatible when Swift and OC are mixed. But there’s still a difference in meaning. Blocks are more about anonymous code blocks, and closures are about true first-level objects in addition to that.

Learning materials

Mimosa

Chinese programmers tend to pronounce wrong words

Address: github.com/shimohq/chi…

Are you worried your colleague won’t understand a word you’re pronouncing while discussing code? Come across a word you can’t pronounce while reviewing code in a meeting? If you’ve had any of these problems, take a look at this Github repository. It’s a repository of the most mispronounced words in the programming world, and currently has 14.4K stars, which identifies the most mispronounced and correct sounds, and supports online listening.

IoT for Beginners

Address: github.com/microsoft/I…

This is the Internet of Things course from Microsoft Azure. It’s a 12-week 24 class course that has all the basics of the Internet of Things. Each class includes pre-class and after-class quizzes, written instructions for completing the course, solutions, assignments, and more. Each project is real-world hardware suitable for students or hobbyists, and each project provides relevant background knowledge to study specific project areas.

Tools recommended

zhangferry

KeeWeb

Address: keeweb. Info /

Software status: Free, open source

Software Introduction:

KeeWeb is a browser and desktop password manager compatible with KeePass databases. It does not require any servers or additional resources. The application can be run in a browser or as a desktop application. What’s more, it can sync remotely with Dropbox and Google Drive.

About us

IOS Fish weekly, mainly share the experience and lessons encountered in the development process, high-quality blog, high-quality learning materials, practical development tools, etc. The weekly warehouse is here: github.com/zhangferry/… If you have a good content recommendation, you can submit it through the way of issue. You can also apply to be our resident editor to maintain the weekly. Also can pay attention to the public number: iOS growth road, backstage click into the group communication, contact us, get more content.

Phase to recommend

IOS Fishing Weekly 23rd issue

IOS Fishing Weekly Twenty-second issue

IOS Fishing Weekly 21st issue

IOS Fishing Weekly 20th issue