swift3

flatMap and `Ambiguous reference to member` error

断了今生、忘了曾经 提交于 2019-12-24 10:24:12
问题 Consider the following code: typealias PersonRecord = [String : AnyObject] struct Person { let name: String let age: Int public init(name: String, age: Int) { self.name = name self.age = age } } extension Person { init?(record : PersonRecord) { guard let name = record["name"] as? String, let age = record["age"] as? Int else { return nil } self.name = name self.age = age } } Now I want to create an array of Person s from an array of Record s: let records = // load file from bundle let persons

How to add spacing to Left BarButtonItem Image with Swift 3

强颜欢笑 提交于 2019-12-24 09:57:44
问题 I would like to add space to the left of the bar button. So, I add this code. navbar.autoresizingMask = [.flexibleWidth, .flexibleBottomMargin, .flexibleRightMargin] navbar.delegate = self UINavigationBar.appearance().barTintColor = UIColor(red: 0.0/255.0, green:49.0/255.0, blue:79.0/255.0, alpha:0.1) UINavigationBar.appearance().tintColor = UIColor.white UINavigationBar.appearance().isTranslucent = true UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName :

How to use Big5 encoding in Swift on iOS

烂漫一生 提交于 2019-12-24 09:50:12
问题 I'm scanning a QR-Code with chinese characters encoded in Big5. (主页概况) Is there a chance to get this String decoded correctly in Swift 3? I found this Objective-C example on GitHub and this SO question, but there are no kCFStringEncodingBig5_HKSCS_1999 and kCFStringEncodingBig constants in Swift. Update: I found the corresponding swift variables, so i now tried the following: func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from

Creating A Numbered List In UITextView Swift 3

不问归期 提交于 2019-12-24 09:48:59
问题 I am trying to make a numbered list out of the information the user inputs into a UITextView. For example, List item one List item two List item three Here is the code that I have tried but does not give me the desired effect. var currentLine: Int = 1 func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool { // Add "1" when the user starts typing into the text field if (textView.text.isEmpty && !text.isEmpty) { textView.text = "\

Google Face Detection crashing when converting to image and trying to detect face

杀马特。学长 韩版系。学妹 提交于 2019-12-24 09:48:01
问题 I am creating a custom camera with filters. When I add the following line it crashes without showing any exception. //Setting video output func setupBuffer() { videoBuffer = AVCaptureVideoDataOutput() videoBuffer?.alwaysDiscardsLateVideoFrames = true videoBuffer?.videoSettings = [(kCVPixelBufferPixelFormatTypeKey as NSString): NSNumber(value: kCVPixelFormatType_32RGBA)] videoBuffer?.setSampleBufferDelegate(self, queue: DispatchQueue.main) captureSession?.addOutput(videoBuffer) } public func

Programming autolayout swift

偶尔善良 提交于 2019-12-24 09:40:10
问题 I have in app: TextView and TableView. I create their in code. And now I need to make programming autolayout. But I don't know how it make. Please help. P.S. Sorry for my English =) let displayWidth: CGFloat = self.view.frame.width let displayHeight: CGFloat = self.view.frame.height myTextView = UITextView(frame: CGRect(x: 0, y: 20, width: displayWidth, height: displayHeight / 3)) creatTextView() myTableView = UITableView(frame: CGRect(x: 0, y: displayHeight / 3, width: displayWidth, height:

How to change label color inside table cell with swift 3?

試著忘記壹切 提交于 2019-12-24 09:38:03
问题 I put label inside table cell. I changed the text color into "White" in Attributes inspector. I also changed the label background color into "Green". When I run the app, the text color does not change into white color but background changed to green. I also put the code. cell.lblName.textColor = UIColor.white I declare this @IBOutlet weak var lblAllowAutoRenew: UILabel! in MediaPackListCell.swift file. In TableView.swift , func tableView(_ tableView: UITableView, cellForRowAt indexPath:

Swift 3: How to remove the tracked polyline in Google map

给你一囗甜甜゛ 提交于 2019-12-24 09:33:06
问题 I have draw the polylines, but I don't no that what coding can remove the tracked polyline in the google map. I'm trying some coding in below. this is no working. var polyline = GMSPolyline() polyline.map = nil this is working to remove tracked polyline, but when I'm maked the markers and tap it, marker can not sow the info window. mapView.clear() Thank you 回答1: Solution: create polyline: teaching polyline by GoogleMapsAPIs create variable oldPolylineArr/oldPolyline type GMSPolyline

Binary operator '??' cannot be applied to operands of type 'AnyObject?' and 'String'

微笑、不失礼 提交于 2019-12-24 09:03:05
问题 I have done below code with Swift 2.2, but when switched to Swift 3.0 getting error at if condition "Binary operator '??' cannot be applied to operands of type 'AnyObject?' and 'String'" if let custID = dataDict["cust_id"] ?? "", let custName = dataDict["cust_name"] ?? "", let fileName = dataDict["filename"] ?? "", let transNumber = dataDict["trans_no"] ?? "" { linesheet_custID = (custID["text"] ?? "" ) as! String linesheet_custName = (custName["text"] ?? "" ) as! String linesheet_filename =

Calendar Changed in Swift 3?

做~自己de王妃 提交于 2019-12-24 09:01:00
问题 Hey so I'm working on this little app and I let durationDateComponents = Calendar(identifier: Calendar.Identifier.gregorian).dateComponents([.year, .month, .day, .hour, .minute, .second], from: Date(), to: christmasDay, options: []) What do I do here? I get that the error is pointing me to change something with the array, but what? Thanks! 回答1: Remove options . That's not part of dateComponents and thus the compiler is having trouble identifying the method. let calendar = Calendar.current //