common crash

1. The default value of the parameter

  • Using pointers requires non-null judgment
  • nil judgment
  • [NSNull null] Judgment

NSDictionary&&NSArray

  • The code uses setObject:forKey and other initializations in many places. If nil is inserted, it will crash
  • When AddObject, add nil will crash
  • objectForKey: wrong type

wrong data type

Simply judge that dictionary and array are not empty, and there is actually no data in them. The data returned by the backend is judged by type, dictionary, array

array out of bounds

  • When objectAtIndex takes a value, you must make an array size judgment to prevent out-of-bounds values. When it comes to index, it is best to check

substringWithRange/substringFromIndex/substringToIndex

Operations involving range need to do some judgment on the length of NSString

textView.text = [textView.text substringWithRange:NSMakeRange(0, 100)];

Using delegate, Notification NSTimer is not canceled

After using delegate, Notification, and NSTimer, you should pay attention to cancel it if you don't use it. It often happens that the controller has been destroyed, and the callback will cause a crash.

Project circle, navigation delegate, collectionview, tableview

When using unfamiliar APIs

When you are not familiar with the system api, check the minimum version supported by the api. When the api of a higher version is used in a lower version, it will cause a crash.

multithreaded operation

Define the life cycle of the function, the end of the animation, the use of blocks, multi-threaded read and write, and the use of multi-threaded functions.

While traversing the array, it changes the order of the array

 

The operation of exchangeObjectAtIndex:withObjectAtIndex insert del when enumerateObjectsUsingBlock is traversed

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327043688&siteId=291194637