swift3

How to provide a localized description with an Error type in Swift?

心已入冬 提交于 2019-12-25 08:02:06
问题 I am defining a custom error type with Swift 3 syntax and I want to provide a user-friendly description of the error which is returned by the localizedDescription property of the Error object. How can I do it? public enum MyError: Error { case customError var localizedDescription: String { switch self { case .customError: return NSLocalizedString("A user-friendly description of the error.", comment: "My error") } } } let error: Error = MyError.customError error.localizedDescription // "The

How to add sticker VIEWS to browser view in swift?

旧巷老猫 提交于 2019-12-25 07:59:44
问题 Alright, like everyone Im new to ms stickers in Swift but I am trying to figure out the purpose of / difference between an mssticker and msstickerview. I have read the API here https://developer.apple.com/reference/messages/msstickerview/1648434-sticker but cant find an answer to this relatively simple problem - it seems you can only add MSStickers (not StickerViews) to an MSStickerBrowserView, which is the only way to display them. I however need to add StickerVIEWS because I have a custom

Pass value with action sheet button

こ雲淡風輕ζ 提交于 2019-12-25 07:54:17
问题 I created an ActionSheet with action of button. I have button that opens the action sheet and the ActionSheet button opens new viewController . The problem is that the button which opens the action sheet is inside tableview cell and I do not know how to pass value with this button. The concept should be something like this but with the action sheet button: actionSheet.addAction(UIAlertAction(title: "Edit it", style: UIAlertActionStyle.destructive, handler: { (ACTION :UIAlertAction!)in //here

How can I remove a certain CGPoint from a dictionaries

僤鯓⒐⒋嵵緔 提交于 2019-12-25 07:49:18
问题 I have seen a number of posts on looping through a dictionary but they are a different and simpler than what I want to achieve here, in my opinion. I have the following arrays: pt1.array = [0:[pt2.point], 1:[pt8.point, pt12.point, pt4.point], 2:[pt20.point, pt14.point, pt3.point], 3:[pt7.point, pt8.point, pt9.point]] pt2.array = [0:[pt5.point], 1:[pt8.point, pt11.point, pt1.point], 2:[pt10.point, pt9.point, pt3.point], 3:[pt6.point, pt1.point, pt4.point]] pt3.array = [0:[pt13.point], 1:[pt1

UIView reference error

狂风中的少年 提交于 2019-12-25 07:49:16
问题 I have created UIView in storyboard (Xcode 8.2.1). I reference the things inside to UIView class name LoginView . I delete one things by mistake then I got error at the line of Bundle.main.loadNibNamed("LoginView", owner: self, options: nil) . EXC_BAD_ACCESS(code=2,....) I read about this in some answer here, they said about referencing missing. I try to reference everything again but still error. I'm now confusing about what should I reference it to. File Owner or View. EDIT : The bug is

Why is indexPath for section 1 of a tableview starting with a value of [1,0]

ε祈祈猫儿з 提交于 2019-12-25 07:49:00
问题 I have a tableView and it's split into 2 sections. func numberOfSections(in tableView: UITableView) -> Int { return 2 } Each section has it's own FetchResultController (FRC). This is my CellForRoatAt function func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "personCell", for: indexPath) as! PersonTableViewCell switch(indexPath.section) { case 0: print("this is section 0") let person =

JSON structure with Swift and Alamofire

泄露秘密 提交于 2019-12-25 07:48:04
问题 Following on from This question I am trying to bring in the summary field but it has a further value. I have brought in the title and author as follows: func parseData(JSONData : Data) { do { var readableJSON = try JSONSerialization.jsonObject(with: JSONData, options: .mutableContainers) as! JSONstandard // print(readableJSON) if let posts = readableJSON["posts"] as? [JSONstandard] { for post in posts { let title = post["title"] as! String let author = post["author"] as! String let summary =

Swift: How to call non-class function if I have the same function in my class? [duplicate]

半世苍凉 提交于 2019-12-25 07:47:02
问题 This question already has answers here : Selecting global or object print function (2 answers) Closed 2 years ago . I know that I can just change names, but is there another way to solve this? class MyClass{ func print(_ string: String) { // I'm trying to call a native print method. // Results in error, because it's trying to do recursion. print(string, terminator: ";") } } 回答1: For global Swift builtins you can call Swift.whatever(argument) , so in this case: Swift.print(string, terminator:

Grand Central Dispatch Multiple DispatchGroups

自闭症网瘾萝莉.ら 提交于 2019-12-25 07:40:00
问题 I have three async calls. One returns data, and two return images from S3 using firebase. I have one background DispatchQueue, and three dispatch groups. I need a way for them to execute synchronously, but they don't! I have tried everything, and .notify executes immediately, which is wrong. The output of this is : images done all is done group.notify is done getImages() is done What I want to understand is why is imagesdone executed before group.notify is done? I need to execute the first