草庐IT

swift_FORCE_LOAD

全部标签

swift - 如何使用 swift 4 调用 google map api?

我的问题是,我只需要使用googleAPI的餐厅、酒吧。如果您需要代码,我会发给您。这是我的基本url:-"https://maps.googleapis.com/maps/api/place/"nearbyURLFragment:-letnearbyURLFragment="nearbysearch/json?key=%@&location=%f,%f&rankby=distance&type=restaurant,bar"单一类型的正确工作。但是我没有得到正确的结果。 最佳答案 引用GoogleAPI文档,Restrictsth

objective-c - Xcode 10.2 Swift 错误 : Function types cannot be represented in Objective-C unless their parameters and returns can be

我今天将Xcode更新到10.2,但出现以下错误:Methodcannotbemarked@objcbecausethetypeoftheparameter2cannotberepresentedinObjective-CFunctiontypescannotberepresentedinObjective-CunlesstheirparametersandreturnscanbeIdon'tunderstandwhy在10.1中完全没问题。这是我多年来一直使用的示例,没有任何问题。我怎样才能使这段代码无错误地编译?@objcpublicfuncmyFunction(inputStri

ios - Firebase 不会在 Swift/iOS 中显示 microsoft.com 的登录页面

我正在通过使用OAuthProvider类使用个人Microsoft帐户登录来实现Firebase身份验证。我已按照以下说明操作:https://firebase.google.com/docs/auth/ios/microsoft-oauth?authuser=0但是,当我使用FirebaseSDK的OAuthProvider时,它没有显示Microsoft的登录页面,实际上getCredentialWith没有调用任何东西。当我使用GoogleAuthProvider时,一切正常,FirebaseSDK显示了Google的登录页面。letprovider=OAuthProvider

swift - 将图像添加到 UICollection header Swift

我希望在CollectionView的header中实现图像。这是我到目前为止的代码,但在我测试时没有出现标题。我错过了什么吗?funccollectionView(_collectionView:UICollectionView,viewForHeaderInSectionsection:Int)->UIView?{letview=UIView()letimage=UIImageView()image.frame=CGRect(x:collectionView.frame.width-10,y:0,width:20,height:20)image.image=UIImage.init

swift - 如何为具有类型约束的泛型函数提供默认参数?

以下函数定义是合法的Swift:funcdoSomething(value:T="abc"){//...}编译器能够确定默认参数"abc"是一个String,并且String符合StringProtocol.但是这段代码无法编译:funcdoSomething(value:T="abc")whereT.Element==Character{//...}编译错误:Defaultargumentvalueoftype'String'cannotbeconvertedtotype'T'似乎编译器拥有与第一种情况一样多的信息来确定String确实可以转换为T。此外,如果我删除默认参数并使用相同

ios - 从 Objective-C 调用 Swift 扩展函数的语法

我有一个同时使用objective-c和swift的项目。一切都正确连接,所以我通常可以毫无问题地调用类的扩展。然而,在这种情况下,我必须将一个参数传递给扩展并且我被语法挂断了。这是Swift3扩展extensionDouble{///Roundsthedoubletodecimalplacesvaluefuncrounded(toPlacesplaces:Int)->Double{letdivisor=pow(10.0,Double(places))return(self*divisor).rounded()/divisor}}在Swift中你可以调用它letx=Double(0.1

arrays - Swift - 循环遍历 Array of Array [[Int]] 的智能方法

我使用ArrayofArray[[Int]]存储map中的坐标。例如,我想用“1”替换所有“2”。为此,我创建了2个for循环,用于定义数组空间并检查内容。这不是很灵活,只适用于定义大小的数组。privatefuncremove2fromArray(currentArray:[[Int]])->[[Int]]{varnewArray:[[Int]]=currentArrayforsectionin0...14{forrowin0...19{ifnewArray[section][row]==2{newArray[section][row]=1}}}returnnewArray}有没有办

ios - Swift 如何在变量闭包中干燥代码?

我正在使用自动布局(以编程方式)设置我的ViewController,我已经得到了我想要的一切,但现在我想让我的代码更有效率,我注意到我有很多重复代码,我是试图弄清楚如何在变量闭包中获取重复代码并将其放在其他地方,以便代码更清晰。如何清理我的代码?对变量闭包还是陌生的。我复制粘贴的代码是一个全局变量。letdescriptionTextViewOne:UITextView={lettextView=UITextView()lettext="Tapanywheretostart\nyourdayright!"letshadow=NSShadow()shadow.shadowColor=U

swift - 在 Swift 中编写多个嵌套的 for...in 循环

请问有没有更简洁或更好的方法来在Swift中编写下面的嵌套for...in循环?还是使用for...in甚至以正确的方式填充我的卡片?forcardNumberin1...3{forcardSymbolIdentifierin1...3{forcardColorIdentifierin1...3{forcardShadingIdentifierin1...3{letcard=Card(cardNumber:cardNumber,cardSymbolIdentifier:cardSymbolIdentifier,cardColorIdentifier:cardColorIdentifie

swift - 有没有办法从 subview 中获取父对象?

我正在为swift开发一个填字游戏应用程序,但我无法从UIButton中的subview获取UIButton是一个文本域。文本字段占用了UIButton标题应占的空间,但是当单击textfield时它没有单击UIButton。目前,UIButton本身突出显示了某些列和行的所有UIButtons。我已经尝试了一些方法,例如雕刻subview的父类(superclass)varmyButton:CustomButton=textfield.superclassas?CustomButton我也试过用varmyObject:CustomButton?{returnview.compactM