swift5

getting unresolved identifier 'self' in SwiftUI code trying to use Timer.scheduledTimer

和自甴很熟 提交于 2019-12-13 17:26:26
问题 In SwiftUI I'm noting to use a Timer that: Try 1 - This doesn't work as get "Use of unresolved identifier 'self'" var timer2: Timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { self.angle = self.angle + .degrees(1) } Try 2 - Works, but have to put in an "_ = self.timer" to start it later var timer: Timer { Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true) {_ in self.angle = self.angle + .degrees(1) } } // then after need to use " .onAppear(perform: {_ = self.timer}) "

Passing a class type by reference

自古美人都是妖i 提交于 2019-12-13 04:08:12
问题 So I want I my base tableView, upon which I've derived others, to centralize drag-n-drop operations. Each of these tableViews have a distinct array controller as its dataSource, with each item class conforming to pasteboard reading and writing protocols. But I'm stuck on its setup override func mouseDragged(with event: NSEvent) { let arrayController = self.dataSource as! NSArrayController let itemClass = arrayController.objectClass let objects = arrayController.arrangedObjects as! [itemClass]

How to change tab bar item text colour on focus in TVOS

允我心安 提交于 2019-12-13 00:53:20
问题 I have four item in tab bar. 1> Watch. (Black Colour) 2> On Demand. (Black Colour) 3> Search. (Black Colour) 4> Settings. (My Colour) How can i change the colour of item text in tab bar to match with its icon colour. (Right now Performance is selected in the tab bar) enter image description here How can I change the color of "1,2,3" text in tabbar to match with its icon color. (Right now Performance is selected in the tab bar) I tried to set TitleTextAttributes. UITabBarItem.appearance()

How to get index path on click of button from UITableView in Swift 5 [duplicate]

大憨熊 提交于 2019-12-11 19:46:23
问题 This question already has answers here : swift: how to get the indexpath.row when a button in a cell is tapped? (14 answers) Closed 3 months ago . In tableview, on the cells there are buttons in it, need to get the index of tableview means, which index cell's button is clicked. So, not able to implement it in swift 5. So far tried is but this give me wrong value. let position: CGPoint = sender.convert(CGPoint.zero, to: organizationsTableView) if let indexPath = organizationsTableView

AspectFit image inside an UIButton

て烟熏妆下的殇ゞ 提交于 2019-12-11 19:09:41
问题 I have an image looking like this But it should look like this : I added the line : cameraUIButton.imageView?.contentMode = .scaleAspectFit It doesn't works BUT if i click on the button it fit !! What append in swift when you click on the button that recalculate the fit of the image ? I already tried cameraUIButton.setNeedsDisplay() cameraUIButton.imageView?.setNeedsDisplay() cameraUIButton.imageView?.layoutIfNeeded() cameraUIButton.layoutIfNeeded() self.view.layoutIfNeeded() and all in

Limitation Of @State

末鹿安然 提交于 2019-12-11 07:45:58
问题 I saw in some article that @state has many limitations that we shouldn't use it with complex models and its preferable to use it with the simple property like string, bool, ... etc. and we should use it inside the view itself. I tried to make a struct model and mark it with @state in the contentview (ParentView) and pass this model to its child views by wrapping it with @binding it worked just fine, so i don't understand why we still need @objectbinding as we can pass the same value to these

Change tabBar height in Swift 5 for IOS 13

限于喜欢 提交于 2019-12-11 06:24:29
问题 I need to change the UITabBar height to 95. I can do that in the older version of iOS Swift. This is my code that work in the older version. override func viewWillLayoutSubviews() { super.viewWillLayoutSubviews() tabBar.frame.size.height = 95 tabBar.frame.origin.y = view.frame.height - 95 menuButton.frame.origin.y = self.view.bounds.height - tabBar.frame.size.height - 10 shadowBtn.frame.origin.y = self.view.bounds.height - tabBar.frame.size.height - 15 } 回答1: Try it in viewDidLayoutSubviews

Protocol methods in a class extension are not called under specific conditions

六月ゝ 毕业季﹏ 提交于 2019-12-11 06:24:27
问题 I encountered a weird behavior. The best way I can put it is … Not overridden protocol methods in a class extension are not called while the superclass already conforms to the protocol (via extension) . However this happens only while it's build with the release build configuration. class A: UIViewController {} extension A: UIScrollViewDelegate { func scrollViewDidScroll(_ scrollView: UIScrollView) { print("scrollViewDidScroll in superclass") } } class B: A { // A tableView (and its data

opening app using custom URL Scheme. First time scene(_:openURLContexts:) does not call in sceneDelegate

こ雲淡風輕ζ 提交于 2019-12-11 02:34:56
问题 In info.plist file I configured URL Identifier and URL Scheme successfully. Also I am able to open app using custom URL. The problem is when app launches first time the method func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) does not call. I have some dependent functionality based on above method. So when app launches first time I am not able to see anything in my app. Also I added code in method func scene(_ scene: UIScene, willConnectTo session:

iOS SwiftUI Searchbar and REST-API

Deadly 提交于 2019-12-10 00:03:01
问题 I'm experimenting with SwiftUI and would like to fetch an update from my REST API with a search string. However, I'm not sure how to bring the two components together now. I hope you have an idea. Here my Code: struct ContentView: View { @State private var searchTerm: String = "" @ObservedObject var gameData: GameListViewModel = GameListViewModel(searchString: ### SEARCH STRING ???? ###) var body: some View { NavigationView{ Group{ // Games werden geladen... if(self.gameData.isLoading) {