
original source : https://youtu.be/gI3pz7eFgfo
original source : https://youtu.be/gI3pz7eFgfo
왼쪽 로보트는 delegator 이며 이는 어떤 기능들이 필요한지 전체적인 구조만 알고 있다.
오른쪽 로보트는 delegate 이며 실제로 어떤 기능이 어떻게 수행되어야하는지 자세한 내용이 가지고 있다.
다시 말하면 왼쪽 로보트에는 이러이런 기능이 필요하다는 전체의 내용만 기술되어 있다. (protocol) 실제로 이 protocol을 따르면 실제 기능을 구현하는 것은 오른쪽 로보트가 된다.
Search results for collection view – Cocoa Controls
다양한 collection view layout들을 확인할수 있다.
Using Container Views! (Xcode)
containerview를 이용 다른 viewcontroller를 삽입하는 방법을 보여준다. 화면을 분할해서 한쪽에는 게임, 한쪽은 tableviewcontroller를 디스플레이하는 과정을 예제로 보여준다.
참고자료) iPhone Application 프로그래밍 10강 스크롤 뷰와 씬 내장 https://youtu.be/RfpbsZXgo9U
처음에는 이 동영상을 보고 좀더 이해하기위해 찾다가 위 동영상을 발견
strong, weak, unowned – Reference Counting in Swift
This article explains Apple’s memory management in Swift. Even if it gets handled mostly automatic there are still some pitfalls. Choosing the correct reference type to describe the relationship between objects help you to avoid memory leaks.
Apple’s implementation for automatic tracking and managing of memory usage is called ARC (Automatic Reference Counting). It automatically frees up the memory when objects aren’t referenced anymore. To know which objects are still in use it tracks the relationship between objects by increasing and decreasing a reference count. Objects can only be deallocated when the reference count is zero. ARC only applies to instances of Classes. Structs, Enums and Value-Types are not passed by reference. This is a another great reason to use Structs instead of Classes whenever possible.
You’ll find strong references almost everywhere in Swift because it’s the default declaration of a property. This doesn’t lead to a problem when you have a linear reference flow. When you deallocate the parent and decrease the retain count, all child get decreased as well. Here is an example of a strong reference:
import Foundation class Car { var brand: String init(brand: String) { self.brand = brand print("Car of the brand (brand) allocated") } deinit { print("Car of the brand (brand) is being deallocated") } } do { let tesla = Car(brand: "tesla") }
The initialisation of the car object is wrapped in a do block. This creates a scope around it. At the end of the scope the object gets deallocated and everything is fine:
Car of the brand tesla allocated
Car of the brand tesla is being deallocated
However it’s possible to write code with a strong reference cycles between class instances. This modified version of the previous example shows a reference cycle:
import Foundation class Car { var brand: String var owner: Owner? init(brand: String) { self.brand = brand print("Car of the brand (brand) allocated") } deinit { print("Car of the brand (brand) is being deallocated") } } class Owner { var name: String var car: Car? init(name: String) { self.name = name print("Owner (name) allocated") } deinit { print("Owner (name) deallocated") } } do { let tesla = Car(brand: "tesla") let misterX = Owner(name: "Mister X") tesla.owner = misterX misterX.car = tesla }
The car object now also has an optional reference to an Owner and the Owner has an optional reference to a Car. The output is:
Car of the brand tesla allocated
Owner Mister X allocated
The strong reference cycle prevents the retain count to reach zero to get deallocated and free up the memory. To solve this issue we need weak references.
Unlike strong references weak don’t increase the retain count by one. So they don’t protect the object from being deallocated by the ARC. On deallocation the weak reference will be automatically set to nil. This is the reason why all weak references are mutating optional variables. Defining a constant as weak is not possible.
Let’s take a look at the previous example. Using a weak reference between the car and owner helps to fix the deallocation:
class Car { weak var owner: Owner? ... } class Owner { weak var car: Car? ... } ...
Now ARC correctly deallocates all objects:
Car of the brand tesla allocated
Owner Mister X allocated
Owner Mister X deallocated
Car of the brand tesla is being deallocated
Note: Using only one weak reference in the Car or Owner class instead of both would have fixed the issue as well and dissolve the strong reference cycle.
Unowned references behave similar to weak ones. They don’t increase the retain count by one as well. Unlike weak references unowned don’t have to be an Optional because they aren’t automatically set to nil on deallocation. It’s important that you only use unowned references when you really know that the object will never be nil once it has been set.
According to Apple it’s best to use when your reference and the referenced code will be deallocated at the same time.
“Use a weak reference whenever it is valid for that reference to become nil at some point during its lifetime. Conversely, use an unowned reference when you know that the reference will never be nil once it has been set during initialisation.” Apple Documentation
Apple’s automatic memory management doesn’t prevent you from producing memory leaks. Non-linear strong references and reference cycles can prevent the retain count from reaching zero. The use of weak and unowned references help you to avoid this and keep your app memory in balance.
after effect에서 만든 애니메이션을 lottie iibrary를 이용해서 ios에서 사용하는 방법
aftereffect에 bodymovin plugin 를 다운받으면 aftereffect로 작업한 애니메이션을 json화일로 export가 가능하게 되고 이 화일을 project 폴더에 넣는다. 그리고 lottie library를 code에서 import하고 나서 애니메이션을 ios에서 사용가능하게 된다.