swift3

iOS Charts X Axis labels are not all showing

耗尽温柔 提交于 2020-06-28 05:03:51
问题 My app manages the score of a sport that has 4 quarter periods. My bar chart will not display the x-axis labels correctly. It only shows Qtr 1 and Qtr 3, whereas it should show all 4 quarters under each respective pair of bars. Screen shot of Bar Chart func setChart(dataPoints: [String], values1: [Double], values2: [Double]) { let legend = barChartView.legend legend.enabled = true legend.textColor = Style.labelTextColor let xaxis = barChartView.xAxis xaxis.drawGridLinesEnabled = true xaxis

Swift 3.0 convert Data to Array<UInt8>

自古美人都是妖i 提交于 2020-06-27 08:54:09
问题 How to convert Data to array of UInt8? func serialPort(_ serialPort: ORSSerialPort, didReceive data: Data) { print("recieved:\(data)") let arr: [UInt8] = Data(???)??? } log recieved:70 bytes 回答1: In Swift 3, Data works as a Collection of UInt8 , so you can simply use Array.init . var received: [UInt8] = [] func serialPort(_ serialPort: ORSSerialPort, didReceive data: Data) { print("received:\(data))") received = Array(data) } But, Array.init (or Array.append(contentsOf:) ) copies the content

Swift 3 Easy way to truncate Date to start of the day/month/year

倾然丶 夕夏残阳落幕 提交于 2020-06-25 09:26:05
问题 Is there any easy way to truncate date like we can do in Oracle Database? For example, I need to set value starting from midnight. In Oracle I can do TRUNC(SYSDATE). But I cannot see similar way to do it in Swift. I checked StackOverflow and saw some examples with DateFormatter, Date Components with converting Date to String. I have also seen this question, but didn't understand how to handle Date (not NSDate) type and i But I don't need String values. And I would like to avoid converting to

How to play AVPlayerItems immediately

為{幸葍}努か 提交于 2020-06-25 05:19:08
问题 I'm using AVPlayer which I connect to an remote URL via an AVPlayerItem . The problem is that I want to play the sound from the URL immediately and don't let the user wait for the AVPlayer to buffer. The thing is that if the remote URL's asset media is very short then it doesn't buffer for long at all but if the media is a bit longer it takes a while. Is there a way to skip the buffering process or at least shorten it substantially? 回答1: Swift 5 You just need to use the

Type of expression is ambiguous without more context Swift

本秂侑毒 提交于 2020-06-24 18:16:23
问题 I am getting a ' Type of expression is ambiguous without more context ' on this part of code from a project I am trying to upgrade to latest Swift version. I can't seem to figure it out. I tried different things but can't get it to work. The problem is on the syntax of this line let imageToDeleteParameters = imagesToDelete.map { ["id": $0.id, "url": $0.url.absoluteString, "_destroy": true] } Full code: extension TutorialCreationRequest: WebserviceParametrable { func toParameters() -> [String:

Type of expression is ambiguous without more context Swift

我怕爱的太早我们不能终老 提交于 2020-06-24 18:16:21
问题 I am getting a ' Type of expression is ambiguous without more context ' on this part of code from a project I am trying to upgrade to latest Swift version. I can't seem to figure it out. I tried different things but can't get it to work. The problem is on the syntax of this line let imageToDeleteParameters = imagesToDelete.map { ["id": $0.id, "url": $0.url.absoluteString, "_destroy": true] } Full code: extension TutorialCreationRequest: WebserviceParametrable { func toParameters() -> [String:

Swift 3.0: Value of type 'IndexSet' has no member 'enumerateIndexesUsingBlock'

倾然丶 夕夏残阳落幕 提交于 2020-06-23 07:13:43
问题 Receiving Value of type 'IndexSet' has no member 'enumerateIndexesUsingBlock' error at enumerateIndexesUsingBlock. /** Extension for creating index paths from an index set */ extension IndexSet { /** - parameter section: The section for the created NSIndexPaths - return: An array with NSIndexPaths */ func bs_indexPathsForSection(_ section: Int) -> [IndexPath] { var indexPaths: [IndexPath] = [] self.enumerateIndexesUsingBlock { (index:Int, _) in indexPaths.append(IndexPath(item: index, section

Swift 3.0: Value of type 'IndexSet' has no member 'enumerateIndexesUsingBlock'

人走茶凉 提交于 2020-06-23 07:11:33
问题 Receiving Value of type 'IndexSet' has no member 'enumerateIndexesUsingBlock' error at enumerateIndexesUsingBlock. /** Extension for creating index paths from an index set */ extension IndexSet { /** - parameter section: The section for the created NSIndexPaths - return: An array with NSIndexPaths */ func bs_indexPathsForSection(_ section: Int) -> [IndexPath] { var indexPaths: [IndexPath] = [] self.enumerateIndexesUsingBlock { (index:Int, _) in indexPaths.append(IndexPath(item: index, section

The fastest random number Generator

柔情痞子 提交于 2020-06-17 01:30:30
问题 I'm intending to implement a random number generator via Swift 3. I have three different methods for generating an integer (between 0 and 50000 ) ten thousand times non-stop. Do these generators use the same math principles of generating a value or not? What generator is less CPU and RAM intensive at runtime (having 10000 iterations)? method A : var generator: Int = random() % 50000 method B : let generator = Int(arc4random_uniform(50000)) method C : import GameKit let number: [Int] = [0, 1,

Mock third party classes (Firebase) in Swift

半城伤御伤魂 提交于 2020-06-11 18:36:46
问题 I'm trying to unit test a class of my own which is calling a method on a third party class: FIRAuth.auth()?.signInAnonymously() { (user, error) in // } I'm using protocol based dependency injection to achieve this: protocol FIRAuthProtocol { func signInAnonymously(completion: FIRAuthResultCallback?) } extension FIRAuth: FIRAuthProtocol {} class MyClass { private var firAuth: FIRAuthProtocol init(firAuth: FIRAuthProtocol) { self.firAuth = firAuth } func signIn() { firAuth.signInAnonymously() {