草庐IT

hardcoded_Value

全部标签

ios - 无法分配类型为 '(String!, Bool, [AnyObject]!, NSError!)->Void to a value of type UIActivityViewControllerCompletionWithItemsHandler?' 的值

我的项目中有以下几行代码...@IBActionfuncshareMeme(sender:UIBarButtonItem){letnewMeme=save()letmemedImage=newMeme.memedImageletactivityViewController=UIActivityViewController(activityItems:[memedImage],applicationActivities:nil)presentViewController(activityViewController,animated:true,completion:nil)activit

ios - Swift: "This class is not key value coding-compliant..."用于 Double 值

我有一个场景,我在Swift中有一个简单的数据对象,其中包含多个属性变量。它们是String?和Double?值类型的混合。我正在尝试使用valueForKey检索每个属性的值。我的代码看起来像这样......letmyDataObj=...letstringKeyName="myStringProperty"letdoubleKeyName="myDoubleProperty"guardletstringPropertyValue=myDataObj.valueForKey(stringKeyName)else{return}guardletdoublePropertyValue=m

iOS swift : Value of type 'NotificationCenter' has no member 'publisher'

我正在尝试将新的Combine框架与NotificationCenter一起使用,正如Apple在这段视频中所解释的那样:https://developer.apple.com/videos/play/wwdc2019/721/您可以在幻灯片21中找到它。看来我的项目没有读取Combineframeworkapi。importCombineimportFoundationlettrickNamePublisher=NotificationCenter.default.publisher(for:.newTrickDownloaded)我收到这个错误:“NotificationCente

swift - "Initialisation of immutable value' 上下文 ' was never used, consider replacing assignment to ' _' 或删除它

我在swift中声明了一个变量letcontext:LAContext=LAContext()发出警告"Initialisationofimmutablevalue'context'wasneverused,considerreplacingassignmentto'_'orremovingit. 最佳答案 都在错误信息里value...wasneverused您的变量未在任何地方使用,因此Xcode告诉您可以删除它(因为拥有未使用的变量会浪费内存)。只需在某处使用您的变量,错误就会消失(例如,从中获取一个值,打印它等)。当然是指在

ios - 索引到函数数组 : Expression resolves to an unused l-value

我正在尝试对函数数组进行索引,但出现错误:“表达式解析为未使用的左值”。我试图用谷歌搜索这意味着什么,但信息很少,而且我发现的似乎无关。有谁知道我在这里做错了什么?任何帮助将非常感激!谢谢。overridefunctableView(tableView:UITableView,cellForRowAtIndexPathindexPath:NSIndexPath)->UITableViewCell{varcell:UITableViewCell=myTableView.dequeueReusableCellWithIdentifier("cell")asUITableViewCellva

swift - fatal error : unexpectedly found nil while unwrapping an Optional value when using AudioPlayer in Swift 2

您好,我正在尝试在swift2中使用以下代码播放音乐文件。基本上我只是将名为f.mp3的音频文件拖到asses文件夹中,我的代码中断并显示以下消息:在展开一个Optional值时意外地发现nil。我需要将mp3文件放在哪里,以便IOS可以找到它。谢谢varaudioPlayer:AVAudioPlayer!=nilfuncplayMyFile(){letpath=NSBundle.mainBundle().pathForResource("f",ofType:"mp3")letfileURL=NSURL(fileURLWithPath:path)do{tryaudioPlayer=AV

swift - 错误 : Cannot convert value of type 'URL' to expected argument type 'String'

我在将URL转换为字符串时遇到问题。getScreenShotDirectory()路径是file:///Users/Pat/Desktop/。我的目标是将其转换为字符串,因此路径可以类似于/Users/Pat/Desktop/leturlString=getScreenShotDirectory()letpathURL=URL(string:getScreenShotDirectory())!//error如果需要,我很乐意提供更多代码。 最佳答案 看来您的getScreenShotDirectory()方法已经是一个URL。因此

swift - 错误 : Could not cast value of type NSKVONotifying_MKUserLocation to Park_View. AttractionAnnotation

使用此功能时:funcmapView(mapView:MKMapView!,viewForAnnotationannotation:MKAnnotation!)->MKAnnotationView!{letannotationView=AttractionAnnotationView(annotation:annotation,reuseIdentifier:"Attraction")annotationView.canShowCallout=truereturnannotationView}发生此错误:Couldnotcastvalueoftype'NSKVONotifying_MK

ios - UIDatePicker的Value Changed事件在第一次改变值时不触发

这个问题在这里已经有了答案:UIDatePickerbug?UIControlEventValueChangedafterhittingminimuminternal(7个答案)关闭7年前。我使用Swift开发一个iOS应用。我在Storyboard上有一个文本字段,需要将UIDatePicker设置为其输入View。以下是我的代码。@IBOutletvartextField:UITextField!overridefuncviewDidLoad(){super.viewDidLoad()vardatePicker:UIDatePicker=UIDatePicker()datePick

iOS 8 核心数据堆栈 - fatal error : found nil while unwrapping an Optional value

我是iOS开发的新手,因此决定实现我自己的核心数据堆栈,以取代Apple的默认堆栈。我不得不对我的代码进行更改(很明显)并且已经能够弄清楚,但是在这种情况下我不能。这是我的代码:importUIKitimportCoreDataclassAddTableViewController:UITableViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate{@IBOutletweakvarnameTextField:UITextField!@IBOutletweakvarlocationTex