[default] [ERROR] Could not create a bookmark: NSError: Cocoa 257 “The file couldn’t be opened because you don’t have permission to view it.”

Environment

Swift
iOS 14.4
On a real iPhone 8 device

Code

   func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
        // close picker
        picker.dismiss(animated: true, completion: nil)
        // check canceled
        if results.count == 0 {
            debugPrint("PHImagePicker was canceled")
            return
        }
        if let itemProvider = results.first?.itemProvider,
           itemProvider.canLoadObject(ofClass: UIImage.self) {
            itemProvider.loadObject(ofClass: UIImage.self, completionHandler: {image, error in
                // do something.
            })
        }
    }

Symptom

When an image is selected by PHPicker, the following error message was reported.

2021-02-20 00:12:24.794146+0900 *** [6290:1858791] [default] [ERROR] Could not create a bookmark: NSError: Cocoa 257 “The file couldn’t be opened because you don’t have permission to view it.” }

Main Thread Checker: UI API called on a background thread: -[UIImageView setImage:]

Error Message #1

Could not create a bookmark: NSError: Cocoa 257 “The file couldn’t be opened because you don’t have permission to view it.”

Solution #1

So far, the code works for me as expected with the message. It seems the error message could be ignored.

Stay tuned with the Apple Developer Forum

Error Message #2

Main Thread Checker: UI API called on a background thread: -[UIImageView setImage:]

Cause #2

imageView has been accessed from the PHPicker completion handler as follows.

itemProvider.loadObject(ofClass: UIImage.self,
completionHandler: {image, error in
                     guard let image = image as? UIImage 

GUI operations should be called in the main thread.

Solution #2

In the completionHandler, image should be handled in the main thread.

   func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
        // close picker
        picker.dismiss(animated: true, completion: nil)
        // check canceled
        if results.count == 0 {
            debugPrint("PHImagePicker was canceled")
            return
        }
        if let itemProvider = results.first?.itemProvider,
           itemProvider.canLoadObject(ofClass: UIImage.self) {
            itemProvider.loadObject(ofClass: UIImage.self, completionHandler: {image, error in
                DispatchQueue.main.async {
                    guard let image = image as? UIImage else {
                        debugPrint("Error: UIImage is nil")
                        return }
                    self.imageView.image = image
                }
            })
        }
    }


Cannot initialize kernel with given library data.

Error

2021-02-19 10:12:59.279429+0900 **** [58937:5072989] [api] +[CIKernel kernelWithFunctionName:fromMetalLibraryData:options:error:] Cannot initialize kernel with given library data.

Fatal error: ‘try!’ expression unexpectedly raised an error: Error Domain=CIKernel Code=6 “(null)” UserInfo={CINonLocalizedDescriptionKey=Cannot initialize kernel with given library data.}: file ****/MyFilter.swift, line 11

2021-02-19 10:12:59.280439+0900 ****[58937:5072989] Fatal error: ‘try!’ expression unexpectedly raised an error: Error Domain=CIKernel Code=6 “(null)” UserInfo={CINonLocalizedDescriptionKey=Cannot initialize kernel with given library data.}: file ****/MyFilter.swift, line 11

Cause

The Metal Compiler and Linker flags have not been set.

Solution

Add the following -fcikernel flags to the Build Settings.

Xcode compile error

Symptom

After adding DatePicker, set properties and compile, and then the following error message was reported.

/Users/*****/Main.storyboard:1:1: Internal error. Please file a bug at feedbackassistant.apple.com and attach “/var/folders/gm/t2l4p33d1r9gpqzscb8kdggw0000gn/T/IB-agent-diagnostics_2020-12-13_14-22-11_398000”.

Cause

Unknown.

In my case, I added DatePicker with count down timer for macCatalyst. And added a few lines of code to change properties. Then, suddenly the error came up. After removing the DatePicker control and then it was solved. I guess it would be a Xcode bug.

Solution

Clean build and rebuild did not work.

Close and reopen the project did not work.

Restart Xcode did not work.

Removed the DatePicker control and rebuild, then it worked.

framework not found after pod install

Symptom

  1. Create a new Swift project on Xcode.
  2. Close Xcode
  3. Run pod init.
  4. Edit the Podfile and add a framework.
  5. Run pod install.
  6. Restart Xcode from ***.xcodeproj
  7. Run build and then “ld: framework not found framework-name” will come up.

Solution

Restart Xcode from ***.xcworkspace, not ***.xcodeproj.

If you restart Xcode from ***.xcodeproj, it does not recognize the newly installed framework.

If you restart Xcode from ***.xcworkspace, Xcode recognizes the newly installed framework as shown below.

Right after the pod install, you can find the ***.xcworkspace file is created at the same directory of ***.xcodeproj.

Style Transfer Demo

 About U^2-Net for human portrait drawing

U^2-Net for human portrait drawing is so cool. I’m just curious that the Style Transfer could do the similar conversion or not. Here is the evaluation result.

Train Image

I used the following partial image from the U2-Net sample image as a training style image.

Parameters

Use Case: Video

Iterations: 400

Other Parameters: Default

Result

I implemented the human portrait drawing by the Style Transfer with Create ML. Here is the result.

Style Transfer Demo on iPhone8

malloc: nano zone abandoned due to inability to preallocate reserved vm space.

Symptom

malloc: nano zone abandoned due to inability to preallocate reserved vm space. message is displayed when the “Thead Sanitizer” of “Diagnostic” is checked.

Solution

A default Swift Project for iPhone with no control shows this message, when the “Thead Sanitizer” of “Diagnostic” is checked.

It means this message can be ignored, I believe.

nw_protocol_get_quic_image_block_invoke dlopen libquic failed

Symptom

nw_protocol_get_quic_image_block_invoke dlopen libquic failed” error always occurs.

        if let url = URL(string: baseUrlStr) {
            let task = URLSession.shared.dataTask(with: url) {(data, response, error) in
            }
            task.resume()
        }

Solution

Just ignore the error.

I tested the code above within main thread and global thread, and the error message was displayed in both cases. There is no way to avaid this error at this moment.

https://forums.swift.org/t/swift-firebase-connection/41632/6

Singleton

final class Settings {
    let userDefaults = UserDefaults.standard
    
    public static let shared = Settings()

    let defaults: [String : Int] = ["minute" : 4, "second" : 59]
    
    private init() {
        self.minute = userDefaults.integer(forKey: "minute")
        self.second = userDefaults.integer(forKey: "second")
    }

    private var _interval: Int = 0
    var interval: Int {
        get {
            return _interval
        }
        set {
            _interval = newValue
        }
    }
    
    private var _minute: Int = 0
    var minute: Int {
        get {
            return _minute
        }
        set {
            _minute = newValue
        }
    }
}

-------------------------
        // 設定を初期化する
        let _ = Settings.shared

        minStepper.value = Double(Settings.shared.minute)

error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x18).

Reference

Symptom

error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x18).

The process has been returned to the state before expression evaluation.

Investigation

In Xcode, Menu >> Product >> Scheme >> Edit Scheme

From Run >> Diagnostics >> Check Runtime Sanitization

Solution

In my case, accessed timer.userInfo which timer has been already invalidated. It was due to multiple async timer invocations. Inserted timer.isValid check just before accessing timer.userInfo.

“Generic error”: Insufficient Permission (to submit GPU work from background)

Symptom

[espresso] [Espresso::handle_ex_plan] exception=Espresso exception: “Generic error”: Insufficient Permission (to submit GPU work from background) (IOAF code 6); code=7 status=-1

Solution

Background Apps May Not Execute Commands on the Graphics Hardware, at this moment.