swift2

How to record landscape video in a portrait application? (Swift 2, iPhone)

邮差的信 提交于 2019-12-19 04:44:14
问题 I need to record a landscape video inside my portrait iPhone application. Is it possible or is it blocked by any hardware limitation? Using AVCaptureVideoPreviewLayer I was able to change the preview orientation, but the video is still recorded in Portrait. Any idea is welcomed! 回答1: You should be able to set the orientation to landscape for the video recording. And set the preview layer to portrait to achieve a landscape video that is previewed in portrait. If I understand your question

Creating a generic method with AlamoFire in Swift

╄→尐↘猪︶ㄣ 提交于 2019-12-19 04:05:44
问题 I am using AlamoFire for my API calls, and have something like this all over my project: static func login(userName: String, password: String) -> User { let parameters = ["userName": userName , "password": password] let user = User() Alamofire.request(.POST, "myserver.com/login", parameters: parameters, encoding: .JSON) .validate() .responseObject { (response: Response<User, NSError>) in switch response.result { case .Success(let value): user.valueHandle?(value) case .Failure(let error): user

How to create a minimal daemon process in a swift 2 command line tool?

血红的双手。 提交于 2019-12-19 03:12:16
问题 What I am trying to do I want to run a daemon process that can listen to OSX system events like NSWorkspaceWillLaunchApplicationNotification in an command line tool xcode project? Is that possible? And if not, why not and are there any work arounds or hacks? Some code samples The following sample code from a swift 2 cocoa application project sets up a system event listener, which calls WillLaunchApp every time an OSX app gets started. ( this works just fine ) import Cocoa @NSApplicationMain

How do I get the error message in Swift 2.0?

瘦欲@ 提交于 2019-12-18 18:48:51
问题 I used this method very much in Swift 1.2: NSURLConnection.sendSynchronousRequest(:_:_:_) but this is apparently deprecated in iOS9. It still works however but now it uses the new Swift 2.0 Error Handling and I don't know how I will get the error message if it fails, ex. if time runs out. I know I have to put it into a do-catch and then say try before the metho but I dont know how to catch the error message. do { let data = try NSURLConnection.sendSynchronousRequest(request, returningResponse

Divide image in array of images with swift

[亡魂溺海] 提交于 2019-12-18 16:58:54
问题 I'm trying to divide an image to create 16 out of it (in a matrix). I'm using swift 2.1. Here's the code: let cellSize = Int(originalImage.size.height) / 4 for i in 0...4 { for p in 0...4 { let tmpImgRef: CGImage = originalImage.CGImage! let rect: CGImage = CGImageCreateWithImageInRect(tmpImgRef, CGRectMake(CGFloat(i * cellSize), CGFloat(p * cellSize), CGFloat(cellSize), CGFloat(cellSize)))! gameCells.append(cell) } } This works but the images that returns are only part of the original image.

Convert String to NSDate with Swift 2

回眸只為那壹抹淺笑 提交于 2019-12-18 14:54:03
问题 I'm trying to convert a string to NSDate here is my code let strDate = "2015-11-01T00:00:00Z" // "2015-10-06T15:42:34Z" let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy-MM-ddTHH:mm:ssZ" print ( dateFormatter.dateFromString( strDate ) ) I keep getting nil as a result 回答1: The "T" in the format string needs to be single quoted so it will not be consider a symbol: Swift 3.0 let strDate = "2015-11-01T00:00:00Z" let dateFormatter = DateFormatter() dateFormatter.dateFormat =

Swift property observer in protocol extension?

﹥>﹥吖頭↗ 提交于 2019-12-18 12:49:17
问题 Consider the following: protocol ViewControllable: class { typealias VM: ViewModellable var vm: VM! { get } func bind() } extension ViewControllable { var vm: VM! { didSet { bind() } } } I'm trying to observe vm property and call bind whenever it is injected. But this doesn't compile with error saying: Extensions may not contain stored properties which makes sense since protocol cannot enforce properties to be stored or computed . Is this possible to accomplish without introducing class

Swift 2: guard body may not fall through error

梦想与她 提交于 2019-12-18 12:46:18
问题 I have the following guard snippet, which is producing the error 'guard body may not fall through'. Whats wrong? guard NSFileManager.defaultManager().fileExistsAtPath(appBundlePath) else { print("App bundle doesnt exist") } 回答1: The guard statement needs to have a something to take the flow of the program away from the enclosing scope (e.g. most likely case is return to return from the function). This is required as the condition that guard is guarding will not be valid, so the program flow

How to make a HTTPS request to a server in swift?

核能气质少年 提交于 2019-12-18 12:42:17
问题 I am having server certificate and client certificate that needs to be included in the request to authenticate the server is there any tutorial or reference to make such requests in swift i am able to do in java but i am new to swift i want a resource in swift to authenticate and make requests to server my java code to make ssl configuration: SslConfigurator sslConfig = SslConfigurator.newInstance().securityProtocol("protocol") .keyStoreFile("/path").keyStorePassword("password").keyStoreType(

Swift: how to get Parse's many user's name and photo

限于喜欢 提交于 2019-12-18 09:38:19
问题 I have a bunch of users on my message app, fetching my "messages" class I need to get sender's first and last name and profile image from their Parse profile on my app in order to show them in each message on the tableView. I just want to show in tableView the name of users in class "messages" contained in the column "sender" wich contains pointers to PFUsers (of which I need "first_name", "last_name", "profile_picture") my users class my message class update! can't get where is the problem,