swift2

Can't get throws to work with function with completion handler

南楼画角 提交于 2019-12-23 07:22:04
问题 I'm trying to add a throws to my existing function with a completion handler but I keep getting a warning saying no calls throwing functions occur within try expression . In the section where I throw the errors, I get an error saying invalid conversion from throwing function of type '() throwing -> Void' to non-throwing function type. enum LoginError: ErrorType { case Invalid_Credentials case Unable_To_Access_Login case User_Not_Found } @IBAction func loginPressed(sender: AnyObject) { do{ try

Swift 2 remove object from array with contains string have

依然范特西╮ 提交于 2019-12-23 06:58:44
问题 I have string array in Swift 2: var myList : [String] = [] And I have dynamic strings inside and I explode them with * character myList examples: print(myList[0]) output = 2018-04-05*type2*namea print(myList[1]) output = 2018-04-05*type2*nameb print(myList[2]) output = 2018-04-05*type3*nameb print(myList[3]) output = 2018-04-06*type3*named I want to delete objects have type3 ones in myList: IF IN same date AND same name AND have type2 ones Must be my strings like that: print(myList[0]) output

Swift 2: Type of expression is ambiguous without more context, for a dictionary

陌路散爱 提交于 2019-12-23 06:08:47
问题 Why is the compiler throwing an error for the following code that attempts to create a dictionary? How would you fix this code? let options = [ kCVPixelBufferCGImageCompatibilityKey: true, kCVPixelBufferCGBitmapContextCompatibilityKey: true] I've looked through all of the other related questions with this same error and have not been able to find a solution. 回答1: How about let options : [NSObject : AnyObject] = [ kCVPixelBufferCGImageCompatibilityKey: true,

How can I use a protocol with a typealias as a func parameter?

巧了我就是萌 提交于 2019-12-23 06:01:14
问题 The following code: protocol ProtocolA { } protocol ProtocolB { typealias T: ProtocolA var value : Array<T> { get set } } class ProtocolC { func method<T: ProtocolA>(value: ProtocolB<T>) { } } Yields these errors: error: cannot specialize non-generic type 'ProtocolB' func method<T: ProtocolA>(value: ProtocolB<T>) error: generic parameter 'T' is not used in function signature func method<T: ProtocolA>(value: ProtocolB<T>) error: protocol 'ProtocolB' can only be used as a generic constraint

How to open particular post on the click on push notification

北慕城南 提交于 2019-12-23 05:19:12
问题 in my app i implemented push notification. when my app is in running state and if push notification come i am handle that with this code. func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { print(userInfo) myid = (userInfo["id"] as? String)! print(myid) if let notification = userInfo["aps"] as? NSDictionary, let alert = notification["alert"] as? String { var alertCtrl = UIAlertController(title: "Notification", message: alert as String,

Can't use Objective-C Pod Framework in Swift 2 project (“Use of undeclared type 'SMPageControl'”)

和自甴很熟 提交于 2019-12-23 05:07:33
问题 I have a Swift 2 project running on Xcode 7. I'm using CocoaPods (v 0.38.2 with use_frameworks! ) and have already managed to get those frameworks working: CryptoSwift Pluralize_swift Both Pods are written in Swift, so no problems so far. They work as charm. Now I'm trying to use SMPageControl which is written in Objective-C. I've seen it's possible to use Obj-C Pods with Swift 2, tried a lot of different combinations but I can't get it to work. SMPageControl class doesn't show on

Pin an annotation to mapView with the saved coordinates in CoreData

梦想的初衷 提交于 2019-12-23 04:44:02
问题 I have searched now all over the internet and I have tried almost everything. My current project is: I read the current coordinates from the User Location and save the latitude and longitude in CoreData and the name of this place(user can give a name) // MARK: - AddPlace Button Events @IBAction func onAddButton(sender: AnyObject) { //searching the current location let locCoord = CLLocationCoordinate2DMake(self.locationManager.location!.coordinate.latitude, self.locationManager.location!

Swift Generics and Protocol Extensions

女生的网名这么多〃 提交于 2019-12-23 04:22:51
问题 I have a protocol Reusable that has a static function static func reuseId() -> String and a protocol extension that defines the default implementation for the function. Then, I implemented a extension on UITableViewCell to conform to the Reusable protocol. I can now use the function on my TableViewCells without a problem: SomeTableViewCell.reuseId() . The Problem I have is with Generics. I have a generic class that has a generic parameter of the type UITableViewCell : internal class SomeClass

Native Swift implementation of DEFLATE (unzip) algorithm [closed]

不想你离开。 提交于 2019-12-23 03:42:19
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . I have some data that has been compressed with the DEFLATE algorithm which I believe is basically just saying its zipped up. I'm writing a swift app and I was interested in figuring out if there is a native pure swift (2.0) implementation of the unzip algorithm. I need to implement this in a swift dynamic

Ios Swift Override double tap of UItextField

戏子无情 提交于 2019-12-23 03:04:30
问题 I want to write a custom code on double tap on UITextField and block the default text editing and popup of the keyboard. I've tried the following and nothing has worked for me so far. Kindly help me solve this problem. let gestureArray = NamTxtBoxVal.gestureRecognizers var tapGesture = UITapGestureRecognizer() for idxVar in gestureArray! { if let tapVar = idxVar as? UITapGestureRecognizer { if tapVar.numberOfTapsRequired == 2 { tapGesture = tapVar NamTxtBoxVal.removeGestureRecognizer