“This is the 13th day of my participation in the First Challenge 2022. For details: First Challenge 2022.”

The introduction

Coding Style Apple official documentation:

The Objective-C Programming Language:

Developer.apple.com/library/mac…

Cocoa Fundamentals Guide:

Developer.apple.com/legacy/libr…

Coding Guidelines for Cocoa:

Developer.apple.com/library/mac…

IOS App Programming Guide:

Developer.apple.com/library/ios…

Apple previously announced that from the end of January 2022, apps that allow account creation must also allow users to delete their accounts from the App. Apple says it is giving App publishers and developers more time because it recognises the complexity of providing this feature.

Apple requires apps to have the ability to delete accounts built into them, but with a grace period. Apple has delayed implementation of some rules that were due to take effect on January 31, requiring apps to provide a built-in account deletion function.

I. Objective-c coding specification

1.1 Code Organization

Use #pragma mark – in function grouping and protocol/delegate implementations to classify methods

1.2 annotations

When comments are needed, they should be used to explain why this particular piece of code is doing so.

Any comments used must be kept up to date or removed.

1.3 named

  • Method and variable naming: Apple naming rules are as consistent as possible with long, descriptive method and variable naming
UIButton *settingsButton; 

Copy the code
  • constant: You should use camel case naming, capitalizing all words and prefixing them with class names.
static NSTimeInterval const RWTTutorialViewControllerNavigationFadeAnimationDuration = 0.3;  
// Use string constants instead of macros
// Define const global constants that are defined in one place and referenced in more than one place
////#define HWClientId @""// The macro will replace all references to macro variables at compile time, resulting in many of the same temporary literals, wasting memory
//NSString * const HWClientId = @""; // Global const constants instead of macro constants to save memory. There is only one copy of memory

Copy the code
  • attribute:Attributes are also used in camel case, but the first letter of the first word is lowercase.

Use auto-synthesis for attributes, rather than manually writing @synthesize statements, unless you need to

@property (strong.nonatomic) NSString *descriptiveVariableName; 

Copy the code
  • Local variables should not contain underscores. (To distinguish it from instance variables)

  • Dot syntax should always be used to access and modify properties

    self.isfooterRereshing = NO;

Copy the code
  • All attributes should be explicitly listed to help you read the code.

The order of properties is storage, atomicity, and the Interface Builder automatically generates code when connecting UI elements.

@interface KNTutorial : NSObject 

 @property (strong.nonatomic) NSString *tutorialName;// All attributes should be explicitly listed to help you read the code. The order of properties is storage, atomicity, and the Interface Builder automatically generates code when connecting UI elements.

 @end


Copy the code
  • NSString should use the copy property instead of the strong property.

Because even when you declare an NSString property, someone could pass in an instance of NSMutableString and then modify it without you noticing.

1.4 Members of the structure attribute of the object are not allowed to be modified directly;

In OC, it is not allowed to modify the “origin” of “frame” of “object” (iconButton) directly. However, members of structure attributes are allowed to be modified

- (void)setY:(CGFloat)y{
    CGRect frame = self.frame;
    frame.origin.y = y;// A member that allows modification of structure attributes
    self.frame = frame;
}

Copy the code

1.5 Use CGGeometry to operate the Frame

1.6 Boolean value

  • Objective-c uses YES and NO.

Because true and false should only be used in CoreFoundation, Cor C++ code.

  • Since nil resolves to NO, there is NO need to compare in conditional statements.

Don’t compare something directly to YES, because YES is defined as 1

II Performance correlation

2.1 Replacing macro constants with global const constants saves memory.

  • Use string constants instead of macros

Const const const const const const const const const const const const const const const const const const const const const const const const const const const const const const const const const const const const const const const const const const const const const There is only one copy of memory



#define KNClientId @""// Macros will replace all references to macro variables at compile time, resulting in many of the same temporary literals, wasting memory
NSString * const KNClientId = @ "";// Global const constants instead of macro constants to save memory. There is only one copy of memory

Copy the code

2.2 In-depth understanding of MRC and ARC memory management mechanisms

  1. Resources to be released:ImageCache, Queue, Operations, View, notifies listener to remove, destroy soundID
  2. Release method:Dealloc, applicationDidReceiveMemoryWarning, didReceiveMemoryWarning
  3. In the name of any functionCreate, copy, new, retainAnd so on, should be released when it’s no longer needed. The GCD data type does not need to be released in the ARC environment; While CF data types need to be released in ARC and MRC environments.

2.2

III FaQs

3.1 the Cocoa naming

Property follows Cocoa naming convention for returning ‘owned’ objects

Attributes cannot be defined beginning with the new keyword

Correct property definition

Due to space reasons, more content please pay attention to # small program: iOS reverse, only for you to present valuable information, focus on mobile technology research field; For more services and advice, please follow # publicid: iOS Reverse.