草庐IT

var_value

全部标签

ios - SWIFT:var someVariable:int = textfield.text.toInt() x textfield2.text.toInt() 并强制展开

第一次发帖,请多多关照。我对编码相当陌生,正在努力了解SWIFT及其可选项目。非常感谢专业人士的一些建议!我正在编写一个简单的应用程序,用户在其中输入文本字段,然后在应用程序中进行一些乘法运算,然后按下按钮“calculateTM”将答案吐出到另一个文本字段中。我在计算本身时遇到了一些问题,也许是因为我试图在一行上做太多-获取文本字段条目,转换为整数,与另一个转换为整数的文本字段条目相乘,基本上是我写的在标题中:varsomeVariable:Int=textfield.text.toInt()*textfield2.text.toInt()问题是,Xcode希望我强制解包并添加一个!

ios - swift 错误 : Value of type 'NSObject -> () ' AnimalListTableViewController' has no member 'tableView'

我正试图在swiftxcode中消除这些错误如果截图太小,这里是代码importUIKitclassAnimalListTableViewController:UITableViewController{overridefunctableView(tableView:UITableView,numberOfRowsInSectionsection:Int)->Int{return4}letindexPath=self.tableView.indexPathForSelectedRow()//thisiswheretheerrorappears,itsaysValueoftype'NSO

swift 2 : Cannot convert value of type '[NSObject : AnyObject]' to expected argument type '[String : AnyObject]'

我有一个用Swift1构建的项目。但是在自动转换为Swift2后,它显示错误:无法将类型'[NSObject:AnyObject]'的值转换为预期的参数类型'[String:AnyObject]'。函数代码:funccreateViewContainers()->NSDictionary{varcontainersDict=NSMutableDictionary()letitemsCount:Int=tabBar.items!.countasInt-1forindexin0...itemsCount{varviewContainer=createViewContainer()conta

ios - swift 错误 : Could not cast value of type 'NSTaggedPointerString' (0x1a1264378) to 'NSNumber' (0x1a126f900)

我在Xcode(swift)中遇到这个错误:Couldnotcastvalueoftype'NSTaggedPointerString'(0x1a1264378)to'NSNumber'(0x1a126f900).我用//ERROR:("...")明确了错误在哪里代码:importUIKitimportiAdimportAVFoundationimportAudioToolboxletMAX:UInt32=4letMIN:UInt32=1classViewController:UIViewController,ADBannerViewDelegate{varchances=10varw

ios - 关于内存消耗 : Why choose static let over (computed) static var?

我的项目变大了,我的扩展也变大了,使用实用方法来访问某些类型。例如,我有一个UINib的扩展,如下所示:extensionUINib{staticletcollectionViewCellNib1:UINib=UINib(nibName:"collectionViewCellNib1",bundle:Bundle.main)staticletcollectionViewCellNib2:UINib=UINib(nibName:"collectionViewCellNib2",bundle:Bundle.main)staticletcollectionViewCellNib3:UINib

swift - 错误 : cannot convert value of type '() -> ()' to closure result type 'String' using Swift + PromiseKit

我不熟悉Swift中的promise,并使用PromiseKit尝试在Playground上创建一个非常简单的响应并尝试使用它。我有以下代码:importUIKitimportPromiseKitfuncfoo(_error:Bool)->Promise{returnPromise{fulfill,rejectinif(!error){fulfill("foo")}else{reject(Error(domain:"",code:1,userInfo:nil))}}}foo(true).then{response->Stringin{print(response)}}但是我得到以下错误

ios - 从不同 ViewController 中的函数捕获 var | swift

我正在制作一个占星应用程序,在主视图Controller中,您可以单击一系列按钮来拉出一个显示其占星的弹出屏幕。我有一个主要功能buttonLayout()为我的ViewController制作所有按钮并设置它们的图像。单击按钮后,我希望它弹出一个弹出窗口,其中包含他们在主视图Controller中单击的相同按钮我大写的部分是我不知道该怎么做。这是我的ViewController代码://ViewController.swift//Zodiacv2importUIKitclassViewController:UIViewController{@IBOutletweakvarheader

ios - alamofire post 方法中的 response.result.value 为 nil

letparametersDictionary=["email":"name@gmail.com","password":"password"]Alamofire.request("http://nanosoftech.com/store/user_check",method:.post,parameters:(parametersDictionaryasNSDictionary)as?Parameters,encoding:JSONEncoding.default,headers:nil).responseJSON{responseinprint("response:",respon

IOS FoodTracker 教程 : Value of tuple type '()' has no member 'path'

我正在完成IOSSwift教程“FoodTracker”,但是有一个错误我可以找到解决方案,但我不明白哪里出了问题以及如何解决它:错误:Valueoftupletype'()'hasnomember'path'此错误在以下代码中针对变量“Meal.ArchiveUrl.path”显示。我的代码,在MealtableViewController(相当于IOS教程):privatefuncsaveMeals(){letisSuccessfulSave=NSKeyedArchiver.archiveRootObject(meals,toFile:Meal.ArchiveUrl.path)if

iphone - 如何验证 IBOutlet/var 是否为 nil?

我使用Swift和Xcode6.1.1编写了一个简单的应用程序。该程序是一个简单的计算器,运行良好,但我无法验证三个文本字段的非零输入。因此,如果用户将该字段留空然后点击“计算”,应用程序就会崩溃。该应用接受三个输入,最初是字符串。我写了一个if语句来检查nil但它不起作用-无论如何它都会传递给else。这是与我的问题相关的代码块:...@IBOutletvarcalcButton:UIBarButtonItem!@IBOutletvaryearOneField:UITextField!@IBOutletvaryearTwoField:UITextField!@IBOutletvary