“Unrecognized selector sent to instance” in swift

I have no idea what I am doing wrong. I am also quite new to programming so I am not very good at debugging. This was a test app so that I can see how swift ties in with app development. So far, I have got this: I am getting the error “Unrecognized selector sent … Read more

How to create a global variable?

From the official Swift programming guide: Global variables are variables that are defined outside of any function, method, closure, or type context. Global constants and variables are always computed lazily. You can define it in any file and can access it in current module anywhere. So you can define it somewhere in the file outside of any scope. … Read more

What are the supported Swift String format specifiers?

The format specifiers for String formatting in Swift are the same as those in Objective-C NSString format, itself identical to those for CFString format and are buried deep in the archives of Apple Documentation (same content for both pages, both originally from year 2002 or older): https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFStrings/formatSpecifiers.html https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html But this documentation page itself is incomplete, … Read more

Swift – How to convert String to Double

I’m trying to write a BMI program in swift language. And I got this problem: how to convert a String to a Double? In Objective-C, I can do like this: double myDouble = [myString doubleValue]; But how can I achieve this in Swift language?

Is Swift Pass By Value or Pass By Reference

Types of Things in Swift The rule is: Class instances are reference types (i.e. your reference to a class instance is effectively a pointer) Functions are reference types Everything else is a value type; “everything else” simply means instances of structs and instances of enums, because that’s all there is in Swift. Arrays and strings are struct instances, for example. You can pass … Read more

@selector() in Swift?

Swift itself doesn’t use selectors — several design patterns that in Objective-C make use of selectors work differently in Swift. (For example, use optional chaining on protocol types or is/as tests instead of respondsToSelector:, and use closures wherever you can instead of performSelector: for better type/memory safety.) But there are still a number of important ObjC-based APIs that use selectors, including timers … Read more