strong-typing

Are there strongly-typed collections in Objective-C?

 ̄綄美尐妖づ 提交于 2019-11-26 15:57:54
I'm new to Mac/iPhone programming and Objective-C. In C# and Java we have "generics", collection classes whose members can only be of the type declared. For example, in C# Dictionary<int, MyCustomObject> can only contain keys that are integers and values that are of type MyCustomObject. Does a similar mechanism exist in Objective-C? In Xcode 7, Apple has introduced 'Lightweight Generics' to Objective-C. In Objective-C, they will generate compiler warnings if there is a type mismatch. NSArray<NSString*>* arr = @[@"str"]; NSString* string = [arr objectAtIndex:0]; NSNumber* number = [arr

Is there anything like a generic list in Cocoa / Objective-C?

假装没事ソ 提交于 2019-11-26 15:56:22
问题 What I really like in C# are generic lists. A list that can contain only one type of objects. Is there something like a generic list in Cocoa/Objective-C? As far I only know NSArray who will take a pointer to any object. 回答1: Wanting this in a Cocoa app is often a sign of a weak design. NSArray is immutable, so it will not "take a pointer to any object" and presumably already contains the correct objects when handed to you. What I assume you're more worried about is an NSMutableArray where

Is C strongly typed?

橙三吉。 提交于 2019-11-26 15:45:27
To quote Wikipedia : Two commonly used languages that support many kinds of implicit conversion are C and C++, and it is sometimes claimed that these are weakly typed languages. However, others argue that these languages place enough restrictions on how operands of different types can be mixed, that the two should be regarded as strongly typed languages. Is there a more definitive answer? Norman Ramsey "Strongly typed" and "weakly typed" are terms that have no widely agreed-upon technical meaning. Terms that do have a well-defined meaning are Dynamically typed means that types are attached to

Enforce strong type checking in C (type strictness for typedefs)

时光毁灭记忆、已成空白 提交于 2019-11-26 12:25:43
问题 Is there a way to enforce explicit cast for typedefs of the same type? I\'ve to deal with utf8 and sometimes I get confused with the indices for the character count and the byte count. So it be nice to have some typedefs: typedef unsigned int char_idx_t; typedef unsigned int byte_idx_t; With the addition that you need an explicit cast between them: char_idx_t a = 0; byte_idx_t b; b = a; // compile warning b = (byte_idx_t) a; // ok I know that such a feature doesn\'t exist in C, but maybe you

Static/Dynamic vs Strong/Weak

混江龙づ霸主 提交于 2019-11-26 11:57:45
I see these terms bandied around all over the place in programming and I have a vague notion of what they mean. A search shows me that such things have been asked all over stack overflow in fact. As far as I'm aware Static/Dynamic typing in languages is subtly different to Strong/Weak typing but what that difference is eludes me. Different sources seem to use different meanings or even use the terms interchangeably. I can't find somewhere that talks about both and actually spells out the difference. What would be nice is if someone could please spell this out clearly here for me and the rest

What is the difference between a strongly typed language and a statically typed language?

放肆的年华 提交于 2019-11-26 10:56:45
Also, does one imply the other? What is the difference between a strongly typed language and a statically typed language? A statically typed language has a type system that is checked at compile time by the implementation (a compiler or interpreter). The type check rejects some programs, and programs that pass the check usually come with some guarantees; for example, the compiler guarantees not to use integer arithmetic instructions on floating-point numbers. There is no real agreement on what "strongly typed" means, although the most widely used definition in the professional literature is

Is there any way to enforce typing on NSArray, NSMutableArray, etc.?

狂风中的少年 提交于 2019-11-26 08:03:49
问题 Can I make a NSMutableArray instance where all the elements are of type SomeClass ? 回答1: You could make a category with an -addSomeClass: method to allow compile-time static type checking (so the compiler could let you know if you try to add an object it knows is a different class through that method), but there's no real way to enforce that an array only contains objects of a given class. In general, there doesn't seem to be a need for such a constraint in Objective-C. I don't think I've

Is C strongly typed?

陌路散爱 提交于 2019-11-26 04:36:19
问题 To quote Wikipedia: Two commonly used languages that support many kinds of implicit conversion are C and C++, and it is sometimes claimed that these are weakly typed languages. However, others argue that these languages place enough restrictions on how operands of different types can be mixed, that the two should be regarded as strongly typed languages. Is there a more definitive answer? 回答1: "Strongly typed" and "weakly typed" are terms that have no widely agreed-upon technical meaning.

Static/Dynamic vs Strong/Weak

两盒软妹~` 提交于 2019-11-26 02:25:52
问题 I see these terms bandied around all over the place in programming and I have a vague notion of what they mean. A search shows me that such things have been asked all over stack overflow in fact. As far as I\'m aware Static/Dynamic typing in languages is subtly different to Strong/Weak typing but what that difference is eludes me. Different sources seem to use different meanings or even use the terms interchangeably. I can\'t find somewhere that talks about both and actually spells out the

Is Python strongly typed?

跟風遠走 提交于 2019-11-26 01:36:49
问题 I\'ve come across links that say Python is a strongly typed language. However, I thought in strongly typed languages you couldn\'t do this: bob = 1 bob = \"bob\" I thought a strongly typed language didn\'t accept type-changing at run-time. Maybe I\'ve got a wrong (or too simplistic) definition of strong/weak types. So, is Python a strongly or weakly typed language? 回答1: Python is strongly, dynamically typed. Strong typing means that the type of a value doesn't change in unexpected ways. A