반응형
본 게시물은 Hacking with swift 를 참고하여 작성되었습니다. Hacking with swift
SwiftUI
@AppStorage
에서UserDefaults
값을 읽고 씁니다 . 이것은 데이터를 소유합니다. 더 많은 정보.@Binding
다른보기에서 소유 한 값 유형 데이터를 나타냅니다. 바인딩을 로컬로 변경하면 원격 데이터도 변경됩니다. 이것은 데이터를 소유하지 않습니다. 더 많은 정보.@Environment
색 구성표, 접근성 옵션 및 특성 컬렉션과 같은 시스템의 데이터를 읽을 수 있지만 원하는 경우 여기에 고유 한 키를 추가 할 수 있습니다. 이것은 데이터를 소유하지 않습니다. 더 많은 정보.@EnvironmentObject
환경에 배치 한 공유 객체를 읽습니다. 이것은 데이터를 소유하지 않습니다. 더 많은 정보.@FetchRequest
특정 엔티티에 대한 핵심 데이터 가져 오기 요청을 시작합니다. 이것은 데이터를 소유합니다. 더 많은 정보.@FocusedBinding
현재 선택된 텍스트 필드와 같은 키 창의 값을 감시하도록 설계되었습니다. 이것은 데이터를 소유하지 않습니다.@FocusedValue
는 바인딩 된 값을 풀지 않는 더 간단한 버전의@FocusedBinding
입니다. 이것은 데이터를 소유하지 않습니다.@GestureState
스와이프 한 거리와 같이 현재 진행중인 제스처와 관련된 값을 저장합니다. 단, 제스처가 중지되면 기본값으로 재설정됩니다. 이것은 데이터를 소유합니다. 더 많은 정보.@Namespace
다른 뷰에서 공유 할 수있는 일치하는 지오메트리 효과를 허용하는 애니메이션 네임 스페이스를 만듭니다. 이것은 데이터를 소유합니다.@NSApplicationDelegateAdaptormacOS
앱의 앱 대리자로 클래스를 만들고 등록하는 데 사용됩니다. 이것은 데이터를 소유합니다.@ObservedObjectObservableObject
프로토콜 을 준수하는 외부 클래스의 인스턴스를 나타냅니다 . 이것은 데이터를 소유하지 않습니다. 더 많은 정보.@Published
는 내부 속성에 연결되어 ObservableObject있으며 변경 될 때이 속성을 사용하는 모든 뷰를 새로 고치도록 SwiftUI에 알립니다. 이것은 데이터를 소유합니다. 더 많은 정보.@ScaledMetric
사용자의 동적 유형 설정을 읽고 제공 한 원래 값을 기준으로 숫자를 늘리거나 줄입니다. 이것은 데이터를 소유합니다. 더 많은 정보.@SceneStorage
상태 복원을 위해 소량의 데이터를 저장하고 복원 할 수 있습니다. 이것은 데이터를 소유합니다. 더 많은 정보.@State
뷰에 로컬로 소량의 값 유형 데이터를 조작 할 수 있습니다. 이것은 데이터를 소유합니다. 더 많은 정보.@StateObjectObservableObject
프로토콜 을 준수하는 참조 유형 데이터의 새 인스턴스를 저장하는 데 사용됩니다 . 이것은 데이터를 소유합니다. 더 많은 정보.@UIApplicationDelegateAdaptoriOS
앱의 앱 델리게이트로 클래스를 만들고 등록하는 데 사용됩니다. 이것은 데이터를 소유합니다. 더 많은 정보.
Swift
@
- @autoclosure : 클로저 인 함수 매개 변수에 첨부 된 속성으로, Swift를 사용하는 모든 코드를 사용자가 직접 수행하도록 요구하는 대신 자동으로 래핑하도록 요청합니다. 이것은 거의 사용되지 않지만 assert()기능 에서 중요 합니다.
- @available : 특정 버전의 Swift 또는 운영 체제에서 사용 가능하거나 사용할 수없는 것으로 표시하는 유형 또는 함수에 첨부 된 속성입니다.
- @discardableResult : 값을 반환하는 메서드에 연결된 특성으로, 호출자가 원하는 경우 반환 값을 무시해도 안전한 것으로 표시합니다. 이것이 사용되지 않을 때 Swift는 함수의 반환 값으로 무언가를하지 않으면 경고를 표시합니다.
- @dynamicCallable : 직접 호출 가능한 것으로 표시하기 위해 유형에 연결된 속성으로, 주로 Swift가 Python과 같은 동적 언어와 더 쉽게 상호 작용할 수 있도록합니다.
- @dynamicMemberLookup : 특수 메서드를 사용하여 정의되지 않은 속성을 처리 할 수있는 것으로 표시하기 위해 유형에 첨부 된 속성으로, 주로 Swift가 Python과 같은 동적 언어와 더 쉽게 상호 작용할 수 있습니다.
- @escaping : 클로저 인 함수 매개 변수에 첨부 된 속성으로, 함수가 반환 된 후 클로저가 사용될 것임을 Swift에 알려줍니다. 이것은 차례로 Swift가 클로저를 안전하게 저장하여 조기에 파괴되지 않도록합니다.
- @objc : Objective-C 코드에 액세스 할 수 있어야하는 메서드 및 속성을 표시하는 데 사용되는 특성입니다. Swift는 코드가 필요 이상으로 커지지 않도록 기본적으로 Objective-C에 액세스 할 수있는 코드를 만들지 않습니다.
- @objcMembers : Objective-C 코드에서 모든 속성과 메서드에 액세스 할 수 있어야하는 클래스를 표시하는 데 사용되는 속성입니다. Swift는 코드가 필요 이상으로 커지지 않도록 기본적으로 Objective-C에 액세스 할 수있는 코드를 만들지 않습니다.
- @unknown :switch 블록 의 기본 케이스에 첨부 된 속성으로, 코드가 소스 호환성을 깨지 않고 향후 특정 시점에 추가 될 수있는 열거 형 케이스를 처리 할 수 있도록합니다.
a
- Access control : 다른 코드에서 속성에 액세스하는 방법을 제어하는 키워드 집합입니다. open속성은 어디서나 액세스하고 재정의 할 수 있음을 public의미합니다 . 즉, 속성이 어디서든 액세스 할 수 있지만 원래 모듈 내에서만 재정의 internal됨을 의미합니다. 속성이 동일한 모듈 내부의 fileprivate어느 곳에서나 액세스 할 수 있음을 의미합니다. 동일한 파일 private내부에 있으며 동일한 유형의 모든 위치에서 속성에 액세스 할 수 있음을 의미합니다.
- ABI : Swift 컴파일러가 바이너리를 생성하는 방법에 대한 설명 : 데이터 구조가 메모리에 배치되고 액세스되는 방법, 함수가 호출되는 방법 등.
- API : 특정 문제를 해결하기 위해 라이브러리에 의해 노출되는 클래스, 구조체, 메서드 및 속성 모음입니다. Application Programming Interface의 약자입니다.
- Argument: The name for a value that is being passed into a function, to be used inside the function. For example, in sayHello(to: "Paul") the to part is an argument. Many people just say "parameter" rather than "argument", but argument is technically correct.
- Array: A sequential collection of values of any type, such as an array of names in a band.
- Associated type: A missing type in a protocol that must be specified by whatever type is conforming to the protocol. Associated types allow us to have flexibility when adding conformances: we can say that to conform to our protocol you must have an array of items, but we don't care what the data type of those items is. Associated types are written as one word in Swift: associatedtype.
- Associated value: A value that has been added to an enum case to provide some extra meaning. For example, you might have an enum case saying the weather is windy, then add an associated value saying how windy.
b
- Block: Can mean any chunk of code that starts with { and ends with } ("a code block"), but "block" is also the Objective-C name for closures.
- Boolean: A data type that stores either true or false.
- Brace: The name for opening and closing curly brackets, { and }.
- Bracket: The name for opening and closing square brackets, [ and ]
- Break: A keyword that exit the current loop. If used with a labeled statement, e.g. break myLoop, it will break out of the specified block.
c
- Capturing values: The name for the process of closures keeping a reference to values that are used inside the closure but were created outside. This is different from copying: the closure refers to the original values, not its own copies, so if the original values change then the closure's values change too.
- CaseIterable: A Swift protocol that can be applied to enums. If the enum has cases with no associated values, the compiler will generate an allCases array that lets you loop over the cases in the enum.
- Catch: A keyword that starts a block of code to handle errors. You can specify what kind of errors should be caught, and use a generic "catch all" block to catch everything else. Paired with do.
- CGFloat: A floating-point number that may be equivalent to a Double or Float depending on the platform.
- Class: A custom data type that can have one or more properties and one or more methods. Unlike structs, classes are reference types.
- Class inheritance: The ability for one class to build on another, inheriting all its methods and properties. Some languages allow one class to inherit from multiple parents, but Swift does not.
- Closure: An anonymous function that automatically keeps a reference to any values it uses that were declared outside the function.
- Codable: A protocol that allows easy conversion between a struct or a class and JSON or XML.
- Collection: A Swift protocol that is used by sequences types you can traverse multiple times without destroying them or affecting the collection, such as arrays and dictionaries.
- Comparable: A common Swift protocol that says conforming types can be placed into an order using <.
- Compiler directive: One of several special pieces of code written using a #, that act as instructions to the compiler. For example, compiler directives can check whether we're targeting the simulator or not, and compile one of two code variants.
- Compound assignment operator: An operator that modifies a value and assigns it back to the original variable at the same time. For example, score += 1 adds 1 to the current value of score.
- Computed property: Any property that does not have a simple storage area for its value, and instead is calculated each time the property is accessed by running some code.
- Condition: Any check that evaluates to true or false using an if statement. You can provide code to run when your condition is true, as well as an else
- Conditional conformance: The ability to say that a type conforms to a protocol only if specific conditions are met. For example, Swift's arrays conform to Equatable only if their element also conforms to Equatable.
- Constant: Any named piece of data in your code that may not change when your program runs.
- Continue: A keyword that exits the current iteration of a loop, causing the loop to start its next iteration immediately. If used with a labeled statement, e.g. continue myLoop, it will continue the specified block.
- Controller: A part of your program that handles logic. Part of the Model-View-Controller architecture.
d
- Data: A type that holds any kind of binary data.
- Default case: A special case for switch blocks that will match all other values.
- Default parameter: A function parameter that has a default value attached, to allow callers not to provide it and get reasonable behavior. For example, func checkSettings(debugMode: Bool = true) can be called as checkSettings(debugMode: true) or checkSettings(debugMode: false), but also as checkSettings() – missing a debugMode value will assume true, because that's the default value.
- Defer: A keyword that allows us to schedule work for when the current scope is exited.
- Deinitializer: A special method that is called when an instance of a class is being destroyed. These may not accept parameters, and do not exist on structs.
- Dictionary: A high-performance, unordered collection of values stored using a key for fast access.
- Do: A keyword that starts a block of code that might throw errors. Paired with catch.
- Double: A high-precision floating-point number, such as 3.1, or 3.141592654.
e
- Enum: A set of named values that are easier to remember and safer than just using strings or integers. For example, you might create an enum of directions, using north, south, east, and west – this is much nicer than using 0, 1, 2, and 3, for example. Short for "enumeration". Pronounced as "ee-numb", but "ee-noom" is an accepted variation.
- Equatable: A common Swift protocol that says conforming types can be compared for equality using ==.
- Error: A Swift protocol that our own enums can conform to, which we can then use to throw errors from functions.
- Expression: Some code that evaluates to a value. For example, 12 * 12 evaluates to 144.
- Extension: A set of additional methods and computed properties that are added to a concrete type, such as Int.
f
- Fallthrough: A keyword used in switch blocks to mean "carry on executing the case immediately following this one."
- Failable initializer: An initializer that returns an optional value, because initialization might have failed for some reason. These are written as init?() or init!().
- Final class: A class that may not be inherited from by anything else.
- Float: A low-precision floating-point number, such as 3.1, or 3.141592654.
- For loop: A loop that counts through all values in a sequence, such as an array or a range.
- Force unwrap: The process of using the value inside an optional without checking it exists first. If the optional is empty – if it has no value – force unwrapping will crash your code.
- Framework: A collection of code that you are using. Frameworks differ from libraries in that frameworks usually take over control of their operation, and call back to you when they need information.
- Function: A named section of your code that performs a specific, reusable task. You might pass in parameters to the function to customize how it runs, and it might return one or more values that are the result of its work.
- Functional programming: A programming approach that favors sending and receiving immutable data to and from functions, avoiding side effects, and composing functions together.
g
- Generics: The ability for one type or function to be used with a variety of data types. For example, Swift's arrays are generic, because you can make an array that stores integers, an array that stores strings, and so on.
- guard: A piece of Swift syntax that checks whether a condition is true, and forces you to exit the current scope immediately if it is not. This is commonly used as guard let, which checks whether an optional has a value, and, if it does, creates a new constant for that optional's value so it can be used safely. If it has no value, the guard condition fails and you must exit the current scope.
h
- Hashable: A common Swift protocol that says conforming types can be represented using hash values.
- Higher-order function: A function that accepts another function as a parameter, or sends back a function as its return value.
i
- if let: A piece of Swift syntax that checks whether an optional has a value, and, if it does, creates a new constant for that optional's value so it can be used safely. If it has no value, the if condition fails and you can run an else block instead.
- Implicitly unwrapped optional: A special Swift optional that may or may not contain a value, but does not need to be checked before use. If you attempt to use an implicitly unwrapped optional that has no value, your app will crash.
- Indirect enum: An enum that is compiled specially so that it can reference itself in its associated values. For example, if you had a linked list enum that needed to reference another linked list item as an associated value, this would need to be indirect.
- Infinite loop: A loop that never ends until you say so. This is most commonly done using a boolean variable set to true – you can set it to false as soon as you want the loop to end.
- Initializer: A special method that gets run to create an instance of a struct or class. You can have many initializers, and in the case of classes may call parent initializers inside your own initializer.
- inout parameter: A function parameter that, when changed inside the function, remains changed outside the function.
- Integer: A whole number, such as 5, 55, or 55 million.
k
- Keypath: A way of referring to properties without actually reading them.
- Keyword: Any word that has specific meaning as a Swift construct, such as class, continue, and try.
l
- Labeled statement: A name attached to a specific block of code, such as a loop or a condition, allowing you to break out of it specifically even if you are inside other blocks. For example, if you are inside a loop that's inside a loop that's inside a third loop, you could exit the outermost loop.
- Lazy: A keyword that marks a property as being created only when it is first accessed. This is a performance optimization, because it means if the property is never accessed the work required to calculate its value is never done.
- Library: A collection of code that you are using. Libraries differ from frameworks in that libraries are just collections of classes, structs, enums, and so on, for you to use however you want.
m
- Memberwise initializer: An initialer for structs that is automatically generated by the Swift compiler, requiring that all properties must have a value. If you implement your own initializer inside the struct the memberwise initializer will no longer be generated by Swift.
- Method: A function that belongs to a struct or a class.
- Model: A part of your program that stores data. Part of the Model-View-Controller architecture.
- Multi-line strings: A string that spans multiple lines. Multi-line strings in Swift must start and end with three double quotes on their own line.
- Mutating method: A method on a struct that will change one of the properties of the struct. This must be used because only variable structs can have mutating methods called on them. Mutating methods are not required for classes, where every method can be mutating without the keyword.
n
- Nested type: A class or a struct that is defined inside another class or struct.
- Nil: Swift's term for missing data. An optional that has no value will be set to nil.
- Nil coalescing: An operator in Swift, written as ??, that uses the value from an optional if it has one, or a default value otherwise.
- Non-throwing function: A function that cannot throw errors. These must not be marked using throws, and must not use the throw keyword.
o
- Objective-C: Apple's first programming language, and the forerunner to Swift.
- Operand: The values that work alongside an operator. For example, in 2 + 3 the 2 and 3 are operands.
- Operator: Any symbol that acts as a function on values to its left and/or right. For example, + is an operator that adds two values together.
- Operator overloading: The ability for one operator, such as + to do multiple things depending on how it's used. For example, 1 + 1 is an integer addition, but "Hello " + "Paul" will join the strings together.
- Optional: A type that wraps another type, such as String or Int, but adds the ability to store no value at all. "No value" is different from all regular integer values, including zero. Swift uses optionals heavily as a way of providing runtime safety, and the compiler forces us to use them correctly.
- Optional chaining: The ability to use multiple optional methods or properties in a single line of code. If any of them are nil then execution of that line will stop, but if they all succeed then you will get an optional value back. For example, user?.name?.uppercased().
- Override method: A class's method that has the same name, parameters, and return type as a method on the class's parent class. The override keyword tells the Swift compiler you understand that you are changing the behavior.
p
- Parameter: The name for a value that has been passed into a function, to be used inside the function. For example, in func sayHello(to: String), the to part is a parameter.
- Parameter label: Custom names assigned to function parameters that affect the way they are used externally. For example, in sayHello(to name: String), people calling the function will say sayHello(to: "Paul"), but inside the function you would refer to name.
- Parenthesis: The name for opening and closing rounded brackets, ( and ).
- Polymorphism: The ability for an object to appear as and be used as multiple different types. For example, a Labrador class instance could also be used as a Dog and Mammal if you had defined those as parent classes.
- Property: A constant or variable that belongs to a class, struct, or enum.
- Property observer: Code added to a property using willSet and didSet, that gets called whenever a property is being changed.
- Property wrapper: An attribute placed around a property that gives it custom abilities. For example, you could write a @UserDefaults property wrapper to make loading and saving data to user defaults easier.
- Protocol: A list of criteria that a type must conform to, such as property names and methods. Protocols allow us to treat many objects the same way, because they implement all the behavior required to make the protocol work.
- Protocol extension: A set of additional methods and computed properties that are added to a protocol, such as Equatable.
- Protocol inheritance: The ability for one protocol to inherit requirements from another protocol. For example, the Comparable protocol inherits from Equatable.
- Protocol-oriented programming: An approach to programming that favors code re-use through protocol extensions, providing the benefits of multiple inheritance without some of the complexity. Specifically, protocol-oriented programming (POP) cannot add stored properties to a type, so there is less cruft.
r
- Range: Ranges span the distance between two values, up to and sometimes including the final value. This is mostly used with numbers: 1..<4 includes the numbers 1, 2, and 3, whereas the range 1...4 includes the numbers 1, 2, 3, and 4. Ranges can also be made from other data types, such as dates.
- Raw strings: The ability to specify custom string delimiters for situations when you want to use backslashes and quote marks without them having their regular meaning.
- Raw value: A simple underlying data type that enum values can be mapped to for the purpose of loading and saving. For example, you might say that the planets Mercury, Venus, and Earth have the integer raw values 1, 2, and 3.
- Reference type: Any type that stores its data indirectly in memory, with the variable or constant really just being a pointer (or reference) to that piece of memory. If you point a second variable to a reference type, it will point at the same data in memory as the original reference, so the data is shared.
- Repeat loop: A loop that will continue executing as long as its condition is true. If its condition starts false, it will still execute at least once.
- Rethrowing functions: A function that uses the rethrows keyword so that it throws errors only if the closure it accepts throws errors.
- Return type: The type of data that a function says it will return. Swift always enforces this, so if you say you will return a string you must do so.
- Runtime: When your code is running, as opposed to compile time, which is when the code is being built.
s
- Scope: A region of code where variables and constants are valid. Each time you use an opening brace you start a new scope: all previous variables and constants remain valid in that scope, but any that are declared inside that scope are only valid until the scope ends with a closing brace.
- Selector: A way of referring to functions without actually calling them, usually for the purpose of calling them later on.
- Serialization: The process of converting objects into text or binary, and vice versa. For example, converting an array of users into JSON, or converting JSON into an array of users.
- Set: A high-performance, unordered collection of values of any type that conforms to the Hashable protocol.
- Shorthand parameter name: Special parameter names made available inside closures, written as a dollar sign the numbers starting from 0. For example, if a closure accepts a name string and an age integer, you could refer to the string as $0 and the age as $1. Note: you may not mix and match shorthand syntax with regular syntax.
- some: A keyword that uses an opaque return type – return types such as some View in SwiftUI to mean "some sort of View will be returned but it doesn't matter which type specifically."
- Statement: Some code that performs an action, such as print(age).
- Static method: A method that is shared across all instances of a struct or class, rather than unique to each instance. Because this is not run on a specific instance of a struct or class, it cannot access any properties that are not also marked static.
- Static property: A property that is shared across all instances of a struct or class, rather than unique to each instance.
- StaticString: A specialized form of Swift's String that must be hand-typed – you must literally type the string directly into your code rather than using string interpolation.
- String: A collection of letters, such as "Hello".
- String interpolation: The ability for Swift to insert the values of variables and constants into strings, such as "Hello, \(name)."
- Struct: A custom data type that can have one or more properties and one or more methods. Unlike classes, structs are value types.
- Subscript: Special methods that are used with collections, and provide easy access to read and write values in the collection. For example, someArray[3] is a subscript, as is someDictionary["name"].
- Switch case: A system of evaluating multiple conditions in one block of code. For example, you might use switch age to evaluate the age variable, then have cases for 0 to 10, 10 to 20, 20 to 30, and so on. Switch blocks must be exhaustive in Swift, which means they must have cases to cover all possible values.
- Syntactic sugar: The name for special Swift syntax that is designed to mask complexity. The name comes from the idea that it's better to create short and sweet syntax that does the same as longer syntax. For example, [String] is syntactic sugar for Array<String>.
- Synthesize: The name for when the Swift compiler generates code on your behalf. For example, if you say that a custom struct conforms to Equatable, and all its properties already conform to Equatable, then Swift can synthesize a == function for it.
t
- Ternary operator: An operator that works with three values, written in Swift as ? :. For example, isEnabled ? 10 : 100 will return 10 if isEnabled is true, and 100 if it's false.
- Throwing function: A function that has the ability to throw errors. These must be marked using the throws keyword in Swift, and called using try.
- Trailing closure syntax: The ability for functions that accept a closure as their final parameter to have that closure specified after the function's parentheses, which usually helps make the function call easier to read.
- try catch: The ability to run throwing functions and catch any errors that occur. You must start using a do block, then call any throwing methods inside that using try, and finally add one or more catch blocks to catch any errors. Writing a catch block to catch all errors is sometimes called a Pokémon catch, because "you gotta catch 'em all."
- Tuple: A fixed-size collection of values of any type, like an anonymous struct. Pronounced as "tyoo-pull" or "too-pull", or sometimes even "tupple".
- Type alias: A type alias is the ability to specify what type should fill an associated type. This is usually not needed, because Swift can figure out the type alias just by looking at properties used with the associated type. Type aliases are written as one word in Swift: typealias.
- Type inference: The ability for Swift's compiler to figure out what kind of data type should be assigned to each of your variables and constants, so you don't have to explicitly state it.
- Typecasting: The ability to treat an object of one type as an object of a different type. This is needed when you know more information about the Swift compiler, such as when you instantiate a view controller from a storyboard.
u
- Unwrapping optionals: The process of checking whether there is a value inside an optional, and, if there is, extracting that value so it can be used safely.
v
- Value type: Any type that stores its data directly in memory. If you point a second variable to a value type it will always copy the data in its entirety, rather than allowing it to be shared.
- Variable: Any named piece of data in your code that may change when your program runs.
- Variadic function: A function that takes one or more values of a specific type, separated by commas. The print() function is variadic, because you can write print(1) to print a single value, or print(1, 2, 3, 4, 5, 6, 7, 8) to print many.
- View: A part of your program that shows visible results to your user. Part of the Model-View-Controller architecture.
- Void: The absence of a value. Used most commonly to refer to the return types of functions that return nothing.
w
- While loop: A loop that will continue executing as long as its condition is true. If its condition starts false, it won't execute even once.
'TIP > iOS & MacOS TIp' 카테고리의 다른 글
iPad에서 Playground를 통해 SwiftUI 코드 작성 (0) | 2021.04.29 |
---|---|
[iOS / Xcode] Snippet 사용법 - 자주쓰는 코드를 저장하자! (0) | 2021.04.08 |
왕 초보를 위한 CocoaPods(코코아팟) 튜토리얼 (1) | 2021.02.09 |
Xcode 프로젝트 이름 변경 방법 (2) | 2021.02.06 |
개발시 참고하면 좋은 사이트 (0) | 2021.01.23 |