草庐IT

clipboard_string

全部标签

objective-c - Dictionary<String, Any> 与 [String : Any]

这个问题在这里已经有了答案:ManywaysofdefiningaSwiftdictionary(2个答案)关闭5年前。目前,在Swift3中,有两种写字典类型的方式。这些是Dictionary和[String:Any].我知道前者与Objective-C键/值编码兼容,而后者不兼容,但除此之外,它们之间是否存在任何重大差异或我应该注意的任何性能影响?我目前倾向于使用前者,因为它与Obj-C键/值兼容,但如果这是一个滑坡,请警告我。我想Array也是如此和[String]也是吗?

swift - 奇怪的 String.unicodeScalars 和 CharacterSet 行为

我正在尝试使用Swift3CharacterSet从String中过滤出字符,但我很早就陷入困境。CharacterSet有一个名为contains的方法funccontains(_member:UnicodeScalar)->BoolTestformembershipofaparticularUnicodeScalarintheCharacterSet.但是测试它不会产生预期的行为。letcharacterSet=CharacterSet.capitalizedLettersletcapitalAString="A"ifletcapitalA=capitalAString.unico

ios - 收到错误 : Type 'String' has no member 'foregroundColor' in Swift 4

我是Swift的新手。我在Swift4中创建了一个应用程序,但是当我将SWIFT_VERSION更改为Swift3.0时,我的代码出现错误。Type'String'hasnomember'foregroundColor'.如何将其转换为当前的Swift语法?代码:ifletp=placeholder{letplace=NSAttributedString(string:p,attributes://error-->[.foregroundColor:#colorLiteral(red:1.0,green:1.0,blue:1.0,alpha:1.0)])attributedPlaceh

swift - 字符串之间有什么不同(描述: Int) vs String(Int)?

我需要将Integer值转换为String。我用Integer值创建了一个变量,然后我使用print打印了它。以下方法有何不同?varword="Countis"varcount=100print(word+String(describing:count));//Countis100print(word+String(count));//Countis100 最佳答案 你的问题实际上是不必要的,因为如果所有你想在这里做的是打印,你可以直接这样做:print("Countis",count)//Countis100那是因为print采

string - 将字符串转换为 int8 数组

我有一个包含C字符串的C结构(旧库,等等等等),现在我需要将CFString和Swift字符串转换成这个C字符串。有点像structProduct{charname[50];charcode[20];}所以我试图将其分配为productName.getCString(&myVarOfStructProduct.name,maxLength:50,encoding:NSUTF8StringEncoding)但是编译器给我以下错误:无法将类型(int8,int8,int8....)转换为[CChar]。 最佳答案 可能的解决方案:wit

swift - 如何在 Swift 中将 String 类型变量转换为 CFString?

我从iOS教程中学到了这个,但它不起作用funcimagePickerController(picker:UIImagePickerController!,didFinishPickingMediaWithInfoinfo:NSDictionary!){varmediaType=info.objectForKey(UIImagePickerControllerMediaType)asStringvaroriginalImage,editedImage,imageToUse:UIImage//Handleastillimagepickedfromaphotoalbumif(CFStrin

ios - "String?' 不可转换为 'NSString'”(Xcode 7 迁移后)

你好,我正在开发项目(在objective-c中完成),但有一个类是用Swift编写的。迁移到XCODE7forios9编译器后返回给我错误:'String?'不可转换为“NSString”对于代码:ifletview=self.emailTextField.rightView{if(self.emailTextField.textasNSString).validateEmail(){self.emailTextField.rightView?.alpha=1}else{self.emailTextField.rightView?.alpha=0}}Swift2大佬们有什么建议:)?

ios - 错误 : Value of type string has no member componentsSeparatedByCharactersInSet

以下代码抛出以下错误:“字符串类型的值没有成员componentsSeparatedByCharactersInSet”此代码来自之前在swift版本1或2中运行但不再运行的另一个项目。importFoundationextensionString{funcsplit()->[String]{returnself.componentsSeparatedByCharactersInSet(CharacterSet.whitespaceAndNewlineCharacterSet()).filter({$0!=""});}}extensionArray{funcunique()->[T]{

ios - Swift iOS : Parsing of date from a string does not work for some devices. 太奇怪了

这个问题在这里已经有了答案:DateFormatterdoesn'treturndatefor"HH:mm:ss"(1个回答)关闭5年前。调试器显示日期字符串为“2017-08-0100:00:00”,我也传递了正确的格式。但是1台设备的dateFormatter.date部分总是失败(返回nil)。但有些适用于模拟器和其他iphone设备。我正在使用swift3

swift - 为什么隐式解包的可选不在 [String : Any] 类型的字典中解包

如果我在我的类中声明了一个隐式解包的可选值,然后我在[String:Any]类型的Dictionary中引用它,它不会被解包。为什么是这样?为什么不是可选的Any不强制它解包?varaString:String!="hello"varparams:[String:Any]=["myString":aString]print(params)//Thisprints["myString":Swift.ImplicitlyUnwrappedOptional.some("hello")]请注意,如果我将字典指定为[String:String]类型,它将被解包,但是当我在Dictionary.