3 ms·
Mixing both adds complexity to the codebase, though. Might as well stick to Objective-C for legacy projects and Swift for new projects.
by charlesdm 11y ago
Mixing both adds complexity to the codebase, though. Might as well stick to Objective-C for legacy projects and Swift for new projects.
- melling 11y agoI think you're overstating the complexity. The real problem is once you see how visually noisy Objective C is compared to Swift, you'll get the urge to translate your ObjC code. NSString *s = @"Swift is the future"; UIViewController *vc = [[UIViewController alloc] init]; NSArray *names = @[@"John", @"Paul", @"George", @"Ringo"]; vs let s = "Swift is the future" let vc = UIViewController() let names = ["John", "Paul", "George", "Ringo"]
- xyzzy4 11y agoBut the "noise" also reduces ambiguity. For example, you can search the code and see s is a NSString in Objective C. You can't do this in Swift.
- maxdesiatov 11y agoYou can just alt-click on the variable in Xcode and see the inferred variable type instantly, no matter what the type is or where the variable is declared. No need to search. You can't do this in Objective-C.
- melling 11y agoCan't say that I see the value in that but you do have the option of adding types the old fashion way. let s = "Swift is the future" let s:String = "Swift is the future" It's just a matter of making a coding convention.
- supster 11y agoWell you can see that s is a string because of the assignment, and if you want you can also add type annotations like let s: String = "Swift is the future"