Tag: swift2

Alamofire无法正常工作(Swift / Xcode 8)

我试图导入Alamofire到我的项目时(Cocoapods不为我工作,所以我必须手动导入它)时出现以下错误。 无论如何,我正在使用XCode 8和Swift 2.3,我得到这些错误: 更新:我清理XCode,下载最新版本的Alamofire,并重新启动我的电脑。 现在,XCode似乎给了我相互矛盾的错误(图片供参考) 谢谢!

在Swift中检测可用的API iOS与watchOS

区分watchOS和iOS时, #available似乎不起作用。 以下是iOS和watchOS共享的代码示例: lazy var session: WCSession = { let session = WCSession.defaultSession() session.delegate = self return session }() … if #available(iOS 9.0, *) { guard session.paired else { throw WatchBridgeError.NotPaired } // paired is not available guard session.watchAppInstalled else { throw WatchBridgeError.NoWatchApp } // watchAppInstalled is not available } guard session.reachable else { throw […]

iOS9 self.canDisplayBannerAds = true不显示任何广告

非常简单的iAd代码: import UIKit import iAd class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() self.canDisplayBannerAds = true } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } } iAd.framework被加载。 它曾经工作。 iOS9之后,不工作。 iAd的模拟器设置设置为100%,刷新率为15秒。 不显示任何广告。 试用iPhone 6,5S,4S和iPad Air2。 不显示任何广告。 我在这里错过了什么? 关于失去我的想法…所有我的应用程序,用于显示iAds没有问题,现在没有显示任何iAds。

如何在iOS Swift中获取来电的电话号码?

我想在我的应用程序中获取来电者的电话号码。 请有人提供我迅速解决这个问题。

为什么Swift 2.0会输出数组中最后一个元素而不是所有元素?

我试图打印出此数组中的所有元素,当我显示它时,它只打印出Pickup洗衣店。 var todo = ["Return Calls", "Write blog", "Cook Dinner", "Pickup laundry"] for element in todo { print(element) } 我不知道为什么这是错的…

如何在X秒后更改NSTimer的NSTimeInterval?

我正在快速制作一个有两个定时器的应用程序。 10秒后,我想另一个计时器去更快。 我试过这样做,但它没有工作(我试图改变无功time为1): @IBOutlet var displayTimeLabel: UILabel! var startTimer = NSTimeInterval() var timer = NSTimer() var timer2:NSTimer = NSTimer() var time = 2.0 @IBAction func Start(sender: UIButton) { if !timer2.valid { timer2 = NSTimer.scheduledTimerWithTimeInterval(0.01, target: self, selector: "updateTime", userInfo: nil, repeats: true) startTimer = NSDate.timeIntervalSinceReferenceDate() } timer = NSTimer.scheduledTimerWithTimeInterval(time, target: self, selector: "timer:", userInfo: nil, […]

为什么斯威夫特2有利于强迫打开可选项?

我不再看到Xcode抱怨某些事情需要选项(“?”)。 现在它总是被迫解开(砰!!“)。 当我们现在强制解包时,是否有任何理由再使用可选项?

UICollectionView cellForItem调用不正确

将Swift 2.2迁移到Swift 3后的Xcode 8.2.1 UICollectionView的cellForItem没有正确调用,但在迁移之前工作正常 我有水平的UICollectionViewFlowLayout CollectionView和设置分页设置为true UIViewController的视图框架与UICollectionView框架一样,也是页面应用程序的单元框架(全尺寸) 我滚动UICollectionView向右滚动cellForItem(UICollectionViewDataSource函数)indexPath.row indexPath.row打印如下 0, 3, 4, 5, 6, 7, 8, 9, 10 然后在上次打印时滚动到相反的方向10 下一个indexPath是7但应该是9因为最后一个被调用的索引是10 并滚动,直到第一个单元格显示 6, 5, 4, 3, 2, 1, 0印 为什么这种情况发生? 在Swift 2.2迁移之前,工作正常 在Swift 3或者iOS 10之后,UICollectionView或者UICollectionViewFlowLayout有没有改变?

检查文本字段是否为空导致Swift 2中的错误

我正在尝试检查一个文本框是否没有价值。 当我这样做: if(userEmail?.isEmpty || userPassword?.isEmpty || userPasswordRepeat?.isEmpty) 我得到以下错误 我尝试添加“?” 之前的“.isEmpty”,但错误不会消失 有任何想法吗?

可拖动的标签 – ios

只有当用户触摸并拖动标签时,我才需要移动标签。 我无法找出用户是否触摸过该标签。 我使用了touchesMoved方法(Swift 2)。 以下是我的代码 override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) { super.touchesBegan(touches as Set<UITouch>, withEvent: event) let touch = touches.first if (touch!.view) == (moveLabel as UIView) // moveButton is my label { location = touch!.locationInView(self.view) moveLabel.center = location } } 当我这样做,我的标签不动:( :(请人帮助我