swift3

Swift 3 Type 'Any' has no subscript members

99封情书 提交于 2019-12-21 04:07:09
问题 I just converted my project to Swift 3 I have this line of code here: let type = self.data[indexPath.row]["Type"] as? String but now I get this error: Type 'Any' has no subscript members Why am I getting this error and do I fix it? 回答1: let type = (self.data[indexPath.row] as? [String : String])?["Type"] You need to cast self.data[indexPath.row] to a dictionary. 回答2: Either your data or the value returned when you subscript it, e.g. data[0] has the Any type, which you're trying to subscript.

Disable blinking cursor from UITextField in swift?

社会主义新天地 提交于 2019-12-21 03:51:36
问题 How to disable cursor in Swift from UITextField ? Condition - When the user logs in, then enter into application. If user can may me logout from application then not show cursor into UITextField. 回答1: First you need to confirm to UITextFieldDelegate and then set you textField like yourTextField.delegate =self add yourTextField.resignFirstResponder() to your code. Call resignFirstResponder to yourTextField. and you can also use below code (According to your need). In delegate method

Thread Safety for a getter and setter in a singleton

时光毁灭记忆、已成空白 提交于 2019-12-21 03:41:00
问题 I have created an simple singleton in Swift 3: class MySingleton { private var myName: String private init() {} static let shared = MySingleton() func setName(_ name: String) { myName = name } func getName() -> String { return myName } } Since I made the init() private , and also declared shared instance to be static let , I think the initializer is thread safe. But what about the getter and setter functions for myName , are they thread safe? 回答1: You are correct that those getters that you

Drawing text over Core Graphics in Swift 3

妖精的绣舞 提交于 2019-12-21 03:39:25
问题 Background: I am drawing on a UIImageView with Core Graphics. I would like to ultimately draw a text string over the core graphics drawing. This (hackingwithswift.com) method i used to draw the text to an image, set my imageView to that image, and then draw over with core graphics. But I want the text to overlay the core graphics drawing. Now I have moved to this https://stackoverflow.com/a/35574171/6337391 but it still isnt allowing me to write on top of my drawing. class MapViewController:

swift 3 get start index (as int) of substring

浪尽此生 提交于 2019-12-21 03:38:09
问题 I would like to get the start and end position of a substring within a string. Example: in the string "hi this is my name"; if I provide the string "this" I would like to know the start index is 4 and end index is 7. I found several links, including this one: Swift: get index of start of a substring in a string a-substring-in-a-string But it doesn´t work in swift 3 as the method is now called range. I am now using this: let range = mystring.range(of: "StringSearch")?.lowerBound which returns

How to make auto renewable subscriptions tied to in-house user, not apple id?

一世执手 提交于 2019-12-21 03:28:22
问题 I seem to have hit a brick wall, but essentially what I have in my app is a login page for the user and a create account page. When the user opens my app and creates a new account, their information is stored on a Firebase Server (BaSS). Now my question is how would I go about making it so that for every user that created an account through my application, they have the option to subscribe to my application, and this subscription is only valid for their account (not apple id). Currently, if

xcode 8 swift update with error “Use Legacy Swift Language Version”

廉价感情. 提交于 2019-12-21 03:19:20
问题 When i opened my project into Xcode 8 then I got the following error Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly referring to a similar post on StackOverflow , Use Legacy Swift Language Version YES/NO . But it's not working for me either by doing YES or No value ?

Add shadow to every section in grouped table view

心已入冬 提交于 2019-12-21 03:17:10
问题 As shown in image I want to add shadow to my table view sections. As like table view has 4 section then there would be 4 shadow view in table view. func numberOfSections(in tableView: UITableView) -> Int { return 3 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 3 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { switch processIndex { return cell } func tableView(_ tableView: UITableView,

How to manage users' different authentication in firebase

梦想的初衷 提交于 2019-12-21 03:16:32
问题 please help me finding correct solution in the following situation. I am developing ios app with swift which will use Firebase as a backend. Users should be able to login into firebase with email/password or/and with facebook. Maybe google will be added later. It is important for me to have one firebase account for each real user as user will have reward points and it won't make sense if on one devise(with email login) he will have X points and on other device(with facebook) he will have

How to write Dictionary to a file?

不打扰是莪最后的温柔 提交于 2019-12-21 03:15:41
问题 I have a FileHelper class where I've implemented 3 methods whose job is to write a Dictionary contents to a file. Those methods are: func storeDictionary(_ dictionary: Dictionary<String, String>, inFile fileName: String, atDirectory directory: String) -> Bool { let ext = "txt" let filePath = createFile(fileName, withExtension: ext, atDirectory: directory) /**** //If I use this method, file is created and dictionary is saved guard (dictionary as NSDictionary).write(to: filePath!, atomically: