cellForItem is not called when reloadData

  1. To fix the flash? lightening bug when scrolling the search results I changed reloadData when paging to “insertItems”
  2. After that, when I need to reloadData from SearchResults to SearchHistory, cellForItem is not called for section 0
  3. The reason was realodData is called before insertItems finished
  4. So I made the orders guaranteed using dispatchGroup.
private let insertItemsAndReloadDataGroup = DispatchGroup()

... after getting paged results ....
self.insertItemsAndReloadDataGroup.enter()
             self.collectionView.performBatchUpdates {
                 self.collectionView.insertItems(at: indexPaths)
             } completion: { _ in
                 self.insertItemsAndReloadDataGroup.leave()
             }

... when I go back to searchHistory from searchResult ...
insertItemsAndReloadDataGroup.notify(queue: .main) { [weak self] in
                 guard let self = self else { return }
                 self.reloadDataAndResetScroll()

5. After that I had other problems. Because I used different numbers of sections according to the types of search results. So I changed the code to reloadData when it is not paging, I mean it’s first page.

How iOS app is launched

 

  • main function of main.m and  UIApplicationMain function never returns.
  • UIApplicationMain:
    • application: instantiates the application object from the principal class and
    • instantiates the delegate (if any) from the given class and
    • application delegate: sets the delegate for the application.
    • sets up the event cycle: It also sets up the main event loop, including the application’s run loop, and begins processing events.
    • If the application’s Info.plist file specifies a main nib file to be loaded, by including the NSMainNibFile key and a valid nib file name for the value, this function loads that nib file.

about URLRequest configuration

urlRequest.cachePolicy = .reloadIgnoringLocalCacheData

        urlRequest.httpShouldHandleCookies = false

To configure a session, you use a URLSessionConfiguration object, which controls behavior like how to use caches and cookies, or whether to allow connections on a cellular network.

In some cases, the policies defined in this configuration may be overridden by policies specified by an NSURLRequest object provided for a task. Any policy specified on the request object is respected unless the session’s policy is more restrictive.

When UIImageJPEGRepresentation returns nil

fileprivate lazy var ciContext = CIContext()

guard let cgImage = self.ciContext.createCGImage(outputImage, from: outputImage.extent) else {

                return

           }

            let uiImage = UIImage(cgImage: cgImage)

            guard let image = UIImageJPEGRepresentation(uiImage, 0.9) else {

                return

                

            }

try not to make UIImage directly from ciImage

  1. convert ciImage to cgImage
  2. then convert the cgImage to UIImage

app status, app lifecycle

https://developer.apple.com/documentation/uikit/uiapplicationdelegate

inactive: The app is running in the foreground but is not receiving events.

Background: The app is executing code but is not visible onscreen.

For example, the system may wake up an app so that it can process background downloads, certain types of location events, remote notifications, and other types of events.

An app in the background state should do as little work as possible. Apps that request time to process specific types of events should process those events and return control back to the system as quickly as possible.

https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StrategiesforHandlingAppStateTransitions/StrategiesforHandlingAppStateTransitions.html#//apple_ref/doc/uid/TP40007072-CH8-SW1

https://developer.apple.com/library/archive/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/TheAppLifeCycle/TheAppLifeCycle.html