- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
错误发生在两个地方,都在调用 managedObjectContext。它在过去几天工作正常。然后我在上面运行得很干净,现在我收到了这个错误。因为它一直在工作,所以我不知道去哪里看。我得到的错误是 fatal error :在展开可选值时意外发现 nil。错误发生在 let managedContext =.... 我是核心数据的新手所以让我知道您需要查看哪些其他代码。我还包含了我的 appDelegate,
override func viewDidLoad() {
super.viewDidLoad()
let appDelegate =
UIApplication.sharedApplication().delegate as! AppDelegate
let managedContext = appDelegate.managedObjectContext
self.context = managedContext
try! self.fetchResultsController.performFetch()
self.fetchedResultsController.delegate = self
}
import UIKit
import CoreData
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var context: NSManagedObjectContext!
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
//context = self.managedObjectContext
return true
}
func applicationWillResignActive(application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
// Saves changes in the application's managed object context before the application terminates.
self.saveContext()
}
// MARK: - Core Data stack
lazy var applicationDocumentsDirectory: NSURL = {
// The directory the application uses to store the Core Data store file. This code uses a directory named "com.JohnnyCox.SalesCRM" in the application's documents Application Support directory.
let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
return urls[urls.count-1]
}()
lazy var managedObjectModel: NSManagedObjectModel = {
// The managed object model for the application. This property is not optional. It is a fatal error for the application not to be able to find and load its model.
let modelURL = NSBundle.mainBundle().URLForResource("SalesCRM", withExtension: "momd")!
return NSManagedObjectModel(contentsOfURL: modelURL)!
}()
lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator = {
// The persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail.
// Create the coordinator and store
let coordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel)
let url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("SingleViewCoreData.sqlite")
var failureReason = "There was an error creating or loading the application's saved data."
do {
try coordinator.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil)
} catch {
// Report any error we got.
var dict = [String: AnyObject]()
dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data"
dict[NSLocalizedFailureReasonErrorKey] = failureReason
dict[NSUnderlyingErrorKey] = error as NSError
let wrappedError = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict)
// Replace this with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog("Unresolved error \(wrappedError), \(wrappedError.userInfo)")
abort()
}
return coordinator
}()
lazy var managedObjectContext: NSManagedObjectContext = {
// Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) This property is optional since there are legitimate error conditions that could cause the creation of the context to fail.
let coordinator = self.persistentStoreCoordinator
var managedObjectContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
managedObjectContext.persistentStoreCoordinator = coordinator
return managedObjectContext
}()
// MARK: - Core Data Saving support
func saveContext () {
if managedObjectContext.hasChanges {
do {
try managedObjectContext.save()
} catch {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
let nserror = error as NSError
NSLog("Unresolved error \(nserror), \(nserror.userInfo)")
abort()
}
}
}
最佳答案
在到处搜索答案后,我找到了简单的答案。我已经重命名了我的 coredata 文件,并且没有更改 appDelegate 中要求它的一行。希望这可以帮助其他人了解这个非常明显的答案。
关于ios - 清理后,managedObjectContext 为 nil 并导致 fatal error : unexpectedly found nil while unwrapping an optional value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30968080/
我需要为元素属性动态构建 XPath 查询,其中属性值由用户提供。我不确定如何清理或清理此值以防止 XPath 等同于 SQL 注入(inject)攻击。例如(在 PHP 中): xpath("//m
问题很简单:在使用 PHPmailer 类时我应该使用任何类型的清理吗? 我制作了使用 phpmailer 类发送电子邮件的简单发送邮件表单。目前我只使用“htmlspecialchars”进行清理(
你可以在python中创建一个在for循环退出时运行清理代码的迭代吗?就像是: from random import randint class Iterable: def __iter__(
假设我定期将数据插入 SQLite 数据库,然后清除前 50% 的数据,但我不清理。 我现在是否有类似文件前 50% 的清零页面之类的东西?如果我添加另一批数据,我是否正在填写那些清零的页面? 手册中
我有一堆 HTML 代码,我想在其中删除所有 HTML 标记。 我认为 Regex(正则表达式)可以做到这一点。通过搜索和替换,我将如何执行此操作? 我尝试了 ,我认为 * 是通配符,但显然不是。
我仍在学习 Haskell,我想知道是否有一种不太冗长的方法来使用 1 行代码来表达以下语句: map (\x -> (x, (if mod x 3 == 0 then "fizz" else "")
我需要怎么做才能正确清理/转义程序化SSH命令中输入的参数? 例如,路径参数- public boolean exists(String path) { try { Chann
这个问题已经有答案了: How to clear the canvas for redrawing (25 个回答) 已关闭10 个月前。 我目前正在尝试创建一个带有雨滴落下的 Canvas ,我唯一
我目前正在使用此过程来清理/过滤用户输入的评论 -> 这个是用来去掉斜线的……和 if (get_magic_quotes_gpc()) { function stripslashe
是否可以在 portal_setup 中删除旧的导入配置文件。 目前,我的网站上有许多可追溯到 2009 年的条目:: import-all-profile-Products.Archetypes_
假设我有多个指令,包括以下内容: ...template content... ...template content... 你如何销毁指令?通常我会在 jquery 中做一些我 $('#2').re
我正在开发一个可移植java应用程序,它可以在用户的PC(Windows XP)上动态生成一些文件。现在,我想要的是在java程序退出后删除这些临时文件。显然,java的文件删除机制是不可信的。即
我有一个 argv c 程序,它反转单词,并查看它是否是回文。我只是想清理输出并让它打印原始输入而不是相反的输入,但由于它是 argv,我似乎不知道该怎么做。 int main(int argc, c
我的网页上有一篇用 markdown 写的文章,我想在索引页上显示一份简短的简历。 问题是正文有markdown,我想在简历上显示纯文本。 例如: Article text: Hello people
在下面的代码片段中,可以做些什么来a)让编译器安静,b)清理交叉的指针困惑? extern struct tree *sintablein[sintablesize]; struct tree *(*
我试图弄清楚 WeakHashMap 在垃圾收集后如何清理。正如你们中许多人可能知道的那样,当 WeakHashMap 条目的键被垃圾回收时,它会自动删除。但是,例如,如果我做这样的事情: List>
我对构建的理解是,它只编译上次构建中编辑过的Java文件,而干净构建将删除所有类文件并重新编译所有文件。那么,当单独构建就足以满足我提供最新版本的类文件的需要时,干净构建的效用是什么? 最佳答案 有时
是否有任何简单的(内置的、附加的、开源的或商业的)在 Postgresql(主从)上进行复制,以便在复制时清理从属内部的数据以符合 PCI 合规性? ETL工具怎么样?它不一定是瞬时的……最多一个小时
我有一个将数据保存到 MySQL 数据库的网站 在将 HTML 插入 MySQL 或在我的网站上显示它时,我应该转义 HTML 吗? 理想情况下,我想将原始 HTML 输入到我的数据库中,并在每次从中
我知道我已经asked一个关于 sanitizer 和转义的问题,但我有一个问题没有得到回答。 好了,到此为止。如果我有一个 PHP 脚本并且我 GET用户输入和SELECT它来自 mySQL 数据库
我是一名优秀的程序员,十分优秀!