swift3

How can I switch views programmatically in a view controller? (Xcode, iPhone)

懵懂的女人 提交于 2019-12-17 10:20:11
问题 Have been struggling with this for a while, and can never seem to get a direct answer. Any help is appreciated! 回答1: If you're in a Navigation Controller: ViewController *viewController = [[ViewController alloc] init]; [self.navigationController pushViewController:viewController animated:YES]; or if you just want to present a new view: ViewController *viewController = [[ViewController alloc] init]; [self presentViewController:viewController animated:YES completion:nil]; 回答2: If you want to

add Shadow on UIView using swift 3

余生长醉 提交于 2019-12-17 10:19:45
问题 prior swift 3 i was adding shadow in my UIView like this : //toolbar is an UIToolbar (UIView) toolbar.layer.masksToBounds = false toolbar.layer.shadowOffset = CGSize(width: -1, height: 1) toolbar.layer.shadowRadius = 1 toolbar.layer.shadowOpacity = 0.5 but the above code is not working in swift 3 , instead of shadow my whole View's color is turned to ugly gray anyone knows how can we add shadow in swift 3 ? 回答1: CODE SNIPPET: extension UIView { // OUTPUT 1 func dropShadow(scale: Bool = true)

Add a Watermark on Video after merging Video and Audio Asset into one in Swift3 iOS

为君一笑 提交于 2019-12-17 10:14:13
问题 I am working on Video based application in Swift3 . As per my requirement I have to merge Video and Audio AVAsset into one, adjust their volumes separately and save the final Video in iPhone Device gallery . This is working fine using below code: func mergeVideoAndMusicWithVolume(assetVideo: AVAsset, assetMusic: AVAsset, startAudioTime: Float64, volumeVideo: Float, volumeAudio: Float){ //To merging a video and a music and set it a volume let dirPaths = NSSearchPathForDirectoriesInDomains(

How to read/write from one IOS App set up with firebase, to another firebase database contained in another firebase project? Swift 3

纵饮孤独 提交于 2019-12-17 10:10:08
问题 I have a Firebase database connected to my IOS app with the GoogleService-Info.plist. In AppDelegate I configured the App FIRApp.configure(). I could read/write data. Now, from within this IOS app, I would like to access another FireBase Database brevCustomer . For some reason let dbRef from viewDidLoad has a flag in Xcode saying this 'immutable value dbRef was never used' and the app crashes on the first line in fun startObserving() dbRef.observe(.value, with: { (snapshot: FIRDataSnapshot)

Redirect NSLog to File in Swift not working

自古美人都是妖i 提交于 2019-12-17 10:05:53
问题 I am trying to send NSLog to a file in Swift 3 running on Simulator, IOS 10.2 and nothing is being produced How to NSLog into a file func redirectConsoleLogToDocumentFolder() { let file = "file.txt" if let dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first { let logPath = dir.appendingPathComponent(file).absoluteString print("log:\(logPath)") freopen(logPath, "a+", stderr) } NSLog("print nslog") } Output ~/Library/Developer/CoreSimulator/Devices/A7B717-3ED8

Reorder array compared to another array in Swift [duplicate]

ぐ巨炮叔叔 提交于 2019-12-17 09:58:41
问题 This question already has answers here : Sorting a Swift array by ordering from another array (6 answers) Closed 5 months ago . I have one array in Swift containing some ids of objects, and I have another array containing these objects with their ids, so something like this: class MyObject { let id: String ... } let ids: [String] = ... let objects: [MyObject] = ... Now the array of ids is sorted in some custom order, and I need the array of objects to be sorted in the same order. So for

Convert Swift Array to Dictionary with indexes [duplicate]

♀尐吖头ヾ 提交于 2019-12-17 09:48:18
问题 This question already has answers here : Error: Immutable value passed on reduce function (3 answers) Closed 4 years ago . I'm using Xcode 6.4 I have an array of UIViews and I want to convert to a Dictionary with keys "v0", "v1"... . Like so: var dict = [String:UIView]() for (index, view) in enumerate(views) { dict["v\(index)"] = view } dict //=> ["v0": <view0>, "v1": <view1> ...] This works, but I'm trying to do this in a more functional style. I guess it bothers me that I have to create the

UIImagePickerController crashes app | Swift3, Xcode8

眉间皱痕 提交于 2019-12-17 09:33:36
问题 FYI: I´m new to Swift so this might be a really simple problem but I just can´t figure it out. I have been following the Start Developing iOS Apps (Swift) tutorial using the Xcode 8 beta and Swift 3. I attached a Tap Gesture Recognizer to a Image View and then added this action in the ViewController.swift : @IBAction func selectImageFromPhotoLibrary(_ sender: UITapGestureRecognizer) { // Hide the keyboard. nameTextField.resignFirstResponder() // UIImagePickerController is a view controller

try, try! & try? what’s the difference, and when to use each?

江枫思渺然 提交于 2019-12-17 07:58:33
问题 In Swift 2.0, Apple introduced a new way to handle errors (do-try-catch). And few days ago in Beta 6 an even newer keyword was introduced ( try? ). Also, knew that I can use try! . What's the difference between the 3 keywords, and when to use each? 回答1: Updated for Swift 5.1 Assume the following throwing function: enum ThrowableError: Error { case badError(howBad: Int) } func doSomething(everythingIsFine: Bool = false) throws -> String { if everythingIsFine { return "Everything is ok" } else

Alamofire fire variable type has no subscript members

我是研究僧i 提交于 2019-12-17 07:50:19
问题 After updating to Alamofire 4 and updating my code to Swift 3, all of my requests are not working for some reason. The variables that I am trying to utilize are highlighted in red and say "Type Any' has no subscript members" Here is my code: Alamofire.request("https://example.com/notifications.php?action=\(action)&UUID=\(UniversalUUID)&token=\(token)").responseJSON{ (response) -> Void in if let JSON = response.result.value{ let message = JSON["message"] as! String print(message) } 回答1: You