楼主: julyVAHF
跳转到指定楼层
上一主题 下一主题
收起左侧

100 days of swiftUI

🔗
 楼主| julyVAHF 2021-11-27 13:52:53 来自APP | 只看该作者
全局:
Day 59 core data recap
[C] modifier  makes nspredict insensitive
%@ replace value with double quote, %k does not add quotes
Begins with and contains are both case sensitive
We can create fetch request without @FetchRequest property wrapper using the FetchRequest struct
FetchRequest only work with one entity
回复

使用道具 举报

🔗
 楼主| julyVAHF 2021-12-7 13:52:18 来自APP | 只看该作者
全局:
Day 60: summarize 3 projects
1. Sending back varying views: if a, return a view; else return b view
- wrap with AnyView (Performance degrade); should be  used as the last resource
- add @ViewBuilder annotation ( useful but if use it a lot, might need to separate code logic in to different smaller views)
- Group view (similar as @viewbuolder, but no effect on layout and extra view), can bypass 10 views limit
- Ternary condition: inert modifier:
Text(“Hi”)
   . Frame(width: Bool.random()? 300: nil)
Best performance is using Ternary condition since only one view is created

Return [AnyView]() is possible
View.append(AnyView(Circle().frame(height:50))

Extension View {
     func erasedToAnyView() -> AnyView {
          AnyView(self)
     }
}


Codable Keys
Useful way to decode:
Decoder.keyDecodingStrategy  = . ConvertFromSnakeCase

If the json data key mapping is totally different from the property name, use CodingKey enum to provide how to mapping

Json:
{
“first”:”Andrew”,
“last”:”Gou”
}

struct User: Codable {

enum CodingKeys: String, CodingKey {
    case firstName = “first”
    case lastName = “last”
}


var firstName: String
var lastName: String
}
回复

使用道具 举报

🔗
 楼主| julyVAHF 2021-12-8 13:56:58 来自APP | 只看该作者
全局:
Day 61: core data challenge
Main actor:
When network async call update new data while SwiftUI generates the view?

await MainActor.run{
// code
}

Main actor: single thread process the code
Core data entities better to name different from data struct in case of conflict
回复

使用道具 举报

🔗
 楼主| julyVAHF 2021-12-10 14:40:40 来自APP | 只看该作者
全局:
Day 62 project 13: instafilter
-what is @State property wrapper? Another struct called State with immutable setter -> the change value passed in by SwiftUI view is cached somewhere, the state itself has no change
-> what’s the impact?
At SwiftUI, if use slider with didSet to trigger a State property value, didSet will never get triggered bc non of the struct has changed

Use OnChange to capture any value change( instead of struct change)

Lastly, the confirmationDialog is the same syntax as Alert



补充内容 (2021-12-10 14:54 +08:00):
Not immutable setter -> non mutating set

public car wrappedValue: Value { get nonmutating set}
回复

使用道具 举报

🔗
 楼主| julyVAHF 2021-12-11 14:34:53 来自APP | 只看该作者
全局:
Day 63: integrate core image with SwiftUI
- use typealias UIViewControllerType = …type you want to add
-> let Xcode auto generate the methods  needed to confront to UIViewControllerRepresenrable
In the example, we use PHPickerViewController

Difference between SwiftUI image-> View
UIImage: from UIKit
CGImage: from core graphics
CIImage: from core image

Layers to transfer each image type and use core image, CIContext, CIFilter to apply filter to SwiftUI image and display the change on SwiftUI( return an Image type)

Dynamically bind inputKeys for all filter type so that when the filter switches, say from sepiaTone to pixelate, no need to update filter keys from intensity to scale
回复

使用道具 举报

🔗
 楼主| julyVAHF 2021-12-22 12:49:36 来自APP | 只看该作者
全局:
Day 64: use coordinator/delegate to manage SwiftUI view controller
Use UIImageWriteToSavedPhotosAlbum UIKit function to save image

补充内容 (2021-12-22 12:54 +08:00):
Create a SwiftUI view that conforms to UIViewControllerRepresentable
Add makeUIViewController() method that create some sort of UIViewController(PHPickerViewController)
Add a nested Coordinator that bridges UIKit view controller to SwiftUI view
Add didFinishPicking to the coordinator
Add @Binding property to the ImagePicker
回复

使用道具 举报

🔗
 楼主| julyVAHF 2021-12-22 13:00:38 来自APP | 只看该作者
全局:
Day 65 add basic UI:
Context - rendering CIIMAGE TO cGImage-  is expensive to create
How to pass UIImage to core image filter? Core image takes float (instead of double)
InputImage property of core image filters is thoroughly broken and tend to cause app to crash- use filters setValue() with the key kCIInputImageKey
回复

使用道具 举报

🔗
 楼主| julyVAHF 2021-12-22 19:04:42 来自APP | 只看该作者
全局:
Day 66: add custom filter in sheet
Apply CIImage filters - custom binding each input keys of the filter

OnChange can apply to the whole view body but for code readability, it’s better to decorate the view that triggers the change.

Separate UIKit function from SwiftUI for save image

- Success handler and error handler
回复

使用道具 举报

🔗
 楼主| julyVAHF 2021-12-23 16:29:07 来自APP | 只看该作者
全局:
Day 67: wrap up
- Confirmation dialogue max allow 10 buttons - still figuring out how to bypass the limit
- @objc let obj-c code call a swift method
回复

使用道具 举报

🔗
 楼主| julyVAHF 2021-12-25 15:58:35 来自APP | 只看该作者
全局:
Day 68: bucket list intro
Comparable protocol
Write to document directory
Use enums to switch view
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表