Ios 阿拉莫菲尔与斯威夫特;无法强制转换类型为';斯威夫特。斯威夫特延期安排';(OX1075EBB0)至';Photomania.PhotoInfo';(0x107ee7b90)。”;
运行OS X El Cap开发测试版、iOS 9.0、Xcode 7.0 GM 我正在学习这个Ray Wenderlich教程(),我确实有一些问题。在我创建请求路由器之前,我的应用程序无法运行。它正确构建,然后一旦开始加载,我就会在标题中写出调试器短语。构建错误描述为“线程1:信号SIGABRT” 概述的路线是:Ios 阿拉莫菲尔与斯威夫特;无法强制转换类型为';斯威夫特。斯威夫特延期安排';(OX1075EBB0)至';Photomania.PhotoInfo';(0x107ee7b90)。”;,ios,xcode,swift,Ios,Xcode,Swift,运行OS X El Cap开发测试版、iOS 9.0、Xcode 7.0 GM 我正在学习这个Ray Wenderlich教程(),我确实有一些问题。在我创建请求路由器之前,我的应用程序无法运行。它正确构建,然后一旦开始加载,我就会在标题中写出调试器短语。构建错误描述为“线程1:信号SIGABRT” 概述的路线是: let imageURL = (photos.objectAtIndex(indexPath.row) as! PhotoInfo).url 这是我的PhotoBrowserCol
let imageURL = (photos.objectAtIndex(indexPath.row) as! PhotoInfo).url
这是我的PhotoBrowserCollectionViewController.swift文件的全部代码
//
// PhotoBrowserCollectionViewController.swift
// Photomania
//
// Created by Essan Parto on 2014-08-20.
// Copyright (c) 2014 Essan Parto. All rights reserved.
//
import UIKit
import Alamofire
class PhotoBrowserCollectionViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
var photos = NSMutableOrderedSet()
let refreshControl = UIRefreshControl()
let PhotoBrowserCellIdentifier = "PhotoBrowserCell"
let PhotoBrowserFooterViewIdentifier = "PhotoBrowserFooterView"
// MARK: Life-cycle
override func viewDidLoad() {
super.viewDidLoad()
setupView()
// Alamofire.request(.GET, "https://api.500px.com/v1/photos").responseJSON() {
// (_, _, data) in
// print(data.value)}
Alamofire.request(.GET, "https://api.500px.com/v1/photos", parameters: ["consumer_key": "consumer key"]).responseJSON() {
(_,_,JSON) in
print(JSON.value)
let photoInfos = (JSON.value!.valueForKey("photos") as! [NSDictionary]).filter({
($0["nsfw"] as! Bool) == false
}).map {
PhotoInfo(id: $0["id"] as! Int, url: $0["image_url"] as! String)
}
self.photos.addObject(photoInfos)
print(self.photos)
self.collectionView?.reloadData()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
// MARK: CollectionView
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return photos.count
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(PhotoBrowserCellIdentifier, forIndexPath: indexPath) as! PhotoBrowserCollectionViewCell
let imageURL = (photos.objectAtIndex(indexPath.row) as! PhotoInfo).url
Alamofire.request(.GET, imageURL).response() {
(_,_, data, _) in
let image = UIImage(data: data!)
cell.imageView.image = image
}
return cell
}
override func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
return collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: PhotoBrowserFooterViewIdentifier, forIndexPath: indexPath)
}
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
performSegueWithIdentifier("ShowPhoto", sender: (self.photos.objectAtIndex(indexPath.item) as! PhotoInfo).id)
}
// MARK: Helper
func setupView() {
navigationController?.setNavigationBarHidden(false, animated: true)
let layout = UICollectionViewFlowLayout()
let itemWidth = (view.bounds.size.width - 2) / 3
layout.itemSize = CGSize(width: itemWidth, height: itemWidth)
layout.minimumInteritemSpacing = 1.0
layout.minimumLineSpacing = 1.0
layout.footerReferenceSize = CGSize(width: collectionView!.bounds.size.width, height: 100.0)
collectionView!.collectionViewLayout = layout
navigationItem.title = "Featured"
collectionView!.registerClass(PhotoBrowserCollectionViewCell.classForCoder(), forCellWithReuseIdentifier: PhotoBrowserCellIdentifier)
collectionView!.registerClass(PhotoBrowserCollectionViewLoadingCell.classForCoder(), forSupplementaryViewOfKind: UICollectionElementKindSectionFooter, withReuseIdentifier: PhotoBrowserFooterViewIdentifier)
refreshControl.tintColor = UIColor.whiteColor()
refreshControl.addTarget(self, action: "handleRefresh", forControlEvents: .ValueChanged)
collectionView!.addSubview(refreshControl)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "ShowPhoto" {
(segue.destinationViewController as! PhotoViewerViewController).photoID = sender!.integerValue
(segue.destinationViewController as! PhotoViewerViewController).hidesBottomBarWhenPushed = true
}
}
func handleRefresh() {
}
}
class PhotoBrowserCollectionViewCell: UICollectionViewCell {
let imageView = UIImageView()
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = UIColor(white: 0.1, alpha: 1.0)
imageView.frame = bounds
addSubview(imageView)
}
}
class PhotoBrowserCollectionViewLoadingCell: UICollectionReusableView {
let spinner = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.WhiteLarge)
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(frame: CGRect) {
super.init(frame: frame)
spinner.startAnimating()
spinner.center = self.center
addSubview(spinner)
}
}
之所以会发生这种情况,是因为您使用
self.photos.addObject(photoInfos)
相反,你应该这样做
self.photos.addObjectsFromArray(photoInfos)
这会将
photoInfos
中的数组元素逐个添加到photoInfos
中,而不是将整个photoInfos
数组添加到照片的索引1中
我也在学习本教程,但遇到了一些问题。首先,由于到500px.com服务器的网络连接不稳定,我从JSON数据中得到零,因此照片计数为0,因此我在UI中看不到任何单元格;其次,我的Xcode版本是7.2和Swift 2.0,因此我发现我的环境中有一些变化。如果您完全按照教程进行操作,您将遇到一些编码异常
self.photos.addObject(photoInfos)
您应该使用函数addObjectForArray(数组\u名称)
而不是addObject()
我不知道你的Xcode和Swift版本对我来说是否相同。我觉得编码有很多变化。在函数“response”的结尾部分,我这样写:
let request = Alamofire.request(.GET, urlString, parameters: [CONSUMER_KEY : CONSUMER_KEY_VALUE])
request.responseJSON{ response in let json = response.result.value ... }
var data:NSData!
let request = Alamofire.request(.GET, (photoMuatbleOrderedSet.objectAtIndex(indexPath.row) as! Photo).image_url!)
request.responseData { (response) -> Void in
data = response.data!
let image = UIImage(data: data)
cell.imageView.image = image
}
return cell
由于这些变化,当应用程序运行时,我没有例外 你有没有调试过代码,它到底出了什么问题?在哪条线上?可能有些东西没有正确连接。。您正在使用的单元格,是否在情节提要中设置了类?正确连接插座?哦,请求一个新的使用者密钥,您的密钥现在是公开的。问题实际上不在调试器指示的行中的频率有多高?我只是拿了一个样本项目,所以所有的细胞,插座,课程和一切都应该是好的。仍然找不到问题所在:SIt可能是因为所有xcode测试版在swift中都发生了一些变化。我甚至不得不重新添加一个文本框来修复一个应用程序的崩溃,所以值得仔细看看“魔法”发生在哪里……嘿,我实际上已经完成了这个项目,所以我不再需要关于这个照片问题的帮助了!尽管如此,谢谢你过来。