Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
import UIKit
import Foundation
open class podview: UIView {
open var strk = UIColor.black
.
.
}
I have to change the value of "strk" from another view controller. Is it possible to do it.
YES, You can do it. There are two way to do this.
Local Notification (NSNotification)
NSNotificationCenter addObserver in Swift
Delegatation
Examples of Delegates in Swift
If you want to Change View controller B Value from View controller A then you can directly access to it.
For EX ViewcontrollerB.yourVariable = Assign value - From View Controller A
Please review and understand both concepts.
Happy Coding..:)
I'm just providing you trick.
Yes you can change it. First you need to import model of the pod.
then you need to create object of the podview and then you will be able to access strk like
objectOfPodView.strk
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
Is #MainActor just a syntactic sugar for DispatchQueue.main.async or else is there any other use to it?
If we take a look at the declarations for both UILabel and UIViewController, we can see that they’ve both been annotated with the new #MainActor attribute:
#MainActor class UILabel: UIView
#MainActor class UIViewController: UIResponder
What that means is that, when using Swift’s new concurrency system, all properties and methods on those classes (and any of their subclasses) will automatically be set, called, and accessed on the main queue. All those calls will automatically be routed through the system-provided MainActor, which always performs all of its work on the main thread — completely eliminating the need for us to manually call DispatchQueue.main.async.
Source: https://www.swiftbysundell.com/articles/the-main-actor-attribute/
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I put this function in a class and I don't understand this error.
My Code:
Can help me?
Thanks.
You're assigning the delegation of your XMLParser to your class which does not conform to the protocol.
Your class Login should implement the XMLParserDelegate protocol :
extension Login: XMLParserDelegate{
}
I suggest you to read this :
https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Protocols.html#//apple_ref/doc/uid/TP40014097-CH25-ID276
And to google around "swift delegation", there are a lot of good example that explain this concept
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have an Objective-C project, and need hints on how to call a ViewController which is in Swift from another controller in Objective-C?
Apparently it's quite easy.
You have to first make sure you're prepending your class declaration with #objc so that it's available to your Objective-C ones.
For example:
import Foundation
// Belongs to target 'TestProject'
#objc class SwiftController: UIViewController {
//... truncated
}
Now you simply have to import the name of your target (that the swift controller belongs to), appended with '-Swift.h'—exposing its interface—like so:
#import "TestProject-Swift.h"
Create a new file "YourAppName-Bridging-Header.h" and in this file you have to import "Your objective-C view controller.h"
Go to Build setting and search for bridging header and link with your birdging-header path.
Now you are able to write code in swift as usual.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a method called someMethod in controller A and I want to call in controller B.
How would I do this?
Keep a pointer to your controllerA in your controllerB and do:
[self.controllerA performselector:#selector(someMethod) withObject:nil];
or just:
[self.controllerA someMethod];
But I agree with Shawn's comment, that this is not the best design - if you have functionality that needs to be shared between both view controllers, it might be better to move that functionality into a different class - your app delegate, maybe?
There are multiple ways of doing this. One is to create a class method. You create it like this:
+ (void) someMethod {
//Do stuff
}
Call it like this:
[ControllerB someMethod];
Another way to do it is to create a new instance of controller B as Jeff Loughlin said, and call the method on it:
ControllerB *cb = [[ControllerB alloc] init];
[cb someOtherMethod];
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
When I create a new file in Xcode I can specify a subclass of my new class. But when it is already created, how can I know which subclass has it?
Thanks.
You see that in the class definition / .h file, for example:
#interface BCFrequencyPlot : NSView
BCFrequencyPlot is a subclass of NSView.
During compilation, you can type:
po [self class]
It will show you class of self. You can check class for any object currently in scope.