We want to implement a check box[Type : true/false] in an DocumemtType in Umbraco.
Our current Project necessity is:
an check box which will decide whether an image should be an link or popup
The code goes this way ...
var child= #Model;
if(child.GetProperty("popUp").Value.ToString() == "1")
{
// true means image will act as popup
}
else
{
// false means image will act as link
}
But the problem is an error is occurred "Cannot perform runtime binding on a null reference"
I have also tried code like ,
if (child.GetProperty("popup").Value.Equals("1"))
{
}
or
if (child.GetProperty("popup").Value.ToString().Equals("1"))
{
}
but still not able to get it. All suggestions are welcomed .
node.GetProperty("popUp") is the way to go. If your control value is actually string, then your check logic would look like
if (node.GetProperty<string>("popUp") == "1"){}
Effectively generic GetProperty is what your code does, but it handles the null case, returning default(string).
(I have never used the dynamic thing, in case something will go wrong there, do the typed var node = new Node(id);)
Since you recently added the property to the document type, unless each node of that type has been published, the property will return null. You'll need to check if the property is null first then check if its true.
var popUp = child.GetProperty("popUp");
if (popUp != null && popUp.Value.Equals("1"))
{
// popup...
}
else
{
// link...
}
Used the below code and it worked fine for me
var child= #Model;
if(#child.popUp)
{
// true means image will act as popup
}
else
{
// false means image will act as link
}
Use this:
var child= #Model;
if(child.GetPropertyValue<bool>("popUp", false))
{
// true means image will act as popup
}
else
{
// false means image will act as link
}
Related
The SKCameraNode has two methods to it for checking node visibility inside it's viewport. (.containsNode() and .containedNodeSet())
The first return a bool, which is what I'm looking for. Checking for one node object works fine.
if myCamera.containsNode(mySpriteNode) == false {}
But I want to check wether it contains nodes of a class.
if myCamera.containsNode(MyClass()) == false {}
Since it doesn't work I wonder how this would be done.
Thank you.
You need to look at the other method you mentioned containedNodeSet(). This will return Set<SKNode> which you can then inspect as you wish, for example:
for node in cameraNode.containedNodeSet() {
if let interestingNode = node as? InterestingClass {
// Do something useful here
}
}
I have a site where you can look for print shops on a map and filter what services they offer. Example is here: www.pigments.io
Each print shop has some properties stored in an object.
marker: {
processes: {
'digital': false,
'offset': false,
'silk': true,
'letterpress': false,
'engraving': false
},
finishings: {
'diecutting': true,
'lasercut': false,
'perforation': false,
'msg': false,
'softtouch': false,
},
products: {
'apparel': true,
'largeformat': false
}
}
The checkboxes return an object with the same structure, if the checkbox is checked the value is set to true. Now let's say if I want to only show silk screen shops if only silk screen has been checked under processes I could do something like this:
((marker.processes.silk == true && marker.processes.silk == formData.processes.silk) ||
The shop (marker) needs to be set to true with it's silk property & if the checkbox is checked it returns true. I'm using polymer, it filters over each marker object and evaluates the statement above. If it's true, it shows the marker. (I just realized I could have just done this:
((marker.processes.silk == true && formData.processes.silk == true))
Now of course I could do something like this.
((marker.processes.silk == true && formData.processes.silk == true) || (marker.processes.digital == true && formData.processes.digital== true))
and so on. That'll get ugly but it would theoretically work. But now if I introduce another field to be compared, say the finishings, I'm just getting completely lost here. Basically let's say I want to show only silk screen shops. Works as the code above. Now I only want to show the silk screen shops that do diecutting. I know how I could seperately look for only silk shops, or only diecutting shops. But now if I add those two, if diecutting is selected, this needs to exclude from the already filtered silk shops.
My brain is mushy, please help x_x. I've been trying to come up with the solution for this for over an hour, thoughts revolving in circles. I'm not even sure if this can be done with basic comparison operators anymore?
Also, I realize this approach is really ugly and inefficient.
/edit1:
I've just realized I should check underscore. Essentially if I'm not mistaken I just need to check if the print shop object's true values are the same as the checkbox object's values, right?
/edit2:
I think I need to get all the true properties from the marker object and compare them with the corresponding properties in the checkbox. If they are all true/identical, then the marker should be shown, right?
/edit3:
I nearly have it (I think if I was correct with assumption from edit2).
var markerProcessKeys = lodash.keys(lodash.pick(marker.processes, lodash.identity));
var markerProcess = lodash.pick(marker.processes, lodash.identity);
// doesn't work
var filterProcess = lodash.pick(formData.processes, markerProcessKeys);
//var filterProcess = lodash.pick(formData.processes, 'digital','offset');
// This one works, manually selecting only the true ones.
//So what's left to do is get the key names of the true ones and then compare
//I don't have it working yet though... I need to do the manual one automatically with lodash. Suggestions?
// this won't work
var = lodash.pick(markerProcess, filterProcess);
console.log(lodash.isMatch(t1, t2));
/edit4:
Nope, that's the wrong approach :/
Start by building a function that will tell you if a given shop matches a set of requirements. Assuming you requirements object looks like
{
processes: {
'digital': true
},
finishings: {
'diecutting': true
}
}
your function could be written as nested _.every calls :
function matches(requirements, shop) {
return _.every(requirements, function(properties, cat) {
return _.every(properties, function(val, key) {
// (!val) is there to ignore properties set to false
return (!val) || shop.marker[cat][key];
});
});
}
You would then use _.filter to extract the desired shops:
var validshops = _.filter(shops, _.partial(matches, requirements));
And a demo http://jsfiddle.net/nikoshr/9eq6o96L/
I have a feeling there is more than one problem with this code, but my first issue is that my delegate returns nil and I do not know why. First, is my delegate:
import UIKit
//delegate to move information to next screen
protocol userEnteredDataDelegate {
func userDidEnterInformation(info:NSArray)
}
Next, I have a var defined for the delegate and I believe the ? makes it an optional variable? This is defined inside the class
var dataPassDelegate:userEnteredDataDelegate? = nil
Now, after my user has entered information into the fields in the view, I want to add those field values to an array and then pass that array on to the next view where it will be added to. I have pieced this code together from some YouTube examples but I think I am missing a needed part. When do I assign some kind of value to the dataPassDelegate var so it is not nil when the if statement comes? Do I even need that if statement?
if blankData != 1 {
//add code to pass data to next veiw controller
enteredDataArray = [enterDate.text, enterSeason.text, enterSport.text, enterDispTo.text]
//println(enteredDataArray)
self.appIsWorking ()
if (dataPassDelegate != nil) {
let information: NSArray = enteredDataArray
println(information)
dataPassDelegate!.userDidEnterInformation(information)
self.navigationController?.popViewControllerAnimated(true)
} else {
println ("dataPassDelegate = nil")
}
//performSegueWithIdentifier("goToDispenseScreenTwo", sender: self)
activityIndicator.stopAnimating()
UIApplication.sharedApplication().endIgnoringInteractionEvents()
}
blankData = 0
}
Your help is appreciated.
A delegate is a pointer to another object that conforms to a particular protocol. Often you use delegates to refine the behavior of your class, or to send back status information o the results of an async network request
When you set your dataPassDelegate delegate is up to you.
What is the object that has the dataPassDelegate property? What object will be serving as the delegate?
You need to create 2 objects (the object that will be serving as the delegate, and the object that has the dataPassDelegate property) and link them up.
We can't tell you when to do that because we don't know what you're trying to do or where these objects will be used.
I am using AWS to host images for my iOS app. Right now I am trying to list all the objects in an S3 bucket.
Here is my code:
var description = ""
AWSS3.registerS3WithConfiguration(serviceConfig2, forKey: "s3")
AWSS3.S3ForKey("s3").listObjects(objectList).continueWithBlock { (task: AWSTask!) -> AnyObject! in
if task.error != nil {
println(task.error)
}
if task.result != nil {
description = task.result!.description
println(description)
}
return nil
}
println(description == "")
The output is true followed by the correct contents of task.result!.description. In other words, the println outside of the continueWithBlock is printing first and description has not been updated at that time.
How am I supposed to do things with description outside of the continueWithBlock?
You can assign a value that you need to another variable inside the scope of your class or function, then you can call didSet on the variable and carry out another function if you need to, like this:
var someVariableInScopeOfWhereItsNeeded = "abc" {
didSet {
self.maybeSomeOtherFunctionNow
}
}
You asked:
How am I supposed to do things with description outside of the
continueWithBlock
Short answer: You're not.
The whole point of an async method is that it continues immediately, before the time-consuming task has even begun processing. You put the code that depends on the results inside your block. See my answer on this thread for a detailed explanation, including an example project:
Why does Microsoft Azure (or Swift in general) fail to update a variable to return after a table query?
(Don't be fooled by the fact that it mentions MS Azure. It actually has nothing to do with Azure.)
#thefredelement 's solution of using a didSet method on the variable that gets set would work too.
I'm trying to detect whether or not a user's input ends with a blank space, and if it does, to remove that space. I'm using the .hasSuffix() method to see if the space exists, and it should return a boolean variable that I can test for and determine the proper course of action. However, when I check whether the value is true or false, the app crashes. Any thoughts on why that might be? Here's the code:
var userGuess = userGuessField.text.lowercaseString
var guessEndsWithSpace: Bool = userGuess.hasSuffix(" ")
// The above will return true if the string ends with a space, so when this happens, remove the space and then check their guess
if (guessEndsWithSpace == true) {
println("Guess ends with a space")
// checkAnswer(userGuess)
} else {
println("Guess does not end with a space")
// Otherwise, just check their guess
// checkAnswer(userGuess)