change background color of all view controllers if all classes are called (swift4)
When the user visits all three view controllers in no particular order. I want all of the view controllers in this program to turn green. But only if all three classes are visited. I don't know if this is a coredata or userdefulat thing.
import UIKit
class oneV: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
class twoV: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
class threeV: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
core-data global-variables swift4 background-color userdefaults
add a comment |
When the user visits all three view controllers in no particular order. I want all of the view controllers in this program to turn green. But only if all three classes are visited. I don't know if this is a coredata or userdefulat thing.
import UIKit
class oneV: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
class twoV: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
class threeV: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
core-data global-variables swift4 background-color userdefaults
you want to flip the color right away ?
– 7bebMrto
Nov 22 '18 at 11:47
add a comment |
When the user visits all three view controllers in no particular order. I want all of the view controllers in this program to turn green. But only if all three classes are visited. I don't know if this is a coredata or userdefulat thing.
import UIKit
class oneV: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
class twoV: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
class threeV: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
core-data global-variables swift4 background-color userdefaults
When the user visits all three view controllers in no particular order. I want all of the view controllers in this program to turn green. But only if all three classes are visited. I don't know if this is a coredata or userdefulat thing.
import UIKit
class oneV: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
class twoV: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
class threeV: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
core-data global-variables swift4 background-color userdefaults
core-data global-variables swift4 background-color userdefaults
edited Nov 22 '18 at 5:05
hardik parmar
669413
669413
asked Nov 22 '18 at 4:53
Sam BurnsSam Burns
44412
44412
you want to flip the color right away ?
– 7bebMrto
Nov 22 '18 at 11:47
add a comment |
you want to flip the color right away ?
– 7bebMrto
Nov 22 '18 at 11:47
you want to flip the color right away ?
– 7bebMrto
Nov 22 '18 at 11:47
you want to flip the color right away ?
– 7bebMrto
Nov 22 '18 at 11:47
add a comment |
1 Answer
1
active
oldest
votes
UserDefaults Will be great for this, saving a flag for each UIViewController
in its viewDidLoad
function.
Then adding up those three flags into one, and check it in viewWillAppear
in each UIViewController
.
Check this Code Below.
// First create this extension to check on each value
public extension UIViewController {
func isAllVistied() -> Bool {
let a = UserDefaults.standard.bool(forKey: "VC1") // Key used to save inside the viewController
let b = UserDefaults.standard.bool(forKey: "VC2")
let c = UserDefaults.standard.bool(forKey: "VC3")
if a && b && c {
return true
} else {
return false
}
}
}
Usage: In each UIViewController
use this code:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
UserDefaults.standard.set(true, forKey: "VC1") //Key changes based on the current viewController used in example (VC1, VC2, VC3)
}
override func viewWillAppear(_ animated: Bool) {
if self.isAllVistied() {
view.backgroundColor = .green
}
}
}
This works well. I would like to know how the first time all of the classes are triggered it goes to green but anything equal to or greater than 2 it goes to red. So for the first hit green then once they are all called again red? Thanks again for your help?
– Sam Burns
Nov 23 '18 at 0:54
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424103%2fchange-background-color-of-all-view-controllers-if-all-classes-are-called-swift%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
UserDefaults Will be great for this, saving a flag for each UIViewController
in its viewDidLoad
function.
Then adding up those three flags into one, and check it in viewWillAppear
in each UIViewController
.
Check this Code Below.
// First create this extension to check on each value
public extension UIViewController {
func isAllVistied() -> Bool {
let a = UserDefaults.standard.bool(forKey: "VC1") // Key used to save inside the viewController
let b = UserDefaults.standard.bool(forKey: "VC2")
let c = UserDefaults.standard.bool(forKey: "VC3")
if a && b && c {
return true
} else {
return false
}
}
}
Usage: In each UIViewController
use this code:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
UserDefaults.standard.set(true, forKey: "VC1") //Key changes based on the current viewController used in example (VC1, VC2, VC3)
}
override func viewWillAppear(_ animated: Bool) {
if self.isAllVistied() {
view.backgroundColor = .green
}
}
}
This works well. I would like to know how the first time all of the classes are triggered it goes to green but anything equal to or greater than 2 it goes to red. So for the first hit green then once they are all called again red? Thanks again for your help?
– Sam Burns
Nov 23 '18 at 0:54
add a comment |
UserDefaults Will be great for this, saving a flag for each UIViewController
in its viewDidLoad
function.
Then adding up those three flags into one, and check it in viewWillAppear
in each UIViewController
.
Check this Code Below.
// First create this extension to check on each value
public extension UIViewController {
func isAllVistied() -> Bool {
let a = UserDefaults.standard.bool(forKey: "VC1") // Key used to save inside the viewController
let b = UserDefaults.standard.bool(forKey: "VC2")
let c = UserDefaults.standard.bool(forKey: "VC3")
if a && b && c {
return true
} else {
return false
}
}
}
Usage: In each UIViewController
use this code:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
UserDefaults.standard.set(true, forKey: "VC1") //Key changes based on the current viewController used in example (VC1, VC2, VC3)
}
override func viewWillAppear(_ animated: Bool) {
if self.isAllVistied() {
view.backgroundColor = .green
}
}
}
This works well. I would like to know how the first time all of the classes are triggered it goes to green but anything equal to or greater than 2 it goes to red. So for the first hit green then once they are all called again red? Thanks again for your help?
– Sam Burns
Nov 23 '18 at 0:54
add a comment |
UserDefaults Will be great for this, saving a flag for each UIViewController
in its viewDidLoad
function.
Then adding up those three flags into one, and check it in viewWillAppear
in each UIViewController
.
Check this Code Below.
// First create this extension to check on each value
public extension UIViewController {
func isAllVistied() -> Bool {
let a = UserDefaults.standard.bool(forKey: "VC1") // Key used to save inside the viewController
let b = UserDefaults.standard.bool(forKey: "VC2")
let c = UserDefaults.standard.bool(forKey: "VC3")
if a && b && c {
return true
} else {
return false
}
}
}
Usage: In each UIViewController
use this code:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
UserDefaults.standard.set(true, forKey: "VC1") //Key changes based on the current viewController used in example (VC1, VC2, VC3)
}
override func viewWillAppear(_ animated: Bool) {
if self.isAllVistied() {
view.backgroundColor = .green
}
}
}
UserDefaults Will be great for this, saving a flag for each UIViewController
in its viewDidLoad
function.
Then adding up those three flags into one, and check it in viewWillAppear
in each UIViewController
.
Check this Code Below.
// First create this extension to check on each value
public extension UIViewController {
func isAllVistied() -> Bool {
let a = UserDefaults.standard.bool(forKey: "VC1") // Key used to save inside the viewController
let b = UserDefaults.standard.bool(forKey: "VC2")
let c = UserDefaults.standard.bool(forKey: "VC3")
if a && b && c {
return true
} else {
return false
}
}
}
Usage: In each UIViewController
use this code:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
UserDefaults.standard.set(true, forKey: "VC1") //Key changes based on the current viewController used in example (VC1, VC2, VC3)
}
override func viewWillAppear(_ animated: Bool) {
if self.isAllVistied() {
view.backgroundColor = .green
}
}
}
answered Nov 22 '18 at 11:53
7bebMrto7bebMrto
1,5531418
1,5531418
This works well. I would like to know how the first time all of the classes are triggered it goes to green but anything equal to or greater than 2 it goes to red. So for the first hit green then once they are all called again red? Thanks again for your help?
– Sam Burns
Nov 23 '18 at 0:54
add a comment |
This works well. I would like to know how the first time all of the classes are triggered it goes to green but anything equal to or greater than 2 it goes to red. So for the first hit green then once they are all called again red? Thanks again for your help?
– Sam Burns
Nov 23 '18 at 0:54
This works well. I would like to know how the first time all of the classes are triggered it goes to green but anything equal to or greater than 2 it goes to red. So for the first hit green then once they are all called again red? Thanks again for your help?
– Sam Burns
Nov 23 '18 at 0:54
This works well. I would like to know how the first time all of the classes are triggered it goes to green but anything equal to or greater than 2 it goes to red. So for the first hit green then once they are all called again red? Thanks again for your help?
– Sam Burns
Nov 23 '18 at 0:54
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53424103%2fchange-background-color-of-all-view-controllers-if-all-classes-are-called-swift%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
you want to flip the color right away ?
– 7bebMrto
Nov 22 '18 at 11:47