logo
down
shadow

Change class variables in function has no effect after exiting in Swift


Change class variables in function has no effect after exiting in Swift

Content Index :

Change class variables in function has no effect after exiting in Swift
Tag : ios , By : user142345
Date : December 05 2020, 12:22 PM

this will help I have one Data class with variable of NSDictionary type , The problem is that you are performing an asynchronous request:
appDelegate.uData!.login();
print(appDelegate.uData!.result["result"]);

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Change values of variables in class swift


Tag : class , By : Dave M
Date : March 29 2020, 07:55 AM
this will help I found the solution. You need to declare all fields and image view as lazy variables and work with them in init:
import Foundation
import Cocoa
import AppKit

class Game {

init(num : CGFloat, picName : String, gameName : String, description : String, windowHeight : CGFloat, sender : NSViewController) {
    self.number = num
    self.pictureName = picName
    self.name = gameName
    self.desc = description
    self.height = windowHeight
    imageView = NSImageView(frame: NSRect(x: 0, y: 0, width: 100, height: 100))
    nameField = NSTextField(frame: NSRect(x: 110, y: 60, width: 300, height: 30))
    descField = NSTextField(frame: NSRect(x: 110, y: 0, width: 300, height: 60))

    nameField.font = NSFont(name: "System", size: 15.0)
    nameField.stringValue = self.name
    nameField.alignment = NSTextAlignment(rawValue: 2)!
    nameField.selectable = false
    nameField.editable = false
    nameField.backgroundColor = sender.view.window?.backgroundColor
    nameField.bordered = false

    descField.selectable = false
    descField.editable = false
    descField.stringValue = desc
    descField.font = NSFont(name: "System", size: 11.0)
    descField.backgroundColor = NSColor.controlColor()
    descField.bordered = true
    descField.backgroundColor = sender.view.window?.backgroundColor

    imageView.image = NSImage(named: self.pictureName)!

    gameView = NSView(frame: NSRect(x: 0, y: /*height - (100 * num)*/ height - (120 * num), width: 600, height: 100))

    button = NSButton(frame: NSRect(x: 0, y: 0, width: 600, height: 100))
    button.tag = Int(number)
    button.action = nil

    var gesture = NSClickGestureRecognizer(target: sender, action: Selector("buttonPressed:"))
    gesture.numberOfClicksRequired = 1
    gesture.buttonMask = 0x1
    button.addGestureRecognizer(gesture)

    button.bezelStyle = NSBezelStyle(rawValue: 6)!
    button.transparent = true

    gameView.addSubview(nameField)
    gameView.addSubview(imageView)
    gameView.addSubview(descField)
    gameView.addSubview(button)

}

var number : CGFloat
var pictureName : String
var name : String
var desc : String
var height : CGFloat

lazy var button : NSButton = NSButton()
lazy var imageView : NSImageView = NSImageView()
lazy var nameField : NSTextField = NSTextField()
lazy var descField : NSTextField = NSTextField()
lazy var gameView : NSView = NSView()

}
var newGame = Game(num: number, picName: "Bomb2.png", gameName: "Bomber", description: "Just a simple application", windowHeight: size!.height, sender: self)
self.view.addSubview(newGame.gameView)

cannot change class variables while runtime swift


Tag : ios , By : Sharad
Date : March 29 2020, 07:55 AM
help you fix your problem That's an what I want to do. I want to change a class variable while the project is running and use that in player. For example, while the app is running when user plays a button the player will stop and change the URL and start again. How can I do it? , This, is not good, because you create a player with an invalid URL:
// NOT GOOD
class PlayerAv {
    var audioLink: String = ""
    var player: AVPlayer
    init()
    {
        player = AVPlayer(URL: NSURL(string: self.audioLink))
    }
}
let myPlayer = PlayerAv()
// GOOD
class PlayerAv {
    var audioLink: String?
    var player: AVPlayer
    init(link: String) {
        self.audioLink = link
        self.player = AVPlayer(URL: NSURL(string: link))
    }
}
var myPlayer = PlayerAv(link: "http://yourFirstURLhere")
myPlayer.player.play()
myPlayer.player.pause()
myPlayer.player.volume = 2
myPlayer = PlayerAv(link: "http://yourNewURLhere")
myPlayer.player.play()
println(myPlayer.audiolink!)

Issue with using variables inside a class function (Swift Playgrounds)


Tag : swift , By : Diego
Date : March 29 2020, 07:55 AM
I hope this helps . It does work. You can change the value of a in pressed. I added code to your pressed method, as follows:
import UIKit
import PlaygroundSupport

class Responder: NSObject {
    func pressed(sender: UIButton) {
        a = a+1
        print(a)
    }
}
var a: Int = 0

let responder = Responder()
let bt = UIButton(frame: CGRect(x: 0.0, y: 0.0, width: 200.0, height: 200.0))
bt.addTarget(responder, action: #selector(Responder.pressed), for: .touchUpInside)
PlaygroundPage.current.liveView = bt

iOS Swift - Call function for another class and see null variables


Tag : ios , By : browe
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further i have three classes, where i have a container, mainview and a left menu. , I think problem is in this code:
var viewController: ViewController = ViewController()
let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("ViewControllerIdentifier")

Appending to self has no effect after exiting class method


Tag : python-3.x , By : cameron
Date : March 29 2020, 07:55 AM
This might help you You are rebinding the name self to a new instance of Buffer then proceeding to invoke the append method on that new instance. Remember that self is just like any other name that can be rebound and when it is rebound it doesn't retain any special properties pointing back to the original object. The following line can be removed and your code should work as expected.
self = Buffer() # In case self had previous content.
Related Posts Related QUESTIONS :
  • Compiling Metal shaders from source on iOS 13 Simulator gives PCH error
  • conan error:I need to cross build packages for os:iOS with my Macos, but when the first package was done, it broke my cp
  • Update calendar 'start of week' from phones system calendar
  • Xcode is showing some warnings
  • How to remove the default Navigation Bar space in SwiftUI NavigiationView
  • Having trouble integrating multiple pickerviews in the same view
  • SCNNode not in SCNView hierarchy, still showing & getting touches & physics
  • How can I open my SwiftUI app and perform a function using NSUseractivity from within Siri Intent Extension?
  • NSCoding decodeObject always nil
  • Passing data in a segmented Controller?
  • Facing issue in Siri Integration with custom intents
  • ARKit3 Hardware Requirement Clarification
  • ARKit3 How to use TrueDepth camera for face tracking and face meshes of other people?
  • How to discriminate while decoding using Codable Protocol in Swift?
  • 'IPA processing failed' while distributing build in Xcode Beta
  • How to debug a crash which happened when come back from background
  • Synchronising old data with NSPersistentCloudKitContainer
  • iOS app opened from web app with url redirects to Appstore
  • How to change the color of seperator in tableView?
  • Is there a better way to watch for a key-value change?
  • How to make UIBezierPath to fill from the center
  • Why on Xcode 11, UICollectionViewCell changes size as soon as you scroll (I already set size in sizeForItem AtIndexPath:
  • How to scan non LE devices using Swift?
  • Unable to infer closure type in the current context in SwiftUI
  • What is the best way to write common code and use it entire project
  • UISegmentedControl inside UIStackView, segments text not centered - iOS 13
  • Swift & ObjC bridge - cannot find protocol declaration for "WKNavigationDelegate"
  • SwiftUI How to push to next screen when tapping on Button
  • 'NSApp' is unavailable in UIKit for Mac: How to embed Mac only framework in iOS app on macOS?
  • UserDefaults Binding with Toggle in SwiftUI
  • How to create a color with an alpha value using SwiftUI?
  • SwiftUI creates destination views before the user navigates to them
  • Streaming video from https with AVPlayer causes initial delay
  • Tap Action not working when Color is clear SwiftUI
  • SwiftUI NavigationButton: How to navigate to different destinations
  • Supported default light/dark mode colors for Color vs UIColor
  • XCUITest wait for a cell with a specific static text inside it
  • Not able to enable Development mode on iOS 13
  • How to hide the home indicator with SwiftUI?
  • How to write if condition with using label text (Int) values
  • Swift Cannot use instance member within property initializer
  • Issue while getting the frame of the keyboard
  • dynamicMemberLoookup ExpressibleByStringLiteral parameter swift
  • iOS Unity Firebase Messenger Xcode Compile Error: FIRDynamicLinks
  • Firebase Storage Image Cache not updating SWIFT
  • unhandled js exception: application main has not been registered expo TestFlight
  • App freezes on IOS when navigate to another screen - React Navigation
  • How to create haptic feedback for a Button in SwiftUI?
  • How can I achieve automatic scrolling in my text view when text comes down to the keyboard level in Swift?
  • how to get the location with the CLLocationManager every 10 secondes?
  • Calling completion handler of a function from Timer selector function Swift
  • How to make SwiftUI view fullscreen?
  • RAM, JSC, Views, UI and JS usage table appearing whenever I launch my react native app. How to remove this table?
  • Change status bar background color using UIStatusBarManager
  • Should we make tapGesture component an IBAction or IBOutlet to capture the tap event?
  • Iframe automatically goes full screen using Ionic 3.9.2 on iOS
  • How to calculate score out of 1000 given some seconds (In Double)
  • How to calculate time (minutes) between two dates in swift?
  • There was problem loading requested app.it looks like you may be using LAN URL
  • Swift circular corners doesn't work properly on different screen sizes
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com