I'm developing iOS Keyboard Extension, and I load some data of keyboards from plist file. My version is iOS 8.4/Xcode 6.4.
But sometimes(not everytime), when in viewdidload
of InputViewController
, NSDictionary(contentsOfFile:)
returns nil.
It appears when I switched between my keyboard and another one frequently.
What I checked:
- the file is not nil.
- the file name doesnt change at all.
- try again while it is nil.
- contentsOfUrl instead of filepath.
- there are only ascii codes in plist file.
What I'm suspecting:
- file-io problems when the process doesnt end properly.
- swift problems
Thanks to Aderstedt, I checked NSError.
let nsdata = NSData(contentsOfFile: file, options: nil, error: &nserror)
if nserror != nil {
NSLog("load error: \(nserror?.description)")
}
load error: Optional("Error Domain=NSCocoaErrorDomain Code=256 \"The operation couldn\U2019t be completed. (NSCocoaErrorDomain error 256.)\" UserInfo=0x17066c700 {NSFilePath=/private/var/mobile/Containers/Bundle/Application/"My Application", NSUnderlyingError=0x174845df0 \"The operation couldn\U2019t be completed. (NSPOSIXErrorDomain error 24 - Too many open files)\"}")
I fixed this with closing other closing garbage files, and following link was also helpful.
on iOS/iPhone: "Too many open files": need to list open files (like lsof)