본문 바로가기

Programming/Swift

(68)
Swift - 조건문
Value and Reference Types Types in Swift fall into one of two categories: first, “value types”, where each instance keeps a unique copy of its data, usually defined as a struct, enum, or tuple. The second, “reference types”, where instances share a single copy of the data, and the type is usually defined as a class. In this post we explore the merits of value and reference types, and how to choose between them. What’s th..
Collection Types in Swift Swift provides three primary collection types, known as 1. arrays, 2. sets, and 3. dictionaries, for storing collections of values. 1. Arrays are ordered collections of values. 2. Sets are unordered collections of unique values. 3. Dictionaries are unordered collections of key-value associations. Array vs. Dictionary Array > 순서 기반으로 찾음 Dictionary> 의미있는 값을 기반으로 접근하게 됨 이 학생의 점수는 이거다 순서랑 상관없이 이름과 점..
Can an array contain different data types? Arrays can contain any type of element value (primitive types or objects), but you can't store different types in a single array. You can have an array of integers or an array of strings or an array of arrays, but you can't have an array that contains, for example, both strings and integers. >> 하나의 array는 같은 종류의 데이타 타입만 담을 수 있다.
When to use guard let rather than if let Swift gives us an alternative to if let called guard let, which also unwraps optionals if they contain a value, but works slightly differently: guard let is designed to exit the current function, loop, or condition if the check fails, so any values you unwrap using it will stay around after the check. When to use guard let rather than if let - a free Understanding Swift tutorial Was this page us..
Nil coalescing The nil coalescing operator unwraps an optional and returns the value inside if there is one. If there isn’t a value – if the optional was nil – then a default value is used instead. Either way, the result won’t be optional: it will either by the value from inside the optional or the default value used as a back up. Here’s a function that accepts an integer as its only parameter and returns an o..
What is Cyclomatic complexity? The cyclomatic complexity of a section of source code is the number of linearly independent paths within it. For instance, if the source code contained no control flow statements (conditionals or decision points), such as if statements, the complexity would be 1, since there is only a single path through the code. If the code had one single-condition if statement, there would be two paths throug..
Closures Closures are self-contained blocks of functionality that can be passed around and used in your code. Closures in Swift are similar to blocks in C and Objective-C and to lambdas in other programming languages. Closures can capture and store references to any constants and variables from the context in which they are defined. This is known as closing over those constants and variables. Swift handl..
Class: NSManagedObject A base class that implements the behavior required of a Core Data model object. Declaration class NSManagedObject : NSObject Overview A managed object is associated with an entity description (NSEntityDescription) that provides metadata about the object, including the name of the entity that the object represents and the names of its attributes and relationships. A managed object is also associa..
Class: UserDefaults Declaration class UserDefaults : NSObject Overview The UserDefaults class provides a programmatic interface for interacting with the defaults system. The defaults system allows an app to customize its behavior to match a user’s preferences. For example, you can allow users to specify their preferred units of measurement or media playback speed. Apps store these preferences by assigning values to..