2020 Monthly I Learned - kirseia/study GitHub Wiki

2020.12
  • AVAudioEngine ์„ ํ™œ์šฉํ•œ ๋…น์Œ๊ธฐ ๊ฐœ๋ฐœ

    • ํ•ต์‹ฌ์€ mixer.volume = 0์œผ๋กœ ์ž…๋ ฅ๋‹จ์—์„œ์˜ ์†Œ์Œ ์ œ๊ฑฐ(๋…น์Œ๊ธฐ ์†Œ๋ฆฌ๋งŒ ๋ฝ‘๊ธฐ),
    • engine.connect(mixerNode, to: engine.mainMixerNode, format: mixerFormat) ์œผ๋กœ mainMixerNode ๋กœ ์—ฐ๊ฒฐํ•˜๋Š” ๊ฒƒ (engine.outputNode ๊ฐ€ ์•„๋‹ˆ๋ผ)
    • outputNode๋กœ ์—ฐ๊ฒฐํ•˜๋ฉด ๋งˆ์ดํฌ ์ž…๋ ฅ๊ฐ’์ด ์Šคํ”ผ์ปค๋กœ ์ถœ๋ ฅ๋˜์–ด ๋‹ค์‹œ ๋งˆ์ดํฌ๋กœ ์ž…๋ ฅ๋˜๋Š” ํ˜„์ƒ์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Œ
  • ๋กœ์ปฌ ํ‘ธ์‹œ ๋“ฑ๋ก ๋ฐ ์ฒ˜๋ฆฌ 1, 2

    • ๋กœ์ปฌ ํ‘ธ์‹œ์— ์ด๋ฏธ์ง€๋ฅผ ์ถ”๊ฐ€ํ• ๋•Œ๋Š” move ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์šฉํ•  ์ด๋ฏธ์ง€๋ฅผ ๋ณต์‚ฌํ•ด์„œ url์„ ๋„˜๊ฒจ์ค˜์•ผ ํ•จ
    • (but, main bundle ์ด๋ฏธ์ง€๋Š” ๋ณต์‚ฌ๋จ)
  • UserNotifications

  • Share Extension ๊ด€๋ จ ์ •๋ฆฌ, [2]

- ์‚ฌ์ง„ ์—์„œ ๊ณต์œ  ์‹œ phasset ์ด ์•„๋‹ˆ๋ผ image url์ด ๋“ค์–ด์˜ด
- image orientation ์ด ์‚ด์•„์žˆ๋Š” ์ƒํƒœ -> ์‚ฌ์šฉ ๋ฐฉ์‹์— ๋”ฐ๋ผ UIImage.Orientation.up ์œผ๋กœ ๋ณด์ • ํ•„์š”.
- Extension ๊ณผ Host app ์‚ฌ์ด์— ๋ฐ์ดํ„ฐ ์ฃผ๊ณ  ๋ฐ›๊ธฐ๊ฐ€ ์•ˆ๋˜๊ธฐ ๋•Œ๋ฌธ์— image url ์„ ํŒŒ์ผ๋กœ ์ €์žฅํ•ด๋„ Host app ์—์„œ ๋กœ๋“œ๊ฐ€ ์•ˆ๋จ, App groups๋ฅผ ํ™œ์šฉํ•ด์•ผ ํ•จ
- Host app ์ด multi targets ์ด๊ณ , Share Extension ์€ ํ•˜๋‚˜์ผ๋•Œ๋Š” Host app์—์„œ ๋นŒ๋“œํ• ๋•Œ embed ์ดํ›„์— re-signing ๊ณผ์ •์ด ํ•„์š”ํ•จ
- Ref. https://stackoverflow.com/questions/25398636/ios-extensions-with-multiple-targets
- Ref. https://gist.github.com/damian-rzeszot/0b23ad87e5ab5d52aa15c095cbf43c59
2020.11
  • ์‹œ์Šคํ…œ์— ์žˆ๋Š” ํฐํŠธ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
UIFont.systemFont(...) ์œผ๋กœ๋Š” ๊ธฐ๋ณธ ํฐํŠธ๋งŒ ๋กœ๋“œ ๊ฐ€๋Šฅ
for familyName in UIFont.familyNames {
  for fontName in UIFont.fontNames(forFamilyName: fontFamilyName) {
     // ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ๋กœ๋“œ๊ฐ€ ์•ˆ๋จ. ์‹œ์Šคํ…œ ํฐํŠธ๋งŒ ๋กœ๋“œ๋จ
     let font_x = UIFont.font(with: fontName, fontSize: 10) 

     // ์ด๋ ‡๊ฒŒ ํ•ด์•ผ ๋จ, ์ด์œ ๋Š” ๋ชจ๋ฆ„.;
     let description = UIFontDescriptor(name: fontName, size: 10)
     let font_o = UIFont(descriptor: description, size: 10)
  }
}
  • ๊ฐ ํ”Œ๋žซํผ ๊ณต์œ  ๊ธฐ๋Šฅ ์ •๋ฆฌ
- ์ธ์Šคํƒ€  - > ํ•„์ˆ˜ - ์ตœ์†Œ 3์ดˆ, ์ตœ๋Œ€ 10๋ถ„, ์ตœ์†Œ 640x640 
    - "instagram://library?LocalIdentifier=\(assetIdentifier)&InstagramCaption=\(tagString)")
    - ์œ„ ์Šคํ‚ด์œผ๋กœ ํ”ผ๋“œ/์Šคํ† ๋ฆฌ ์—…๋กœ๋“œ ํŽ˜์ด์ง€๋กœ ๋ฐ”๋กœ ์ด๋™ ๊ฐ€๋Šฅ - ๋น„๊ณต๊ฐœ ์ŠคํŒ€
    - https://developers.facebook.com/docs/instagram/sharing-to-feed
 
- ์ธ์Šคํƒ€ ์Šคํ† ๋ฆฌ - ํ•„์ˆ˜ - ์ตœ๋Œ€ 20์ดˆ, ์˜ต์…˜ - 1080p , 50๋ฉ”๊ฐ€ ๋ฏธ๋งŒ 
    - "instagram-stories://share?source_application=\(bundleIdentifier)"
    - scheme + pastebox ํ™œ์šฉํ•ด์„œ ๊ณต์œ  ๊ฐ€๋Šฅ 
    - https://developers.facebook.com/docs/instagram/sharing-to-stories/

- ์œ ํŠœ๋ธŒ - api ๋กœ ์—…๋กœ๋“œ ํ•ด์•ผ ํ•จ, ์ตœ๋Œ€ 128๊ธฐ๊ฐ€
    - youtube://upload scheme (๋น„๊ณต๊ฐœ ์ŠคํŒ€) ์œผ๋กœ ์ƒ์„ฑ ํŽ˜์ด์ง€๋กœ ๋ฐ”๋กœ ์ ‘๊ทผ ๊ฐ€๋Šฅ
    - https://developers.google.com/youtube/v3/docs/videos/insert

- ํ‹ฑํ†ก - sdk ํ•„์š”,
    - 2์ดˆ ~ 60์ดˆ ์‚ฌ์ด, ์›Œํ„ฐ๋งˆํฌ ์žˆ์œผ๋ฉด ์‚ญ์ œ ๋  ์ˆ˜ ์žˆ์Œ. 500๋ฉ”๊ฐ€ ์ œํ•œ, 1080p ์—ฌ์•ผ ํ•จ. 
    - https://boosted.lightricks.com/tiktok-video-length-video-formatting-guide/

- ํŽ˜๋ถ - sdk ํ•„์š” (๋“ค์–ด์žˆ์Œ, ์‚ฌ์šฉ ๊ฐ€๋Šฅ)
    - ๋™์˜์ƒ, 50๋ฉ”๊ฐ€ ๋ฏธ๋งŒ
    - https://developers.facebook.com/docs/sharing/sharing-to-stories/ios-developers/

- ๋ผ์ธ	 sdk ํ•„์š” 
    - 300๋ฉ”๊ฐ€, 1.5๋ถ„์ด ์ œํ•œ 

- wechat sdk ํ•„์š”
    - 100๋ฉ”๊ฐ€ ์ œํ•œ
    - https://developers.facebook.com/docs/whatsapp/api/media/

- qq ๋ฉ”์‹ ์ ธ  sdk ํ•„์š”
- ์™€์ธ ์•ฑ 
    - https://faq.whatsapp.com/iphone/how-to-link-to-whatsapp-from-a-different-app/?lang=kr
2020.10
let a: Any = 120
if let b = a as? Int {
    // 0.011 s 
}
๋ณด๋‹ค 
let a: Any = 120
if case let b as Int = a {
    // 0.001 s
}
2020. 9
2020. 8
2020. 7
2020. 6
2020. 5
2020. 4
AppDelegate.applicationDidReceiveMemoryWarning(_:) <- ์ด๊ฒŒ ๊ฐ€์žฅ ๋จผ์ € ํ˜ธ์ถœ๋จ
UIApplicationDidReceiveMemoryWarningNotification
UIViewController.didReceiveMemoryWarning() <- ๋งˆ์ง€๋ง‰ ํ˜ธ์ถœ ๋จ
    static var totalMemorySpace: UInt64 {
        ProcessInfo.processInfo.physicalMemory / UInt64(1024 * 1024)
    }

    static var usedMemorySpace: UInt64 {
        // The `TASK_VM_INFO_COUNT` and `TASK_VM_INFO_REV1_COUNT` macros are too
        // complex for the Swift C importer, so we have to define them ourselves.
        let TASK_VM_INFO_COUNT = mach_msg_type_number_t(MemoryLayout<task_vm_info_data_t>.size / MemoryLayout<integer_t>.size)
        guard let memoryLayout = MemoryLayout.offset(of: \task_vm_info_data_t.min_address) else {
            return 0
        }
        
        let TASK_VM_INFO_REV1_COUNT = mach_msg_type_number_t(memoryLayout / MemoryLayout<integer_t>.size)
        var info = task_vm_info_data_t()
        var count = TASK_VM_INFO_COUNT
        let kr = withUnsafeMutablePointer(to: &info) { infoPtr in
            infoPtr.withMemoryRebound(to: integer_t.self, capacity: Int(count)) { intPtr in
                task_info(mach_task_self_, task_flavor_t(TASK_VM_INFO), intPtr, &count)
            }
        }
        
        guard kr == KERN_SUCCESS, count >= TASK_VM_INFO_REV1_COUNT else {
            return 0
        }
        
        return info.phys_footprint / UInt64(1024 * 1024)
    }
2020. 3
2020. 2
// average: 0.315 seconds (macOS Sierra 10.12.5)
func testInitializedArrayPerformance() {
    self.measure {
        var array = [Float](repeating: 1, count: 2048 * 2048)
        for i in 0..<array.count {
            array[(i+1)%array.count] = Float(i)
        }
    }
}

// average: 0.043 seconds (macOS Sierra 10.12.5)
func testUninitializedArrayPerformance() {
    self.measure {
        var array : [Float] = []
        array.reserveCapacity(2048 * 2048) <- ์ ค ๋น ๋ฆ„
        array.append(0)
        for i in 0..<(2048 * 2048) {
            array.append(Float(i))
        }
        array[0] = Float(2048 * 2048-1)
    }
}

// average: 0.077 seconds (macOS Sierra 10.12.5)
func testNativeArrayPerformance() {
    self.measure {
        let count = 2048 * 2048
        let array = UnsafeMutablePointer<Float>.allocate(capacity: count)
        for i in 0..<count {
            array[(i+1)%count] = Float(i)
        }
        array.deallocate(capacity: count)
    }
}
[[UIApplication sharedApplication] performSelector:@selector(_performMemoryWarning)];
    func testTuple() {
        let (a, b) = makeTuple()
        print(a)
        print(b)
    }
    
    func makeTuple() -> (Int, Int) {
        return (1, 1)
    }
2020. 1
post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO' 
      config.build_settings['DEBUG_INFORMATION_FORMAT'] = 'dwarf'
      config.build_settings['VALID_ARCHS'] = 'arm64'
    end
  end
end

+ carthage ์ชฝ์€ ๋นŒ๋“œ ํ•  ๋•Œ '--no-use-binaries' ์˜ต์…˜์„ ์ค€๋‹ค

In Xcode, look in Build Settings for โ€œStrip Debug Symbols During Copyโ€ (COPY_PHASE_STRIP). When enabled, debug symbols are omitted from your .app and placed into a .dSYM file. Otherwise your .app contains these symbols. (By default, debug symbols are stripped from release builds for reasons of obfuscation. You probably shouldnโ€™t change this setting for the release configuration.)
  • AVAudioMixParameters ์—์„œ audioPitchAlgorithm ์„ ์˜์ƒ ๋ฐฐ์†์ด ๋น ๋ฅผ ๊ฒฝ์šฐ timeDomain / spectral ์ด ๊ณ„์‚ฐ๋Ÿ‰์ด varispeed ๋ณด๋‹ค ๋†’๊ฑฐ๋‚˜ ๋‚ฎ์Œ์—๋„ ๋ถˆ๊ตฌํ•˜๊ณ  ๋น„์ •์ƒ ๋™์ž‘์„ ํ•จ, varispeed์˜ ๊ฒฝ์šฐ ๊ณ„์‚ฐ๋Ÿ‰์€ ์ค‘๊ฐ„์ด์ง€๋งŒ pitch correction ์ด ๋น ์ ธ์„œ์ธ์ง€, ์ด์œ ๋Š” ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ ์ •์ƒ๋™์ž‘ ํ•จ. (composition ๊ตฌ์„ฑ์‹œ์— ์žฌ์ƒ์€ ์ž˜๋˜๋‚˜, export ๊ฐ€ ์•ˆ๋˜๋Š” ํ˜„์ƒ์ด ์žˆ์—ˆ์Œ)
  • ๊ธฐ๊ธฐ์—์„œ H.265 ์ง€์›ํ•˜๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ
let isHEVC = AVOutputSettingsAssistant.availableOutputSettingsPresets().contains(.hevc3840x2160)
    /* Sent when a download task that has completed a download.  The delegate should
     * copy or move the file at the given location to a new location as it will be
     * removed when the delegate message returns. URLSession:task:didCompleteWithError:
     * will still be called. */

    URLSession ์œผ๋กœ ํŒŒ์ผ์„ ๋ฐ›๊ณ  ๊ฒฐ๊ณผ delegate ๋‚ด์—์„œ ํŒŒ์ผ์„ ๋ณต์‚ฌํ•˜๊ฑฐ๋‚˜ ์ด๋™์‹œ์ผœ์•ผ์ง€, ํ•ด๋‹น delegate๊ฐ€ ์ข…๋ฃŒ๋˜๋ฉด ํŒŒ์ผ์ด ์‚ฌ๋ผ์ ธ๋ฒ„๋ฆฐ๋‹ค. 
    main.queue ์—์„œ ํ•ด๋‹น ์ž‘์—…์„ ํ•˜๋ ค๊ณ  ํ–ˆ๋”๋‹ˆ ๊ฐ€๋” ๋‹ค์šด๋ฐ›์€ ํŒŒ์ผ์ด ์‚ฌ๋ผ์ง€๋Š” ํ˜„์ƒ์ด ์žˆ์–ด์„œ ์ˆ˜์ •ํ–ˆ์—ˆ๋‹ค.;;;
โš ๏ธ **GitHub.com Fallback** โš ๏ธ