swift2

Local Notification every specific day of week

戏子无情 提交于 2020-01-23 02:38:11
问题 I need to create a local notification for a specific time (example at 18.00) fired every working day of week (not Saturday and Sunday) but I can't find examples or tutorial. I want use with swift2.1. How can I create this notification? My problem is define the firedate correctly of the notification 回答1: You can use NSDateComponents to create the exact date for your local notification. Here is the example, how do we create local notification with exact fire date: NSDate *now = [NSDate date];

Pass Parameter with UITapGestureRecognizer

做~自己de王妃 提交于 2020-01-22 17:33:06
问题 Is there any way i can pass parameters with UITapGestureRecognizer? I've seen this answered for objective-c but couldn't find an answer for swift test.userInteractionEnabled = true let tapRecognizer = UITapGestureRecognizer(target: self, action: Selector("imageTapped4:")) // Something like text.myParamater test.addGestureRecognizer(tapRecognizer) And then receive myParameter under func imageTapped4(){} 回答1: One approach would be to subclass UITapGestureRecognizer and then set a property, I've

Is it possible to build Swift code using the Foundation Framework and target linux?

╄→尐↘猪︶ㄣ 提交于 2020-01-22 15:15:27
问题 I know it will be released as open source in the end of the year, however I would like to know, if I create a framework that uses the Foundation framework, will it still be possible to build for Linux? On the announcement it was said that they would be releasing Swift and a compiler for linux. Will builds of the open source version be limited to the standard Swift library? I would really like to create a Web Service in Swift to run in Linux, but I need the Foundation Framework (I don't need

Is it possible to build Swift code using the Foundation Framework and target linux?

一笑奈何 提交于 2020-01-22 15:15:23
问题 I know it will be released as open source in the end of the year, however I would like to know, if I create a framework that uses the Foundation framework, will it still be possible to build for Linux? On the announcement it was said that they would be releasing Swift and a compiler for linux. Will builds of the open source version be limited to the standard Swift library? I would really like to create a Web Service in Swift to run in Linux, but I need the Foundation Framework (I don't need

Swift 2 How to encode from ASCII to Hexadecimal

蓝咒 提交于 2020-01-22 03:00:09
问题 I have a simple ASCII string and i want to convert it to hexadecimal (base16). I'm using xCode 7 (so i'm on IOS9) but i can't find any solution anywhere. I tried to change the format of my string: StringToConvert(String(format: "%02hhx", $0)) Thanks for your help :) 回答1: "abcdefghijklmnopqrstuvwxyz0123456789".utf8.map{ $0 }.reduce("") { $0 + String($1, radix: 16, uppercase: false) } modify it by your needs "ABCD".utf8.map{ $0 }.reduce("") { $0 + "0x" + String($1, radix: 16, uppercase: false)

How to auto clear NSUserDefault values in swift? [duplicate]

跟風遠走 提交于 2020-01-19 23:24:29
问题 This question already has answers here : Delete all keys from a NSUserDefaults dictionary iOS (15 answers) Closed 3 years ago . How can I auto clear the nsuserdefault values in swift? I have already tried this but it doesn't work for me... [[NSUserDefaults standardUserDefaults] setPersistentDomain:[NSDictionary dictionary] forName:[[NSBundle mainBundle] bundleIdentifier]]; 回答1: check how many keys are already stored print(NSUserDefaults.standardUserDefaults().dictionaryRepresentation().keys

Upgrade Xcode 7.3.1 Project to Xcode 8.0

拜拜、爱过 提交于 2020-01-17 18:02:29
问题 I want to upgrade my Xcode 7.3.1 Project to Xcode 8. My project was written in swift 2.2 in Xcode 7 but now I want to upgrade to Xcode 8 with swift 3.0. My project contains some pod-files library while upgrading to Xcode 8, I am facing lots of warning and error. Warning related to storyboard is solved but Error in pod files are not solved. Xcode tell me to convert swift syntax to latest syntax so I did it. Swift syntax error shows in pod-files. I am trying to solve pod file swift syntax error

How to use array of another view controller class?

主宰稳场 提交于 2020-01-17 13:51:22
问题 I need to use the order array in another class ( AddOrderVievContoller.swift class) class OrderListViewController: UITableViewController { var orders: [Order] = [] error message in AddOrderVievContoller.swift class: use of unresolved indentifier 'orders' if results != nil { orders = results as! [Order] } 回答1: Create a global variable: public var orders = [String]() place this in-between the modules your importing ( import UIKit ) and the class definition: import UIKit public var orders =

Pick a random UI Image View - Swift 2

梦想与她 提交于 2020-01-17 05:03:11
问题 So I have 3 images @IBOutlet weak var imageOne: UIImageView! @IBOutlet weak var imageThree: UIImageView! @IBOutlet weak var imageTwo: UIImageView! I generate a random image from an array of images, the random image generated is the "correct" image Here is how I was currently doing it let randomIndex = Int(arc4random_uniform(UInt32(famousPeople.count))) let correct = famousPeople[randomIndex] self.imageOne.image = UIImage(named: correct) Obviously the issue with this is the imageOne is always

How to download and process 2 sets of data, one after the other?

自作多情 提交于 2020-01-17 04:49:18
问题 I am making a webservice call to get a list of data. After I have all of that data I would like to make a web call for every item on that list. Here is the code I have this far: let zipcde:String = self.zipCode let username:String = "tr1gger" //webservice call var listZip = [String]() let wsUrl: NSURL = NSURL(string: "http://api.url.org/findNearbyTheseCodesJSON?postalcode=" + zipcde + "&maxRows=100&country=US&radius=25&username=" + username)! let task = NSURLSession.sharedSession()