Odd Property Declaration Syntax Containing Angular Brackets <>

Odd property declaration syntax containing angular brackets

It is a new addition to Objective-C, called Lightweight Generics. It was introduced in iOS9 / OS X 10.11 in order to enhance interoperability between Swift and Objective-C. As the documentation says:

Objective-C declarations of NSArray, NSSet and NSDictionary types
using lightweight generic parameterization are imported by Swift with
information about the type of their contents preserved.

For example, consider the following Objective-C property declarations:

@property NSArray<NSDate *>* dates; 
@property NSSet<NSString *>* words;
@property NSDictionary<KeyType: NSURL *, NSData *>* cachedData;

Here’s how Swift imports them:

var dates: [NSDate]
var words: Set<String>
var cachedData: [NSURL: NSData]

What does (NSDictionaryNSString *,id * __nonnull) mean?

It is the syntax of Objective C light weight generics. This feature is mainly included for fixing Objective C - Swift interoperability issues.

NSDictionary<NSString *,id> means, the dictionary keys should be of type NSString and it's value can be any type of object (id).

For Example:
If you want to declare a dictionary that will hold NSString values only, you can declare it like:

NSDictionary<NSString *,NSString *> *stringDictionary;

However in Objective C, you can set any-type of values to this dictionary, there will be no errors. But if you are using the same stringDictionary object from a swift class, you can only set a string value to this dictionary, otherwise it'll throw an error.

Please check this article for more details.

What’s the difference between “{}” and “[]” while declaring a JavaScript array?

Nobody seems to be explaining the difference between an array and an object.

[] is declaring an array.

{} is declaring an object.

An array has all the features of an object with additional features (you can think of an array like a sub-class of an object) where additional methods and capabilities are added in the Array sub-class. In fact, typeof [] === "object" to further show you that an array is an object.

The additional features consist of a magic .length property that keeps track of the number of items in the array and a whole slew of methods for operating on the array such as .push(), .pop(), .slice(), .splice(), etc... You can see a list of array methods here.

An object gives you the ability to associate a property name with a value as in:

var x = {};
x.foo = 3;
x["whatever"] = 10;
console.log(x.foo); // shows 3
console.log(x.whatever); // shows 10

Object properties can be accessed either via the x.foo syntax or via the array-like syntax x["foo"]. The advantage of the latter syntax is that you can use a variable as the property name like x[myvar] and using the latter syntax, you can use property names that contain characters that Javascript won't allow in the x.foo syntax.

A property name can be any string value.


An array is an object so it has all the same capabilities of an object plus a bunch of additional features for managing an ordered, sequential list of numbered indexes starting from 0 and going up to some length. Arrays are typically used for an ordered list of items that are accessed by numerical index. And, because the array is ordered, there are lots of useful features to manage the order of the list .sort() or to add or remove things from the list.

Why am I getting an error that says Property assignment expected when I'm not even using TypeScript?

In component screen jsx uses return statment in parantheses rather than curly braces {} .

So just replace this :

const ComponentsScreen = () => {
return (
<View>
<Text style={styles.testStyle}>This is the components screen</Text>
</View>
);
};

Hope it helps. feel free for doubts

When to use square brackets [ ] in directives @Inputs and when not?

When you use [] to bind to an @Input(), it's basically a template expression.

The same way displaying {{abc}} wouldn't display anything (unless you actually had a variable called abc).

If you have a string @Input(), and you want to bind it to a constant string, you could bind it like this: [myText]=" 'some text' ", or in short, like a normal HTML attribute: myText="some text".

The reason [myEnabled]="true" worked is because true is a valid template expression which of course evaluates to the boolean true.

What do {curly braces} around javascript variable name mean

This is what's known as a destructuring assignment, and it's a new feature of JavaScript 1.7 (and ECMAScript 6) (Currently, only available as part of the Firefox JavaScript engine.) Roughly, it would translate into this:

var ActionButton = require("sdk/ui/button/action").ActionButton;

It seems silly in this example, as there's only one item being assigned. However, you'd be able to use this pattern to assign multiple variables at once:

{x, y} = foo;

Is the equivalent to:

x = foo.x;
y = foo.y;

This can also be used for arrays. For example, you could easily swap two values without using a temporary variable:

var a = 1;
var b = 3;

[a, b] = [b, a];

Browser support can be tracked using kangax' ES6 compatibility table.

What is the purpose of double curly braces in React's JSX syntax?

It's just an object literal inlined in the prop value. It's the same as

var obj = {__html: rawMarkup};

<span dangerouslySetInnerHTML={obj} />

NSSet with what looks like a protocol (NSSetNSObject * *name)

In Xcode 7, Apple has added 'Lightweight Generics' to Objective C.

They will generate compiler warnings if there is a type mismatch.

Objective-C declarations of NSArray, NSSet and NSDictionary types
using lightweight generic parameterization are imported by Swift with
information about the type of their contents preserved.

https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-CAPIs.html#//apple_ref/doc/uid/TP40014216-CH4-ID35

Odd Interface Syntax

It is called an indexer and allows you to do instance[1]; when getting an element from your object. You can have a look at this answer on implementing IList as a reference

Meaning of square brackets [] in MS-SQL table designer?

The square brackets [] are used to delimit identifiers. This is necessary if the column name is a reserved keyword or contains special characters such as a space or hyphen.

Some users also like to use square brackets even when they are not necessary.

From MSDN:

Delimited identifiers

Are enclosed in double quotation marks (") or brackets ([ ]). Identifiers that comply with the rules for the format of identifiers may or may not be delimited.

SELECT *
FROM [TableX] --Delimiter is optional.
WHERE [KeyCol] = 124 --Delimiter is optional.

Identifiers that do not comply with all of the rules for identifiers must be delimited in a Transact-SQL statement.

SELECT *
FROM [My Table] --Identifier contains a space and uses a reserved keyword.
WHERE [order] = 10 --Identifier is a reserved keyword.


Related Topics



Leave a reply



Submit