Tag: swift3

使用Swift 3在Xcode 8中寻找修订后的NSPersistentContainer的清晰教程

我回顾了苹果的: Xcode 8发行说明: https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/Introduction.html 从Swift 2.2迁移到Swift 2.3或Swift 3 https://swift.org/migration-guide/ CoreOS 10.12,iOS 10.0,tvOS 10.0和watchOS 3.0中的核心数据的新增function https://developer.apple.com/library/content/releasenotes/General/WhatNewCoreData2016/ReleaseNotes.html#//apple_ref/doc/uid/TP40017342-CH1-DontLinkElementID_1 还有很多其他的…但是苹果应该提供的一个文档,核心数据编程指南,还没有从Swift 2中更新。 https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreData/FetchingObjects.html#//apple_ref/doc/uid/TP40001075-CH6-SW1 理想情况下,我正在寻找这样的事情,但Swift 3。 https://www.raywenderlich.com/115695/getting-started-with-core-data-tutorial 任何线索将非常感激。 每汤姆的评论(下)我错过了什么步骤? 1)创build一个新的项目“testing” 2)select使用CoreDate(这将创buildTest.xcdatamodeld) 这将自动填充AppDelegate与以下(删除默认注释): func applicationWillTerminate(_ application: UIApplication) { self.saveContext() } lazy var persistentContainer: NSPersistentContainer = { let container = NSPersistentContainer(name: "Test") container.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as […]

迅速3准备(for segue)function坏了?

出于某种奇怪的原因,用swift 3, prepare(for segue:方法拒绝承认segue标识符,我把下面的IBAction连接到了UI上的一对button: @IBAction func goToImagesPicker(_ sender: AnyObject) { performSegue(withIdentifier: "showImagePicker", sender: sender) } @IBAction func goToNamePicker(_ sender: AnyObject) { performSegue(withIdentifier: "showNamePicker", sender: sender) } 然而,在我的prepare(for segue:方法,它不能识别不同的segue标识符,我知道,因为我的控制台不logging我分配给每个消息: func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) { if segue.identifier == "showImagePicker" { print("This is the Image Picker") } if segue.identifier == "showNamePicker" { print("This is the Name […]

在Swift 3中replace数组的indexOf(_ :)方法

在我的项目(用Swift 3编写)中,我想使用indexOf(_:)方法(存在于Swift 2.2中)从数组中检索一个元素的索引,但是我找不到任何replace。 Swift 3中的这个方法有什么好的替代方法吗? 更新 我忘了提及,我想在自定义对象中search。 在代码完成时,我没有任何提示input“indexof”。 但是当我试图得到类似Int代码完成工作的构build索引,我可以使用index(of:)方法。

使用未parsing的标识符

我的应用程序工作正常,现在突然Xcode给我这个错误: 使用未parsing的标识符cardWasRemoved func addNewCards() { countOfCards = countOfCards-1 if(countOfCards >= 0){ self.arrayAuthorization.remove(at: dm.objectIndexToRemove) cardWasRemoved(removeIndex: dm.objectIndexToRemove) } } 而我的方法实现是这样的: open func cardWasRemoved(removeIndex:Int) { if layout.newCardShouldAppearOnTheBottom { layout.cardDidRemoved(removeIndex) } else { layout.cardDidRemoved(removeIndex) } }

input'Any?' 没有下标成员(使用Firebase)

每次我运行这行代码都行不通,任何能帮助我的人都可以改变它呢? 谢谢你的帮助。 🙂 以下是我不断收到的错误 inputAny? 没有下标成员 var ref:FIRDatabaseReference? var refHandle: UInt! var postData = [String]() override func viewDidLoad() { super.viewDidLoad() ref = FIRDatabase.database().reference() refHandle = ref?.observe(FIRDataEventType.value, with: { (snapshot) in let dataDict = snapshot.value as! [String: AnyObject] print(dataDict) }) let username: String = (FIRAuth.auth()?.currentUser?.uid)! ref?.child("Users").child(username).observeSingleEvent(of: .value, with: { (snapshot) in let username = snapshot.value!["Username"] as! […]

为什么viewDidLoad在swift中完成时数据不显示?

当我的应用程序完成启动时,应该有数据显示在UITableViewCell上。 然而,这里没有任何东西,所以在重新启动应用之后,通过按回家button并向上滑动视图,select我的演示应用,所有的数据显示正常,似乎没有任何错误。 是什么导致了最初的问题? 你有什么想法,为什么?

尝试在iOS模拟器中使用相机后,应用程序冻结,即使执行捕获处理

我正在尝试在swift 3中将相机function添加到我的应用程序中。由于iOS模拟器没有相机,因此我写了一个do catch以允许应用程序在模拟器中使用相机失败后继续运行。 do{ let captureDeviceInput = try AVCaptureDeviceInput(device: captureDevice) captureSession.addInput(captureDeviceInput) }catch{ print("there was an error adding camera as input: ") print(error.localizedDescription) } 返回的错误是“不能logging”。 但是,这完全冻结了应用程序。 我错过了我的error handling的东西,或者这是使用模拟器不可避免的副作用?

Alamofire无法访问JSON响应的键

我新使用Alamofire并遇到问题。 我可以运行下面的代码来打印出API端点的所有数据。 Alamofire.request("http://codewithchris.com/code/afsample.json").responseJSON { response in if let JSON = response.result.value { print(JSON) } } 问题是,当我运行这个: Alamofire.request("http://codewithchris.com/code/afsample.json").responseJSON { response in if let JSON = response.result.value { print(JSON["firstkey"]) } } 我得到的错误: types“任何”没有下标成员 我不知道为什么这个错误发生,似乎我正确访问数据。 任何帮助将是伟大的,谢谢! 我已经尝试使用两种格式: 打印(JSON [“firstkey”]作为string) 和 打印(JSON [“firstkey”]为[String:Any] 但他们仍然给出同样的错误。 这是我的端点上的JSON: { "firstkey":"it worked!", "secondkey":["item1", "item2", "item3"] }

如何添加2个textfields intget(swift3)

我试图将2个文本字段转换为整数,然后将它们添加到一起。 我也想打印日志中的总和。 let jake = t3.text! + t4.text!

在iMessage应用程序中检查风景/纵向(扩展名)

已经看到很多解决scheme来检查方向,但奇怪的是,没有任何工作! 以下是代码片段, override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { let screenSize = UIScreen.main.bounds let screenWidth = screenSize.width let screenHeight = screenSize.height print("Screen Width = \(screenWidth)") print("Screen Height = \(screenHeight)") if (screenWidth > screenHeight) { print("Landscape") alertView.removeFromSuperview() messageView.addGestureRecognizer(tapTextView) } else { print("Portrait") setupLandscapeAlertView() } } 另一种用来设置视图的方法是, fileprivate func setupLandscapeAlertView() { messageView.removeGestureRecognizer(tapTextView) alertView = UIView(frame: […]