swift5

SwiftUI: How to persist @Published variable using UserDefaults?

此生再无相见时 提交于 2020-01-01 07:07:07
问题 I want a @Published variable to be persisted, so that it's the same every time when I relaunch my app. I want to use both the @UserDefault and @Published property wrappers on one variable. For example I need a ' @PublishedUserDefault var isLogedIn '. I have the following propertyWrapper import Foundation @propertyWrapper struct UserDefault<T> { let key: String let defaultValue: T init(_ key: String, defaultValue: T) { self.key = key self.defaultValue = defaultValue } var wrappedValue: T { get

Why are IBOutlets optionals after swift 5 migration

白昼怎懂夜的黑 提交于 2019-12-31 16:37:27
问题 After migrating the project to swift 5, I'm getting a lot of errors such as Expression implicitly coerced from 'UIButton?' to 'Any' I'm not sure what's causing this. One example where this is happening(there are a bunch) is when I'm setting the view.accessibilityElements. The array is supposed to contain : [Any]?... Any idea what's causing this? Here is an example: @IBOutlet weak var shareButton: UIButton! @IBOutlet weak var shareTitleLabel: UILabel! view.accessibilityElements = [shareButton,

Why are IBOutlets optionals after swift 5 migration

两盒软妹~` 提交于 2019-12-31 16:37:14
问题 After migrating the project to swift 5, I'm getting a lot of errors such as Expression implicitly coerced from 'UIButton?' to 'Any' I'm not sure what's causing this. One example where this is happening(there are a bunch) is when I'm setting the view.accessibilityElements. The array is supposed to contain : [Any]?... Any idea what's causing this? Here is an example: @IBOutlet weak var shareButton: UIButton! @IBOutlet weak var shareTitleLabel: UILabel! view.accessibilityElements = [shareButton,

Why are IBOutlets optionals after swift 5 migration

偶尔善良 提交于 2019-12-31 16:37:04
问题 After migrating the project to swift 5, I'm getting a lot of errors such as Expression implicitly coerced from 'UIButton?' to 'Any' I'm not sure what's causing this. One example where this is happening(there are a bunch) is when I'm setting the view.accessibilityElements. The array is supposed to contain : [Any]?... Any idea what's causing this? Here is an example: @IBOutlet weak var shareButton: UIButton! @IBOutlet weak var shareTitleLabel: UILabel! view.accessibilityElements = [shareButton,

TabbedView using SwiftUI in Xcode11Beta (11M336w)

独自空忆成欢 提交于 2019-12-24 19:14:17
问题 I am following along with the session from WWDC2019 here : https://developer.apple.com/videos/play/wwdc2019/216/ I have the following code working for creating a TabbedView using SwiftUI : //Section1 | ContentView (mine)--------------------------- import SwiftUI struct ContentView : View { var body: some View { NavigationView { TabbedView(selection: .constant(1)) { PlaceForm().tabItemLabel(Text("Tab1")).tag(1) FavoritesForm().tabItemLabel(Text("Tab2")).tag(2) } } } } #if DEBUG struct

Add image to ActionSheet and put it to right

自作多情 提交于 2019-12-24 19:08:15
问题 I want to put the image to the right in an ActionSheet as seen on the AppStore. I know how to add an image and change the titleText style but I am unable to figure out how to change the positions of these two. Third party libraries are not appreciated. Thanks! Screenshot - AppStore 回答1: Updated to swift 4.2 and added images. Go through below link for more info. How to customize UIAlertController with UITableView or is there any default control available like this UI in Pages app? import

How can I append Json values in sting arrays?

拟墨画扇 提交于 2019-12-24 07:34:28
问题 I am parsing Json with Alamofire and SwiftyJSON. I can see all json data from url. Everything is clear in my console but I need to append some values in string arrays. As you can see json values. I create 3 string arrays. I need to append to arrays teams, player names and trophies. I will list team and player name in tableview. I need help to append values in arrays // json values in console [ { "id" : 1, "team" : "Liverpool", "players" : [ { "id" : 2, "name" : "Alisson", "position" : "Goal

How to stream remote audio in iOS 13? (SwiftUI)

岁酱吖の 提交于 2019-12-20 05:26:16
问题 This code using AVPlayer works only on Playground import AVFoundation var player = AVPlayer() let playerItem = AVPlayerItem(url: URL(string: "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3")!) player = AVPlayer(playerItem: playerItem) player.play() When I tried to run it on my SwiftUI App on my physical device, using this code: Button(action:{ var player = AVPlayer() let playerItem = AVPlayerItem(url: URL(string: "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3")!

Filling an array concurrently

微笑、不失礼 提交于 2019-12-20 02:00:50
问题 I am stumbling upon an issue with concurrency and arrays in Swift 5. To reproduce the issue I have simplified my code to the following fragment: import Dispatch let group = DispatchGroup() let queue = DispatchQueue( label: "Concurrent threads", qos: .userInitiated, attributes: .concurrent ) let threadCount = 4 let size = 1_000 var pixels = [SIMD3<Float>]( repeating: .init(repeating: 0), count: threadCount*size ) for thread in 0..<threadCount { queue.async(group: group) { for number in thread

Writing Data to an OutputStream with Swift 5+

百般思念 提交于 2019-12-18 09:34:38
问题 This code used to be fine (in the sense that the compiler didn't complain): extension OutputStream { func write(_ data: Data) -> Int { return data.withUnsafeBytes { pointer in return self.write(pointer, maxLength: data.count) } } } Since Swift 5.0, this produces a warning: Warning: 'withUnsafeBytes' is deprecated: use withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R instead I tried using the proposed method but I can't seem to wrangle the UnsafeRawBufferPointer into