Questions tagged «swift»

Swift是Apple Inc.针对其平台和Linux开发的一种安全,快速且具有表现力的通用编程语言。Swift是开源的。仅将标记用于有关语言功能或在Swift中需要代码的问题。将标签[ios],[ipados],[macos],[watch-os],[tvos],[cocoa-touch]和[cocoa]用于有关平台或框架的(语言不可知)问题。

1
Xcode项目格式:3.1、3.2、6.3和8.0有什么区别?
当我在Xcode 9(或更早版本)中打开一个项目并检查File Inspector时,有一个名为Project Document的部分,带有一个名为Project Format的组合框。 可用的选项(在Xcode中9)有Xcode 3.1-compatible,Xcode 3.2-compatible,Xcode 6.3-compatible,和Xcode 8.0-compatible: 这些格式之间有什么区别? -更新历史(截至2019年5月20日)- 我最初在Xcode 6.4出现时问这个问题。 Xcode的6.4的名单包括Xcode 3.1-compatible,Xcode 3.2-compatible和Xcode 6.3-compatible,并默认为Xcode 3.2-compatible。 Xcode 7没有进行任何更改。 Xcode 8添加了一个Xcode 8.0-compatible项目。 Xcode 9将新项目的默认设置更改为Xcode 8.0-compatible。(2017年10月8日)添加了 Xcode 10.2Xcode 9.3-compatible,Xcode 10.0-compatible(2019年5月)

13
UIImageView捏缩放迅速
我希望有人可以帮助我。我试图允许用户捏UIImageView(允许最大和最小级别)上的缩放。但是由于某种原因,它无法正常工作。图像会稍微放大,然后反弹。谢谢。 这是变焦功能 func zoom(sender:UIPinchGestureRecognizer) { if sender.state == .Ended || sender.state == .Changed { let currentScale = self.view.frame.size.width / self.view.bounds.size.width var newScale = currentScale*sender.scale if newScale < 1 { newScale = 1 } if newScale > 9 { newScale = 9 } let transform = CGAffineTransformMakeScale(newScale, newScale) self.imageView?.transform = transform …

13
从WKWebView获取所有cookie
使用来获取cookieUIWebView似乎很简单NSHTTPCookieStorage.sharedHTTPCookieStorage(),似乎WKWebView将cookie存储在其他位置。 我做了一些研究,然后从NSHTTPURLResponse对象中获取了一些Cookie 。但是,其中不包含WKWebView: func webView(webView: WKWebView, decidePolicyForNavigationResponse navigationResponse: WKNavigationResponse, decisionHandler: (WKNavigationResponsePolicy) -> Void) { if let httpResponse = navigationResponse.response as? NSHTTPURLResponse { if let headers = httpResponse.allHeaderFields as? [String: String], url = httpResponse.URL { let cookies = NSHTTPCookie.cookiesWithResponseHeaderFields(headers, forURL: url) for cookie in cookies { logDebug(cookie.description) logDebug("found cookie " + …

6
Swift-检查时间戳记是昨天,今天,明天还是X天之前
我正在尝试确定如何确定给定的时间戳发生在今天还是+1 / -1天。本质上,我想做这样的事情(伪代码) IF days_from_today(timestamp) == -1 RETURN 'Yesterday' ELSE IF days_from_today(timestamp) == 0 RETURN 'Today' ELSE IF days_from_today(timestamp) == 1 RETURN 'Tomorrow' ELSE IF days_from_today(timestamp) < 1 RETURN days_from_today(timestamp) + ' days ago' ELSE RETURN 'In ' + days_from_today(timestamp) + ' ago' 但至关重要的是,它必须在Swift中,并且我在NSDate / NSCalendar对象方面苦苦挣扎。我首先计算出时差,如下所示: let calendar = NSCalendar.currentCalendar() …
70 ios  swift  nsdate  nscalendar 

3
Swift枚举继承
您可以在Swift中继承枚举吗?关于枚举继承,应注意哪些规则? 以下测试代码: enum TemperatureUnit: Int { case Kelvin, Celcius, Farenheit } enum TemperatureSubunit : Temperature { } 产生 error: type 'TemperatureSubunit' does not conform to protocol 'RawRepresentable'

15
UIView的“界面”构建器中的边框颜色不起作用?
我试图通过IB设置视图的图层属性。一切正常,除了边框的颜色(属性layer.borderColor): 我记得一年前遇到此问题,但最终还是以编程方式完成了此工作。而且,我可以通过编程方式执行此操作,但是我很好奇为什么该layer.borderColor属性永远无法通过界面生成器工作。我不想import QuartzCore,然后仅仅因为这个原因而编写额外的代码行,这似乎有点过头了。

13
如何快速为费率按钮添加链接?
首先,在提交我的应用程序之前,我不知道如何获取链接,并且该链接是针对每个国家/地区的应用商店还是通用的? 我也不知道是否只是通过将链接放在那里就可以做到这一点: @IBAction func rate(sender: AnyObject) { UIApplication.sharedApplication().openURL(NSURL(string : "webLinkHere")!) } 还是我应该使用另一种方式来做到这一点? 谢谢
69 ios  swift  app-store 

1
有无法识别的选择器-replacementObjectForKeyedArchiver:在Swift中实现NSCoding时崩溃
我创建了一个符合NSCoding的Swift类。(Xcode 6 GM,Swift 1.0) import Foundation private var nextNonce = 1000 class Command: NSCoding { let nonce: Int let string: String! init(string: String) { self.nonce = nextNonce++ self.string = string } required init(coder aDecoder: NSCoder) { nonce = aDecoder.decodeIntegerForKey("nonce") string = aDecoder.decodeObjectForKey("string") as String } func encodeWithCoder(aCoder: NSCoder) { aCoder.encodeInteger(nonce, …
69 ios  swift  xcode6  nscoding 

5
更新到Xcode 8后出现错误:“无此类模块”和“目标覆盖了`EMBEDDED_CONTENT_CONTAINS_SWIFT`构建设置”
No such module当我尝试构建项目时,我正在寻求Pods。如果我删除期望该Pod的代码,则另一个Pod出现另一个“无此模块”,这意味着每个Pod必须受到影响。键入时,pod install我收到以下消息: [!] The X target overrides the `EMBEDDED_CONTENT_CONTAINS_SWIFT` build setting defined in `X’. This can lead to problems with the CocoaPods installation - Use the `$(inherited)` flag, or - Remove the build settings from the target. [!] The `X` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in …
69 ios  swift  xcode  cocoapods  xcode8 



4
如何在Swift中比较两个字典?
是否有一种简便的方法可以[String: AnyObject]快速比较两个字典,因为它不接受==运算符? 通过比较两个字典,我的意思是检查它们是否具有相同的精确键,并且对于每个键都具有相同的值。

10
如何在Swift中设置UILabel的textColor
当我尝试使用代码将UILabel的颜色设置为另一个UILabel的颜色时 myLabel.textColor = otherLabel.textColor 它不会改变颜色。但是,当我使用此代码时, myLabel.textColor = UIColor.redColor() 它可以正确更改颜色。第一行有什么问题?

17
在Swift中获取应用名称
如何在Swift中获取应用程序名称? 谷歌搜索给了我这个: [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]; 我将其转换为Swift;错误-方法不存在: NSBundle.mainBundle().infoDictionary.objectForKey("CFBundleName")
69 cocoa  swift 

6
目标C到具有多个目标的Swift头文件
我已经通过import语句从Objective C(针对目标“ MyApp”)成功调用了我的Swift类: #import "MyApp-Swift.h" 我现在创建了一个名为“ MyAppLite”的新目标 编译新目标时,出现错误,因为代码需要“ MyApp-Swift.h”,但是编译器正在创建“ MyAppLite-Swift.h” 因此,我需要为#import要编译的目标创建条件Swift / ObjC标头。 怎么做,还是有更好的办法?

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.