swift3

Loading a previously saved audio file as base64 string

£可爱£侵袭症+ 提交于 2020-01-04 01:37:07
问题 I record and save an audio file, this works and plays in the app as expected. After the recording, however, I try to load it so I can pass the audio into a JSON object, but can't open it. I get the following error: The file “audio.m4a” couldn’t be opened because the text encoding of its contents can’t be determined. This is call I'm making: do { let audioData = try NSData(contentsOfFile: String(contentsOf: audioURL!)) } catch { print error } Any ideas how I can load the audio data as from the

Is there any alternative for NSInvocation in Swift?

偶尔善良 提交于 2020-01-03 21:12:11
问题 I'm trying to invoke a selector, with multiple (2+) arguments (the number of arguments can be determined). However, the selector is unknown at compile time (generated with NSSelectorFromString, actually). In Objective-C, I could create an invocation and set arguments to it and invoke it. But this is not available in Swift. Is there any way around this? Like: let obj = SomeClass() let selector = NSSelectorFromString("arg1:arg2:arg3:") //selector, arguments known only at runtime //invoke

Difference between UserDefaults() and UserDefaults.standard

久未见 提交于 2020-01-03 21:09:42
问题 Is there a difference between UserDefaults() and UserDefaults.standard in Swift 3.0? 回答1: UserDefaults - Gives you a new object , each object is allocated a different memory and deallocated when object scope is finished. UserDefaults.standard - Gives you the singleton object by using the class method standard the object received by this method is allocated single memory throughout the application. And the usage of them if you´re interesedted in that: // Set UserDefaults.standard.set("YOUR

Getting error while installing realm through cocoapods

孤人 提交于 2020-01-03 21:03:03
问题 I am getting this strange error while installing realm on xcode 8 , cocoa pods version cocoapods-1.2.0 The error is - Installing Realm (2.4.3) [!] /bin/bash -c set -e sh build.sh cocoapods-setup ./scripts/swift-version.sh: line 59: [: =: unary operator expected No version of Xcode found that supports Swift 3.0.2 All other pods work great. Thanks for the help in advance. 回答1: Hey for anyone looking for an answer - I did find out that I had the second xcode installed (xcode 7), due to which the

What is the `_base` property of an ReverseRandomAccessCollection?

北慕城南 提交于 2020-01-03 20:58:27
问题 Is it good practice to use the _base property to access the elements of a ReverseRandomAccessCollection ? let myArray = [1, 2, 3] print(myArray.first) // returns 1 print(myArray.reversed().first) // returns 3 print(myArray.reversed()._base.first) // return 1, which is the underlying base array 回答1: A ReverseRandomAccessCollection (you can see its full implementation here) is a simply a wrapper that presents a reversed view onto an underlying RandomAccessCollection (this saves from having to

What is the `_base` property of an ReverseRandomAccessCollection?

不羁的心 提交于 2020-01-03 20:57:16
问题 Is it good practice to use the _base property to access the elements of a ReverseRandomAccessCollection ? let myArray = [1, 2, 3] print(myArray.first) // returns 1 print(myArray.reversed().first) // returns 3 print(myArray.reversed()._base.first) // return 1, which is the underlying base array 回答1: A ReverseRandomAccessCollection (you can see its full implementation here) is a simply a wrapper that presents a reversed view onto an underlying RandomAccessCollection (this saves from having to

Class methods access level internal by default

只谈情不闲聊 提交于 2020-01-03 20:03:22
问题 Usually your class have many methods. Its annoying to set the access modifier for all of them as private and keep one or two with no access modifier. Is there a way to let all methods private by default and give the access modifier to the public ones? maybe by assigning an access modifier for the class. 回答1: Move all your private methods to an extension in the same file and mark it as fileprivate . class Foo { // public stuff, stored properties etc. } fileprivate extension Foo { // private

How to perform action for a custom UITableViewCell inside my viewController?

孤者浪人 提交于 2020-01-03 19:38:51
问题 I have a custom cell that has a xib, this cell contains a button, when the button is pressed I want to do an action , but not inside my custom cell class but from inside the viewcontroller that contains the tableview of the custom cell, any help please? 回答1: First of all you should write a protocol for example: protocol CustomCellDelegate { func doAnyAction(cell:CustomUITableViewCell) } Then inside your custom cell class declare: weak var delegate:CustomCellDelegate? and inside your IBAction

How to use an image logo on the navigation bar instead of title

二次信任 提交于 2020-01-03 16:52:35
问题 I have tried a couple different codes but couldn't make the logo show import UIKit class HomeViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let logo = UIImage(named: "logo.png") let imageView = UIImageView(image: logo) self.navigationItem.titleView = imageView navigationItem.titleView?.sizeToFit() } } I even tried to include IB in the class itself didn't work either, it doesn't seem to work that way @IBOutlet weak var navBar: UINavigationItem! PS. My logo

iOS Swift, AWS Cognito User Pool, Unable to Refresh Access Token

萝らか妹 提交于 2020-01-03 14:18:08
问题 Looked at similar SO questions which didn't help me resolve the issue. I am using AWS Cognito User Pools in our iOS App. We are able to successfully create and login the user. However after about an Hr the access token is not available , I understand from AWS Cognito documentation that the iOS SDK automatically refreshes (also mentioned here) and obtains the token when it is not available, however I don't see this behaviour. The below code shows how I am trying to obtain the access token.