swift framework: code changed and the built framework not update? - swift

Environment: mac OS, Catalina, I tried on iOS simulator
AudioKit framework's structure is like this
I added the following code , rebuild the xcode target, and the change is not updated in the new framework
// see the right channel data
public class Table: NSObject, MutableCollection, Codable {
public
convenience init?(rhs file: AVAudioFile) {
let size = Int(file.length)
self.init(count: size)
guard let data = file.toFloatChannelData() else { return nil }
for i in 0 ..< size {
self[i] = data[1][i]
}
}
}
I have tried Product -> Clear Build folder , both on target AudioKit and Cookbook
I have tried Product -> Clear Build folder , and put alt, on both
I have tried to quit Xcode , and reboot MBP
Still not work.
How to update the swift framework.

Related

Create a Flutter plugin in swift to export realm data

We have a native iOS app that has a Realm database. Now we have developed a new Flutter app that will substitute the native iOS app. When an user upgrade native iOS app to the new Flutter app, we want to migrate the existing Realm database content into the new Sqflite database.
We have created a Flutter plugin with swift to export Realm data to json. At the moment, we were able to add RealmSwift dependency to the plugin, but when we run the below code, it throws Cannot find 'DeviceModel' in scope.
Any idea to get all rows from DeviceModel table? To acomplish that is necesary to add some Realm schema manually?
import Flutter
import UIKit
import RealmSwift
enum PluginError: Error {
case notImplemented
}
public class SwiftRealmToJsonPlugin: NSObject, FlutterPlugin {
public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(name: "realm_to_json", binaryMessenger: registrar.messenger())
let instance = SwiftRealmToJsonPlugin()
registrar.addMethodCallDelegate(instance, channel: channel)
}
public func handle(_ call: FlutterMethodCall, result: #escaping FlutterResult) {
switch call.method {
case "getPlatformVersion":
result("iOS " + UIDevice.current.systemVersion)
case "realmInfoExist":
result(check_data())
default:
result(FlutterMethodNotImplemented)
}
}
// check if Realm exists
func check_data() -> Bool {
let realm = try! Realm()
let devices = realm.objects(DeviceModel.self)
}
}
The solution was:
Change plugin language from Swift to Objective-C and copy and paste all Realm models.
Implement in each model class a method to generate a dictionary with it data.
Export dictionary to json.
Right now we are able to export Realm info into a json format. Next step is implement the migration logic to adapt a table-less structure to sql.
Thanks to #Jay to point me out on the good direction to get a solution.

Trying to figure out Swift Clients for Thrift

I want to utilize thrift from within my new MacOS App. The app is working fine so far as a menubar app.. it takes in a string and lets you save it to memory somewhere... if you click on the clipboard button it saves your string to clipboard.
What I do not understand is.. if I've generated some Swift Client code via the
thrift --gen swift <name_of_thrift_file.thrift>
I get two .swift files, as expected.. AND instructions from the github to rig up the Client object.. here's my Client Object so far.. but I am seeing a error already with the example code. I want to add a status button to the menubar app (anywhere) .. which calls my thrift server for a ping() and goes green once response looks good.
Targeting : Mac OS 12.x+
Thrift Version : v0.16.0
XCode Version : 13.x
happily I hand rolled the library (Thrift) into my project.. for some reason I think the package mangement didn't work.. once added it was a breeze to generate my .thrift files
thrift --gen swift <my_thrift_service>.thrift
once I buttoned all that together in XCode.. the last part was getting a client that worked.. the example in git was showing an error but I got past it with this
AWSBotor3ThriftClient.swift
import Foundation
class AWSBoto3ThriftClient {
var boto3_thrift_client :aws_boto3_accessorClient?
var server_status :Int32
init() {
do {
let transport = try TSocketTransport(hostname: "localhost", port: 9090)
let proto = TBinaryProtocol(on: transport)
let client = aws_boto3_accessorClient(inoutProtocol: proto)
self.boto3_thrift_client = client
self.server_status = try self.boto3_thrift_client!.ping()
} catch {
print("init had a boo boo :(")
self.server_status = 333
self.boto3_thrift_client = nil
}
print(self.server_status)
}
}
S3SyncAppApp.swift
import SwiftUI
#main
struct S3SyncAppApp: App {
#NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
#State var currentNumber: String = "1"
var my_little_client: AWSBoto3ThriftClient = AWSBoto3ThriftClient()
var body: some Scene {
WindowGroup {
ContentView()
}
}
}

Content Previewer not loading on Xcode 12.5.1

I was working on a project the other day, and my preview stopped working. I got the error "Compiling Failed, cannot find "DataType" in scope" (all code/relationships will be shown below). I have restarted XCode a few times, and even commented out that area of code but it continues to not work, is anyone else having this problem and how can I fix it?
I am previewing a sheet called "Profile Sheet", just a standard swiftUI View, so the preview code looks like:
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ProfileSheet()
}
}
In the profile sheet, it is accessing data from a static function associated with my model file (different struct, different file), the functions it is using, and the ones that define "DataType", the problematic generic are here:
static func saveData<DataType>(data: DataType, for key: String) {
defaults.setValue(data, forKey: key)
}
static func retrieveData<DataType>(defaultValue: DataType, for key: String) -> DataType {
guard let value = defaults.value(forKey: key) as? DataType else {return defaultValue}
return value
}
static func saveComplexData<DataType>(data: DataType, for key: String) where DataType: Codable {
let encodedData = try! JSONEncoder().encode(data)
defaults.setValue(encodedData, forKey: key)
}
static func retrieveComplexData<DataType>(defaultValue: DataType, for key: String) -> DataType where DataType: Codable {
guard let retrievedData = defaults.value(forKey: key) as? Data else { return defaultValue}
let decodedData = try! JSONDecoder().decode(DataType.self, from: retrievedData)
return decodedData
}
all of these function as intended, and obviously compile. Even when I run to launch the previewer and compiles my app does it builder properly, its only when it is then trying to launch the preview simulator.
Finally, I thought Id remove those functions entirely and just try to display a View that has no connection to them, so I previewed Text("test") and got the same error.
on Xcode 13 beta 3 & 4 I am able to run the simulator, but I cannot work only on those betas as they are still fairly unstable.
Any help is appreciated :)
I've seen quite a bit of weird behavior with frameworks, I think due to changes to the simulators to support Apple silicon. My temporary workaround is, in my app/extension targets, to add "arm64" to the Excluded Architectures build setting when building for the simulator (as your preview appears to be trying to do), and setting "Build Active Architecture Only" to No for all schemes. Might be worth a try.
As per triplette in apple developer answers.
Try to check it out
https://developer.apple.com/forums/thread/657913
I believe it's not an issue with your code it's an issue with Xcode due to apple silicon macs. try to do a software update and reinstall the Xcode.

Swift debugQuickLookObject Xcode 12.4

I'm trying to test debugQuickLookObject I'm using Xcode 12.4 but the sample code given doesn't return a String in the QuickLook Debugger or the console, is debugQuickLookObject still valid?
class User {
var name = "Duane Dibbley"
var age = 28
#objc func debugQuickLookObject() -> Any? {
return "My name is \(name) and I'm \(age)."
}
}
I've tried inheriting from NSObject - no joy, I can't even confirm if the method signature is correct :-s
Code from here: https://www.hackingwithswift.com/example-code/language/how-to-create-quick-look-debug-previews-for-your-custom-types
I managed to get the code working, but only for iOS based projects, code can be found here:
https://github.com/nthState/RealityKitDebugger
I wish I knew why macOS based projects don't work as expected.

How to check app for compatibility with previous macOS versions?

My app works well in macOS 10.14, but breaks in macOS 10.13. How do I debug it in Xcode, having macOS 10.14 installed? Or at least how do I know what can go wrong, maybe there is some static code check?
I guess the problem could be in this code:
private static func isSystemDarkModeEnabled() -> Bool {
let global = UserDefaults.standard.persistentDomain(forName: UserDefaults.globalDomain)
let style = global!["AppleInterfaceStyle"]
if style != nil && (style as! String).lowercased() == "dark" {
return true
}
return false
}
private class SystemDarkModeChangeObserver {
static func register() {
SystemDarkModeChangeObserver.shared = SystemDarkModeChangeObserver()
}
private static var shared: SystemDarkModeChangeObserver?
private init() {
DistributedNotificationCenter.default().addObserver(self, selector: #selector(self.onChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil)
}
#objc func onChange() {
// ...
}
}
You can change the deployment target in the general project settings. Xcode should tell you what you're using that is not available in that target.
Xcode defaults to target the version installed on your development machine.
Please delete Derived Data,
You can go to File > Workspace Settings if you are in a workspace environment or File > Project Settings for a regular project environment. Then click over the little grey arrow under Derived data section and select your project folder to delete it.
if pod are used than deintegrate and reinstalling all pod files again.
Hope this works for you!