面对问题"值类型'AppDelegate'没有成员'managedObjectContext'在新的Xcode 8中(使用Swift 3,iOS 10)尝试在View Controller中创建新的上下文时
let context = (UIApplication.shared().delegate as! AppDelegate).managedObjectContext
Run Code Online (Sandbox Code Playgroud)
在Xcode 8中,AppDelegate.swift文件中没有managedObjectContext的代码.AppDelegate.swift中的核心数据堆栈代码仅显示:lazy var persistentContainer:NSPersistentContainer属性和func saveContext().没有managedObjectContext属性.
如何在Xcode 8)中使用Swift 3创建managedObjectContext,或者可能没有必要使用Swift 3来创建它?
我目前正在学习如何使用CloudKit Framework以及缺少显示如何同步Core Data和CloudKit的文档或示例.
我观看了所有WWDC视频(2014年,2015年,2016年)专门介绍CloudKit,但没有人告诉我们如何实现与Core Data的同步.我找不到任何新的示例,教程或书籍,展示了如何实现此同步.
我知道使用CloudKit的Operations API(不是Convenience API)和订阅更新是有效的,就像在新的WWDC 2016视频中所说的那样,专用于CloudKit,但使用CoreData进行映射是一个真正的问题.
例如,假设我想创建一个类似于Notes应用程序的应用程序.离线时,用户可以创建他的笔记并与他们一起工作,将他们保存到他的核心数据库中.当设备上线时,应用程序会检查服务器上的更改并将新创建的记录保存到服务器(CloudKit).
当应用程序启动时,它还会从CloudKit获取更改,如果有更改,它会使用新更改更新本地缓存(核心数据).
我希望有一个共同的同步模式.在哪里与Core Data方法同步以及它们应该如何?
非常感谢有关此的任何信息或帮助.
我正在使用Swift 3,Xcode 8,iOS 10.
嗨,这是我的问题:
在我的AppDeleagate的 didFinishLaunchingWithOptions:方法我有一个方法[self configureUINavigationControllerStlyle]; 它配置状态栏和我的应用程序的所有导航栏外观(我的UINavigationController和UITabbarController在我的应用程序中一起工作).
-(void) configureUINavigationControllerStlyle {
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController = (UINavigationController *)[tabBarController.viewControllers objectAtIndex:0];
navigationController.navigationBar.translucent = NO;
[[UINavigationBar appearance] setBarTintColor: [CustomColor getAwesomeColor:@"colorBlue3_1"]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes:@{
NSForegroundColorAttributeName : [UIColor whiteColor],
NSFontAttributeName: [UIFont fontWithName:@"AvenirNext-DemiBold" size:17.0]
}];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
Run Code Online (Sandbox Code Playgroud)
另外在我的info.plist中我设置:查看基于控制器的状态栏外观为"NO"
一切都很好,我的应用程序中的所有控制器都有蓝色背景和白色文本颜色的状态栏.但不是uisearchcontroller和uisearchresultscontroller.
我的根TableViewController看起来像这样:
https://www.dropbox.com/s/oqcozos89x9yqhg/Screen%20Shot%202014-12-11%20at%2016.21.06.jpg?dl=0
我在我的应用程序中集成了searchController和searchResultsController.逻辑运行良好,但我不明白如何处理searchController和searchResultController中的状态栏外观.他们不使用我在AppDelegate.m文件中创建的状态栏的样式.
我的searchController和searchResultsController看起来像这样(状态栏变为白色,状态栏的文本颜色也变为白色,但我需要我的状态栏与我的主视图控制器中的颜色相同(蓝色背景和白色文本颜色).
https://www.dropbox.com/s/26skdz7gvehmwl4/Screen%20Shot%202014-12-11%20at%2016.21.16.png?dl=0
另一个错误:当我使用时
navigationController.navigationBar.translucent = NO;
Run Code Online (Sandbox Code Playgroud)
在我的AppDelegate中 - 在使用搜索控制器后从详细视图控制器返回时,它会导致我的家庭桌面视图"跳跃或拉伸".当我没有设置半透明属性时 - 没有"跳跃".
也许有人知道如何在iOS 8中使用searchController时修复状态栏颜色问题.
如果我使用默认颜色(不要对我的AppDelegate添加任何更改),一切正常,但我需要在我的应用程序中自定义状态栏颜色.
uistatusbar uisearchresultscontroller appdelegate ios8 uisearchcontroller
我有一个付费的iOS应用程序.
我需要original_application_version从Apple AppStore Receipt 获取该号码(用户购买的第一个版本).
要获得收据,当我的应用加载时,我使用checkReceiptFromAppStore()功能:
func checkReceiptFromAppStore() {
let receipt = self.getReceipt()
print("receipt Data is: \(receipt)") // prints this: receipt Data is: Optional(5141 bytes)
}
Run Code Online (Sandbox Code Playgroud)
getReceipt() 功能如下:
func getReceipt() -> Data? {
if Bundle.main.appStoreReceiptURL != nil {
print("app receipt: \(Bundle.main.appStoreReceiptURL)")
do {
let receiptData = try Data(contentsOf: Bundle.main.appStoreReceiptURL!)
return receiptData
} catch {
print("error converting receipt to Data: \(error.localizedDescription)")
}
}
return nil
}
Run Code Online (Sandbox Code Playgroud)
我已经观看了WWDC 2017 Advanced StoreKit关于In App购买和收据验证的视频以及关于使用收据的WWDC 2013视频 …
我的应用程序中有2个视图控制器.
第一个"MainViewController"显示一个tableView,其中包含从私有CloudKit数据库获取的CKRecords字段.在此VC的viewWillAppear方法中,我从CloudKit获取记录并重新加载tableview的数据,以显示先前由用户保存在CloudKit中的最新获取结果.
第二个视图控制器"CreateRecordViewController"用于创建CKRecords并将它们保存到CloudKit的私有数据库.
所以我在CreateRecordViewController中创建记录并在MainViewController中显示它们.
问题如下:当我在CreateRecordViewController创建记录时,它在CloudKit服务器上保存,但在关闭此CreateRecordViewController并转到MainViewController之后,tableview并不总是及时更新.
这是我的CreateRecordViewController中保存记录的代码:
CloudKitManager.sharedInstance.privateDatabase.save(myRecord) { (savedRecord, error) -> Void in
if error == nil {
print("successfully saved record code: \(savedRecord)")
}
else {
// Insert error handling
print("error Saving Data to iCloud: \(error.debugDescription)")
}
}
Run Code Online (Sandbox Code Playgroud)
记录保存后,关闭CreateRecordViewController并查看MainViewController.
正如我之前在MainViewController的viewWillAppear中所述,我检查iCloud是否可用,如果它可用,我从CloudKit获取所有记录并在tableView中显示它们.
override func viewWillAppear(_ animated: Bool) {
CKContainer.default().accountStatus { (accountStatus, error) in
switch accountStatus {
case .noAccount: print("CloudKitManager: no iCloud Alert")
case .available:
print("CloudKitManager: checkAccountStatus : iCloud Available")
self.loadRecordsFromiCloud()
case .restricted:
print("CloudKitManager: checkAccountStatus : iCloud restricted")
case .couldNotDetermine:
print("CloudKitManager: checkAccountStatus : …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我有一个ItemsListView
它显示从核心数据获取的项目列表。
我无法在列表上执行 .onDelete。出现Value of type 'some View' has no member 'onDelete'错误。第二个错误 - 就Protocol type 'Any' cannot conform to 'View' because only concrete types can conform to protocols在列表中。
struct ItemsListView: View {
@Environment(\.managedObjectContext) var managedObjectContext
var fetchRequest: FetchRequest<Item>
var items: FetchedResults<Item>{fetchRequest.wrappedValue}
init() {
fetchRequest = FetchRequest<Item>(entity: Item.entity(), sortDescriptors: [])
}
var body: some View {
List { //error 2 appears here
ForEach(items) { (item : Item) in
Text("\(item.name ?? "Nothing")")
}.onDelete(perform: delete) // getting error …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我有以下情况。
我已经实现了一个自定义标注气泡,其中包含自定义的详细信息CalloutAccessoryView,其中有两个标签。
我知道如何用这一行更改detailCalloutAccessoryView的颜色。
view.detailCalloutAccessoryView?.backgroundColor = UIColor.red
Run Code Online (Sandbox Code Playgroud)
但我不知道如何更改主气泡的背景颜色(现在是透明的灰色/白色)。使用 view.detailCalloutAccessoryView?.backgroundColor = UIColor.red 线条我的标注气泡如下所示:
但我希望我的自定义气泡看起来像这样:
这是我的 viewFor 注释方法:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
let identifier = "pin"
var view : MKAnnotationView
if let dequedView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier) {
dequedView.annotation = annotation
view = dequedView
} else {
view = MKAnnotationView(annotation: annotation, reuseIdentifier: identifier)
view.canShowCallout = true
}
let pinImage = UIImage.init(named: "customPin")
DispatchQueue.main.async(execute: {
view.detailCalloutAccessoryView?.backgroundColor = UIColor.red
})
view.image = …Run Code Online (Sandbox Code Playgroud) 我曾经为 iOS 开发,但我不明白为什么我不能NSView在主视图中轻松更改s 的背景颜色。
假设我有一个带有主视图的视图控制器。在此视图中,我添加了 3 个自定义视图,并设置了它们的约束以适合主视图。
我为我的视图控制器创建了 3 个插座:
@IBOutlet weak var topView: NSView!
@IBOutlet weak var leftView: NSView!
@IBOutlet weak var rightView: NSView!
Run Code Online (Sandbox Code Playgroud)
在那之后,我试图设置这些视图的背景,但不能这样做。当我运行应用程序时,我没有看到任何颜色变化。
这是我添加的用于显示自定义视图颜色的代码:
override func viewDidLoad() {
super.viewDidLoad()
self.view.wantsLayer = true
self.topView.layer?.backgroundColor = NSColor.blue.cgColor
self.rightView.layer?.backgroundColor = NSColor.green.cgColor
self.leftView.layer?.backgroundColor = NSColor.yellow.cgColor
}
Run Code Online (Sandbox Code Playgroud)
它什么也没显示(我的视图上没有背景颜色):
我不明白为什么这段代码不起作用。为什么设置 an 的颜色如此困难NSView(而在 iOS 开发中却如此简单)?我正在使用 Xcode 8 并使用 Swift 3 编写代码。
假设我们有一个有效的 NSPersistentCloudKitContainer 和一个名为 Item 的 CoreData 实体。假设我们想要在 iOS、iPad 和 Mac 应用程序之间同步。
我观看了有关同步 CoreData 和 CloudKit 的 WWDC 会议,并在我的 SwiftUI 应用程序中实现了基本同步。它可以工作,数据会发送到所有 3 台设备并自动同步。
但是在 Mac 上,如果不重新加载视图(以及在模拟器中(因为它们没有收到推送通知),数据就不会出现。它来了,但没有自动刷新。我还测试了模拟器到真实设备,有时它会自动同步,有时我需要重新打开应用程序才能看到更改。
我很好奇是否有一种可以与 NSPersistentCloudKitContainer 一起使用的强制获取方法。或者也许有人知道在使用 NSPersistentCloudKitContainer 和 SwiftUI 时手动重新获取数据的解决方法?
我还想在新数据开始出现时显示一个活动指示器,但不确定在代码中从哪里开始获取获取点?
我使用了 Apple 提供的这个 UIKit示例代码,并将其调整为在 SwiftUI 中工作。我还阅读了此处的所有文档。
这是我使用的persistentContainer代码:
lazy var persistentContainer: NSPersistentCloudKitContainer = {
let container = NSPersistentCloudKitContainer(name: "AppName")
container.persistentStoreDescriptions.first?.setOption(true as NSNumber, forKey: NSPersistentStoreRemoteChangeNotificationPostOptionKey)
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
fatalError("Unresolved error \(error), \(error.userInfo)")
} …Run Code Online (Sandbox Code Playgroud) core-data ios cloudkit swiftui nspersistentcloudkitcontainer
I'm facing the following problem with SwiftUI Text: In the following example SwiftUI breaks the word "Amazement" into "amazeme" on the first line and "nt" on the second. How to avoid it, isn't it a bug?
I want the word "amazement" to be written on one line. Is there any modifier that can allow this (don't divide words or something)?
Tried .allowsTightening, .fixedSize. Changed the order of modifiers, Didn't help.
Is it a bug or we currently don't have an …
swift ×6
ios ×4
swift3 ×4
cloudkit ×3
core-data ×3
swiftui ×3
ios10 ×2
appdelegate ×1
ckoperation ×1
ckrecord ×1
cocoa ×1
ios11 ×1
ios14 ×1
ios8 ×1
list ×1
macos ×1
mkannotation ×1
mkmapview ×1
nspersistentcloudkitcontainer ×1
nsview ×1
storekit ×1
swiftui-list ×1
swiftui-text ×1
text ×1
uistatusbar ×1
xcode ×1