swift3

Camera and gallery image upload by alamofire in swift 3

那年仲夏 提交于 2019-12-13 03:20:59
问题 Hi there i have spent more than 20 hours to figure out how to upload image from my app to server, image which i want to upload could be either taken from camera or photo roll..... here is my code which does show progress of uploading but doesnt reach to server and thus gets negative response form server.. please help me.. Alamofire.upload(multipartFormData: { multipartFormData in multipartFormData.append(UIImageJPEGRepresentation(image, 0.1)!, withName: imageName) for (key, value) in

How to constrain a generic sequence parameter to a tuple in Swift 3?

Deadly 提交于 2019-12-13 02:38:50
问题 In Swift 2, I was able to write a function which operated on any sequence of, for example, (String, Int) . It looked something like this: func test<T: SequenceType where T.Generator.Element == (String, Int)>(input: T) { for (k, v) in input { print(k, "=", String(v)) } } Using a tuple as the constrained type was particularly useful so that it could accept dictionaries, such as [String:Int] , as their sequence type consisted of tuples. In Swift 3, I believe a similar function would be: func

How to implement pagination for collection view in table view cell in swift 3?

六眼飞鱼酱① 提交于 2019-12-13 02:26:17
问题 Here I am having layout in which one of my table view cell consists of collection view and in this I need to implement pagination and I am unable to use func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) this function now how to implement pagination for table view can anyone help me how to implement this to place condition when it reaches last element of my collection view and here I know how to implement pagination

swift 3 get a substring from query params

半腔热情 提交于 2019-12-13 02:12:50
问题 I want to get a substring from a larger string in swift 3. The string is just the query part of a url: user_one_id=7&user_two_id=5 I just want the id of each user, so I want 7 and 5. 回答1: A quite simple solution is to create URLComponents , assign the query part and (flat)map the query items to their values let string = "user_one_id=7&user_two_id=5" let components = URLComponents(string: "http://dummy.com?" + string) let userIDs = components?.queryItems?.flatMap{ $0.value } print(userIDs) let

Swift - Google Maps update directions from current location

房东的猫 提交于 2019-12-13 01:42:39
问题 I am currently in the process of learning the Google Maps API for Swift, and therefore I have a couple of questions that I hope can be answered by some of you guys. It just so happens that I am trying to create an app that simply gives the user directions, and much like Apple Maps and Google Maps, it simply draws a direction route for the user. I have managed to make this work, but what I am struggling with - is to simply 'update' the directions instead of constantly 'creating' new direction

Swift 3 - Capturing a photo on custom camera view

扶醉桌前 提交于 2019-12-13 00:37:42
问题 I am using Swift 3, Xcode 8.2. A lot of the tutorials that I find on this topic seem to always be in Swift 2. I have a custom camera view already created and I am trying to capture a photo from it. I've set up an @IBAction function below. The variable session_output is AVCapturePhotoOutput : @IBAction func shutterButtonPressed() { session_output.capturePhoto(with: AVCapturePhotoSettings.init(format: [AVVideoCodecKey : AVVideoCodecJPEG]), delegate: <#T##AVCapturePhotoCaptureDelegate#>) } I don

Using KVO within a tableview cell to track changes to specific properties of a class instance in Swift 3

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-12 23:29:08
问题 I'm trying to use KVO to track changes to the properties of my Account object, the important part of which looks like this: class Account: NSObject { var battleTagLabel: String! dynamic var onlineStatusIcon: String! dynamic var currentGameIcon: String! dynamic var currentStatusLabel: String! I want to be notified within my tableview cell when those three properties change in value. My tableview cell class: import Foundation import UIKit private var observerContext = 0 class FriendAccountCell:

NSObject setValuesForKeys coding-complaint error in Swift 4.0.2

谁说我不能喝 提交于 2019-12-12 22:24:00
问题 I usually would create an NSObject like the example below make a firebase observe single event call to get data, then I would create an instance of the NSObject and simply call the setValueForKeys method on the NSObject and the values will be passed in then I could easily use an if let statement to get the specific data I required. this has stopped working since I upgraded to swift 4.0.2 from swift 3.1 see code snippet below. I believe I am doing this wrong way, since the new update. As the

What is the correct way to reinterpret an entity in Swift?

谁都会走 提交于 2019-12-12 22:22:54
问题 There are cases when you have to deal with a structure of certain type, but the upstream API requires you to present it though a pointer to another type at other places. For instance, Unix Bind is expecting its second argument to be a pointer to a sockaddr , whereas the constructor should be sockaddr_in . For now I'm sticking to a two-layer with* : var sa = sockaddr_in(/* ... */) withUnsafePointer(to: &sa) { _sa in _sa.withMemoryRebound(to: sockaddr.self, capacity: 1) { __sa in let err = bind

How to get range of substring in swift3? [duplicate]

偶尔善良 提交于 2019-12-12 21:22:11
问题 This question already has answers here : How do I check if a string contains another string in Swift? (27 answers) Closed 3 years ago . How to get range of substring in swift3? let string = "Please Click Here" I need range of click 回答1: let string = "Please Click Here" if let range = string.range(of: "Click") { print(range) } 回答2: Convert to NSString and user rangeOf : let string = "Please Click Here" let range = (string as NSString).range(of: "Click", options: .caseInsensitive) print(range)