swift2

How to handle error with Realm during writing?

点点圈 提交于 2019-12-12 11:05:57
问题 I'm used to working with SQL database, I'm new to Realm and, so far, I'm really impressed by the ease of use of this new mobile database. But there is something that I really don't undestand: how to handle error throwing? Take this simple example: I want to store in a Realm DB some market stocks. Each stock has a "symbol" as a unique identifier: APPL for Apple Inc, TSLA for Tesla Motors Inc, etc. I believe it would make sense to declare these symbols as primary keys, since it's not possible

Swift delegate protocol cannot prevent retain cycle issue

♀尐吖头ヾ 提交于 2019-12-12 10:46:20
问题 In Swift, if I create a delegate protocol, it can be conformed to by class and struct. protocol MyDelegate { // Can be conformed to by class or struct } The issue comes up when I declare the delegate. If the delegate is a class instance, I want the variable to be weak to avoid retain cycle. If it is a struct, there is no such need - in fact, Swift won't allow me to make the delegate variable weak. Note: I know how to create a weak delegate, but the key question is - if you create a delegate

What is the 0xFFFFFFFF doing in this example?

China☆狼群 提交于 2019-12-12 10:43:59
问题 I understand that arc4random returns an unsigned integer up to (2^32)-1. In this scenario it it always gives a number between 0 and 1. var x:UInt32 = (arc4random() / 0xFFFFFFFF) How does the division by 0xFFFFFFFF cause the number to be between 0 - 1? 回答1: As you've stated, arc4random returns an unsigned integer up to (2^32)-1 0xFFFFFFFF is equal to (2^32)-1, which is the largest possible value of arc4random() . So the arithmetic expression (arc4random() / 0xFFFFFFFF) gives you a ratio that

issue while changing the CurrentPage of UIPageControl which is Inside a TableViewCell

末鹿安然 提交于 2019-12-12 10:26:12
问题 am trying to create a Carousel inside tableViewCell and am almost there but am having difficulty while implementing the UIPageControl in my TableView so that when CollectionViewCell's (which is inside tableViewCell) Item got changed i can show it on UIPageControl, i tried the below solution and encountered a strange behaviour (maybe its strange for only me ) , when the View Loads and i change my item (which is in collectionViewCell) the PageControl's currentPage is not changing but after

How to pass data to a UIViewController from a UITableViewRowAction in Swift?

走远了吗. 提交于 2019-12-12 10:24:27
问题 I'm new to iOS programming, and I've been searching for how to do this, but can't seem to find what I'm looking for. I thought this would be a fairly easy task, and I'm sure it is if someone can enlighten me. When you swipe left on a table view I have some custom actions that can be performed. One of those actions is a simple "Edit" of the item selected. All I want to do is display another view controller but pass some data to that view controller like how it's normally done in

The user credentials are need to obtain access token. Please call the non-silent acquireTokenWithResource methods. ADALiOS issue

╄→гoц情女王★ 提交于 2019-12-12 10:23:24
问题 In my swift project, I am using convergence dev branch source code. I have added ADALiOS files manually in my project. Currently retrieving access token from refresh token is a problem. Till last week my project was working all fine but as I opened my project on Mondat i.e. 20th March, 2016, I don't know how and why my app is not able to save access token in local cache. So whenever I tried to get access token silently it is unable to retrieve it from local cache. For every call I am getting

AVPlayer can't resume after paused + some waiting

烂漫一生 提交于 2019-12-12 09:38:52
问题 After .pause() if I call .play() ok it continues but if I wait 30-60 sec after .pause() and try to .play() it sometimes fail to play, AVPlayerStatus.Failed returns false AVPlayerStatus.ReadyToPlay returns true I should re-initialize player with url to make it work. Now I want to do that, if player can be played, I want to just call .play() but if not, I want to re-initialize it, my question is how to detect if player is playable? By the way it is a radio link with .pls extension 回答1: Indeed

regiondidchange called several times on app load swift

好久不见. 提交于 2019-12-12 09:26:49
问题 I have a map that when i pan away or type in a location and navigate to it that I want a simple print function to run. I have this accomplished, however, when i first load the app it calls that print function several times until it is finished zooming in. Is there a way to NOT count the initial on app load region change? 回答1: answer finally found herehttp://ask.ttwait.com/que/5556977 private var mapChangedFromUserInteraction = false private func mapViewRegionDidChangeFromUserInteraction() ->

Swift UIView with multiply effect

柔情痞子 提交于 2019-12-12 09:16:42
问题 What I've been trying to achieve for a couple of hours is something like the following: I would like to have a UIImage in the background and then preferably a UIView with a background color of red with some kind of multiply effect (the red area). Is this possible? I've seen a few extensions for UIImage that tints them, but that would only work if I wanted my WHOLE image to have a red multiply color effect. Thanks 回答1: You could just add a red UIView to the top of your UIImageView . Adjust the

swift ios keyboard extension - long press / press and hold

夙愿已清 提交于 2019-12-12 09:14:14
问题 I need to know how to add long press (press and hold) function to ios custom keyboard extension so that i con show multiple keys to chose one from. expected design my project structure current code for keypress action - code can add the title of the button pressed as a new text into any proxy text field. @IBAction func keypress(sender: UIButton!){ let typedCharacter = sender.titleLabel?.text let proxy = textDocumentProxy as UITextDocumentProxy proxy.insertText(typedCharacter!) } func