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

Where is the variable “code” in SKError defined?

I am seeing examples of code using SKError “code” property or variable. I cannot seem to define any definition for this property. How is xcode / Swift able to access this property? I am using SwiftyStoreKit with this issue. Thanks Tried looking in the documentation for SKError, nothing there. Tried debugging in xcode, live, cannot … Read more

Declaration is only valid at file scope (extension)

The error message is quite clear. You cannot declare an extension inside of anything – inside a class declaration, inside a struct declaration, etc. It must be outside of everything, at the top level of the containing file. There must be no curly braces around it. You have not shown the context in which you are declaring this extension, but clearly there are curly … Read more

UITableView example for Swift

The example below is an adaptation and simplification of a longer post from We ❤ Swift. This is what it will look like: Create a New Project It can be just the usual Single View Application. Add the Code Replace the ViewController.swift code with the following: Read the in-code comments to see what is happening. The highlights are The … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)