swift3

Swift3 UITextField in UIAlert validation after button pressed

↘锁芯ラ 提交于 2020-01-07 04:39:05
问题 I have implemented alert window with two text fields. And I want to perform some validation: if one of text fields is blank (user did not input any value), application should not allow user to press the "Done" button. I don't want to show any alerts, just want to not allow user to save blank data. I have created the function listed below. Added two guards with return. But in this case if user did not input anything, alert just closes and nothing is saved. I don't want alert window to be

How to restrict textfield to accept only decimal values in swift

梦想的初衷 提交于 2020-01-07 04:19:29
问题 I want to accept only decimal values in my textfield. The following code allows me to enter only numbers and '.' but we can enter more than one '.' How can i restrict it to just one '.' or how can I restrict the textfield to accept only decimal values in swift 3.1 let aSet = NSCharacterSet(charactersIn:"0123456789.").inverted let compSepByCharInSet = r_Qty_txt.text?.components(separatedBy: aSet) let numberFiltered = compSepByCharInSet?.joined(separator: "") My target device is iPad.

Json and variable scope

不羁岁月 提交于 2020-01-07 03:17:06
问题 My error should be quite obvious but I can't find it; I've a global variable initialized a the beginning of my class: class InscriptionStageViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource { var lesSemaines = [String]() I try to populate this array with a distant json file using that function func getSemainesStages(){ let url = URL(string: "http://www.boisdelacambre.be/ios/json/semaines.json") let task = URLSession.shared.dataTask(with: url!){ (data, response,

delete core data managed object with Swift 3

99封情书 提交于 2020-01-07 02:58:27
问题 Swift 3 has migrated my code and changed: context.deleteObject(myManagedObject) to context.delete(myManagedObject) this is compiling fine (XCode 8b3) but at runtime complaining that the context does not have a function/selector delete(managedObject) Here is the runtime error: [NSManagedObjectContext delete:]: unrecognized selector sent to instance My code is very basic: func delete() { let appDel: AppDelegate = UIApplication.shared().delegate as! AppDelegate if let context:

Why isn't viewWithTag and some other methods renamed in Swift 3?

雨燕双飞 提交于 2020-01-07 02:37:10
问题 In Swift 3, a lot of the methods got renamed. According to one of the sessions at WWDC, the prepositions in method names are moved to the parameter name: UIView.animateWithDuration(1) -> UIView.animate(withDuration: 1) UIStoryboard.instantiateViewControllerWithIdentifier("some stuff") -> UIStoryboard.instantiateViewController(withIdentifier: "some stuff") So I thought viewWithTag(1) will be renamed to view(withTag: 1) , but it isn't! There is even mentioned in the API guidelines: Especially

Archive is not success, due to error code -1, Although I can do build and install in my devices with developement profile

僤鯓⒐⒋嵵緔 提交于 2020-01-06 21:09:37
问题 My Application is coded with swift 3 And core-data as offline information storage. I'm not able to archive my application due to long list or error like <unknown>:0: error: no such file or directory: '/Users/Ashwin/Library/Developer /Xcode/DerivedData/BeerScout-eweygxkfdhbkbkalbiyywrsuievg/Build /Intermediates/ArchiveIntermediates/BeerScout/IntermediateBuildFilesPath /BeerScout.build/Release-iphoneos/BeerScout.build/DerivedSources /CoreDataGenerated/BeerScout/Beer+CoreDataClass.swift' ... And

How do I make changes to my interface while a button is pressed

佐手、 提交于 2020-01-06 19:53:45
问题 I've got a button that will do some math when tapped. Depending on the equation that the user enters, the button will be tapped, but then stay down, as the app takes a while to do the math in the button's function. It would be great if I could have a progress bar show the user during that time. I added one, but the problem is that it doesn't show up when the button has been tapped, as the button is lagging.. it seems that no changes can occur on the screen while the button is tapped down and

Delete model from Realm

女生的网名这么多〃 提交于 2020-01-06 19:28:36
问题 I am trying to remove a model from Realm. I appears there's a straightforward way to do it in Java with realm.getSchema().remove(className) It doesn't appear there is an option in Swift 3 other than to remove the model from the App and then migrate the data, or delete the entire Realm file. To clarify, when I open the Realm Browser I have three models Dog 2 Person 4 Test 0 and I want to remove just the Test model via code. There doesn't appear to be any way to remove it via the Browser either

iOS Mapbox annotation not opening

夙愿已清 提交于 2020-01-06 19:27:26
问题 Fairly new to iOS dev and I'm following the "first steps with the iOS MapBox SDK" tutorial for Swift (https://www.mapbox.com/help/first-steps-ios-sdk/). Things were fine with displaying the map, custom style, and adding an annotation. But then encountered an issue when trying to interact with the annotation to display its title and subtitle. The print("allow") print("tap on callout") don't seem to ever get called. Even mapView.selectAnnotation(point, animated: true) doesn't do anything (and

Swift 3 extension constrained to a type

白昼怎懂夜的黑 提交于 2020-01-06 18:57:42
问题 I'd like to extend an RXSwift protocol, namely OsbervableConvertibleType, but I only want to create an extension method only on OsbervableConvertibleTypes, that has a Result object in them. Now, Result is generic again. But I'd like to retain the generic type in my extension function, so the return type of my function is generic as well. Something like this: extension ObservableConvertibleType where E: Result<T> { public func asResultDriver() -> RxCocoa.SharedSequence<RxCocoa