I've just downloaded AudioKit most recent version (4.2.2). When I ran the build_frameworks.sh I get the following error:
[AVAudioUnit?]' has no member 'compactMap'
return _effectsChain.compactMap { $0 }
^~~~~~~~~~~~~ ~~~~~~~~~~
/Users/sky/Desktop/AudioKit-4.2.2/AudioKit/Common/Nodes/Mixing/Mixer/AKMixer.swift:40:19: error: value of type '[AKNode?]' has no member 'compactMap'
self.init(inputs.compactMap { $0 })
^~~~~~ ~~~~~~~~~~
/Users/sky/Desktop/AudioKit-4.2.2/AudioKit/Common/Internals/AudioKitHelpers.swift:22:16: error: cannot invoke 'index' with an argument list of type '(Self.Index, offsetBy: Int)'
return index(startIndex, offsetBy: offset)
^
/Users/sky/Desktop/AudioKit-4.2.2/AudioKit/Common/Internals/AudioKitHelpers.swift:22:16: note: expected an argument list of type '(Self.Index, offsetBy: Self.IndexDistance)'
return index(startIndex, offsetBy: offset)
^
/Users/sky/Desktop/AudioKit-4.2.2/AudioKit/Common/Internals/CoreAudio/AudioUnit+Helpers.swift:101:29: error: missing argument for parameter 'capacity' in call
data.deallocate()
^
capacity: <#Int#>
Swift.UnsafeMutablePointer:273:17: note: 'deallocate(capacity:)' declared here
public func deallocate(capacity: Int)
^
/Users/sky/Desktop/AudioKit-4.2.2/AudioKit/Common/Nodes/Effects/Reverb/Convolution/AKConvolution.swift:144:41: error: missing argument for parameter 'capacity' in call
theData?.deallocate()
^
capacity: <#Int#>
Swift.UnsafeMutablePointer:273:17: note: 'deallocate(capacity:)' declared here
public func deallocate(capacity: Int)
^
/Users/sky/Desktop/AudioKit-4.2.2/AudioKit/Common/Nodes/Playback/Phase-Locked Vocoder/AKPhaseLockedVocoder.swift:226:41: error: missing argument for parameter 'capacity' in call
theData?.deallocate()
^
capacity: <#Int#>
Swift.UnsafeMutablePointer:273:17: note: 'deallocate(capacity:)' declared here
public func deallocate(capacity: Int)
^
/Users/sky/Desktop/AudioKit-4.2.2/AudioKit/Common/Nodes/Effects/AudioKit Operation-Based Effect/AKOperationEffect.swift:28:17: error: value of type '[NSNumber]' has no member 'compactMap'
$0.compactMap { $0.doubleValue }
^~ ~~~~~~~~~~
I tried to copy the AudioKit source code into the project I was testing: AudioKit's HelloWorld project. In this case I have the following error on XCode:
/Users/sky/Desktop/AudioKit-4.2.2/AudioKit/Common/Internals/AudioUnit Host/AKAudioUnitManager.swift:140:16: Value of type '[AVAudioUnit?]' has no member 'compactMap'
The error is thrown on source code file AKAudioUnitManager.swift on the method below:
private var linkedEffects: [AVAudioUnit] {
return _effectsChain.compactMap { $0 }
}
Also, playground is not working even with compiled framework.
I use MacOS Sierra, XCode 9.2, Swift 4, iOS 9.2.
Thanks!
Related
I have following .ts files
core.ts
interface Signature {
args: string[];
ret?: string;
}
const subject = 'hook'
const now = () => (new Date()).getTime()
const readable = (type: string, arg: NativePointer) => (type === 'char *' ? arg.readUtf8String() : arg)
export function hook(mod: string | null, symbol: string, signature: Signature) {
const p = Module.findExportByName(mod, symbol)
if (!p) throw new Error(`Function ${mod || 'global'}!${symbol} not found`)
const range = Process.findRangeByAddress(p)
if (!range?.protection.includes('x')) throw new Error('Invalid symbol, expected a function but received a data pointer')
const id = p.toString()
const lib = mod || Process.getModuleByAddress(p)!.name
const listener = Interceptor.attach(p, {
onEnter(args) {
const time = now()
const pretty = signature.args.map((type, i) => readable(type, args[i]))
const backtrace = Thread.backtrace(this.context, Backtracer.ACCURATE)
.map(DebugSymbol.fromAddress).filter(e => e.name)
this.backtrace = backtrace
send({
subject,
event: 'call',
args: pretty,
lib,
symbol,
backtrace,
time
})
},
onLeave(retVal) {
if (!signature.ret) return
const time = now()
const ret = readable(signature.ret, retVal)
send({
subject,
event: 'return',
lib,
symbol,
time,
backtrace: this.backtrace,
ret
})
}
})
return listener
}
sql-hooks.ts
// import { hook } from './core'
const { hook } = require('./core.ts')
ObjC.schedule(ObjC.mainQueue, function () {
enable()
});
function enable() {
console.log('enabled')
hook('libsqlite3.dylib', 'sqlite3_open', { args: ['char *', 'int'], ret: 'int' })
hook('libsqlite3.dylib', 'sqlite3_prepare_v2', { args: ['pointer', 'char *', 'int', 'pointer', 'pointer'] })
hook('libsqlite3.dylib', 'sqlite3_bind_int', { args: ['pointer', 'int', 'int'] })
hook('libsqlite3.dylib', 'sqlite3_bind_null', { args: ['pointer', 'int'] })
hook('libsqlite3.dylib', 'sqlite3_bind_text', { args: ['pointer', 'int', 'char *', 'int', 'pointer'] })
}
Then I used following command to connect these two files
frida-compile '/path/to/sql-hooks.ts' -o out.ts
Finally I used following command to actually use out.ts
frida -U -F -l '/path/to/out.ts'
But unfortunately I get this error
out.ts:1:1 - error TS1127: Invalid character.
out.ts:2:6 - error TS2304: Cannot find name 'sql'.
out.ts:2:10 - error TS2552: Cannot find name 'hooks'. Did you mean 'hook'?
out.ts:3:6 - error TS2304: Cannot find name 'sql'.
out.ts:3:10 - error TS2552: Cannot find name 'hooks'. Did you mean 'hook'?
out.ts:4:1 - error TS1127: Invalid character.
out.ts:5:11 - error TS1005: ';' expected.
out.ts:5:12 - error TS2695: Left side of comma operator is unused and has no side effects.
out.ts:5:20 - error TS1005: ';' expected.
out.ts:5:21 - error TS2695: Left side of comma operator is unused and has no side effects.
out.ts:5:48 - error TS1005: ';' expected.
out.ts:5:49 - error TS2695: Left side of comma operator is unused and has no side effects.
out.ts:5:105 - error TS1005: ';' expected.
out.ts:5:106 - error TS2695: Left side of comma operator is unused and has no side effects.
out.ts:5:130 - error TS1005: ';' expected.
out.ts:5:131 - error TS2695: Left side of comma operator is unused and has no side effects.
out.ts:5:144 - error TS1005: ';' expected.
out.ts:6:1 - error TS1127: Invalid character.
What am I doing wrong?
I bumped into a frida-compile example (from oleavr) and I found out I was doing a couple of things wrong. In particular I took a look at the agent folder and at the package.json scripts region.
I'm going to mention two files: sql-hooks.ts (which is my main.ts) and core.ts (which is my module.ts); both of them are inside the same folder.
I changed first line of sql-hooks.ts from
const { hook } = require('./core.ts')
to
import { hook } from './core.js'
Notice I imported core.ts as a .js
Then I used following command to connect sql-hooks.ts and core.ts
frida-compile '/path/to/sql-hooks.ts' -o out.js
Notice output extension is .js
And that's it, everything's gonna work fine.
this is my debug log
Automatically signing iOS for device deployment using specified development team in Xcode
project: P7NL527WV9
Running Xcode build...
Xcode build done. 75.6s
Failed to build iOS app
Error output from Xcode build:
↳
** BUILD FAILED **
Xcode's output:
↳
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter_wkwebview-2.
7.1/ios/Classes/FlutterWebView.m:575:23: warning: 'requiresUserActionForMediaPlayback' is
deprecated: first deprecated in iOS 10.0 [-Wdeprecated-declarations]
configuration.requiresUserActionForMediaPlayback = true;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mediaTypesRequiringUserActionForPlayback
In module 'WebKit' imported from
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter_wkwebview-2.
7.1/ios/Classes/FlutterWebView.h:6:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneO
S14.0.sdk/System/Library/Frameworks/WebKit.framework/Headers/WKWebViewConfiguration.h:213:28:
note: 'requiresUserActionForMediaPlayback' has been explicitly marked deprecated here
#property (nonatomic) BOOL requiresUserActionForMediaPlayback
API_DEPRECATED_WITH_REPLACEMENT("mediaTypesRequiringUserActionForPlayback", ios(9.0, 10.0));
^
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter_wkwebview-2.
7.1/ios/Classes/FlutterWebView.m:587:23: warning: 'requiresUserActionForMediaPlayback' is
deprecated: first deprecated in iOS 10.0 [-Wdeprecated-declarations]
configuration.requiresUserActionForMediaPlayback = false;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mediaTypesRequiringUserActionForPlayback
In module 'WebKit' imported from
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter_wkwebview-2.
7.1/ios/Classes/FlutterWebView.h:6:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneO
S14.0.sdk/System/Library/Frameworks/WebKit.framework/Headers/WKWebViewConfiguration.h:213:28:
note: 'requiresUserActionForMediaPlayback' has been explicitly marked deprecated here
#property (nonatomic) BOOL requiresUserActionForMediaPlayback
API_DEPRECATED_WITH_REPLACEMENT("mediaTypesRequiringUserActionForPlayback", ios(9.0, 10.0));
^
2 warnings generated.
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter_wkwebview-2.
7.1/ios/Classes/FlutterWebView.m:575:23: warning: 'requiresUserActionForMediaPlayback' is
deprecated: first deprecated in iOS 10.0 [-Wdeprecated-declarations]
configuration.requiresUserActionForMediaPlayback = true;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mediaTypesRequiringUserActionForPlayback
In module 'WebKit' imported from
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter_wkwebview-2.
7.1/ios/Classes/FlutterWebView.h:6:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneO
S14.0.sdk/System/Library/Frameworks/WebKit.framework/Headers/WKWebViewConfiguration.h:213:28:
note: 'requiresUserActionForMediaPlayback' has been explicitly marked deprecated here
#property (nonatomic) BOOL requiresUserActionForMediaPlayback
API_DEPRECATED_WITH_REPLACEMENT("mediaTypesRequiringUserActionForPlayback", ios(9.0, 10.0));
^
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter_wkwebview-2.
7.1/ios/Classes/FlutterWebView.m:587:23: warning: 'requiresUserActionForMediaPlayback' is
deprecated: first deprecated in iOS 10.0 [-Wdeprecated-declarations]
configuration.requiresUserActionForMediaPlayback = false;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mediaTypesRequiringUserActionForPlayback
In module 'WebKit' imported from
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter_wkwebview-2.
7.1/ios/Classes/FlutterWebView.h:6:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneO
S14.0.sdk/System/Library/Frameworks/WebKit.framework/Headers/WKWebViewConfiguration.h:213:28:
note: 'requiresUserActionForMediaPlayback' has been explicitly marked deprecated here
#property (nonatomic) BOOL requiresUserActionForMediaPlayback
API_DEPRECATED_WITH_REPLACEMENT("mediaTypesRequiringUserActionForPlayback", ios(9.0, 10.0));
^
2 warnings generated.
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/SafariViewController/SafariBrowserOptions.swift:34:16: warning: unnecessary check
for 'iOS'; enclosing scope ensures guard will always be true
if #available(iOS 10.0, *) {
^
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/SafariViewController/SafariBrowserOptions.swift:12:14: note: enclosing scope here
public class SafariBrowserOptions: Options<SafariViewController> {
^
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/SafariViewController/SafariViewController.swift:66:12: warning: unnecessary check
for 'iOS'; enclosing scope ensures guard will always be true
if #available(iOS 10.0, *) {
^
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/SafariViewController/SafariViewController.swift:12:14: note: enclosing scope here
public class SafariViewController: SFSafariViewController, FlutterPlugin,
SFSafariViewControllerDelegate {
^
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/InAppBrowser/InAppBrowserWebViewController.swift:557:13: warning: setter for
'statusBarStyle' was deprecated in iOS 9.0: Use -[UIViewController preferredStatusBarStyle]
UIApplication.shared.statusBarStyle = UIStatusBarStyle(rawValue:
previousStatusBarStyle)!
^
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/InAppWebView/InAppWebView.swift:695:34: error: value of type 'WKPDFConfiguration'
has no member 'rect'
pdfConfiguration.rect = CGRect(x: rect["x"]!, y: rect["y"]!, width:
rect["width"]!, height: rect["height"]!)
~~~~~~~~~~~~~~~~ ^~~~
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/InAppWebView/InAppWebView.swift:698:9: error: cannot find 'createPDF' in scope
createPDF(configuration: pdfConfiguration) { (result) in
^~~~~~~~~
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/InAppWebView/InAppWebView.swift:713:29: error: incorrect argument label in call
(have 'completionHandler:', expected 'dataCompletionHandler:')
createWebArchiveData(completionHandler: { (result) in
^~~~~~~~~~~~~~~~~~
dataCompletionHandler
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/InAppWebView/InAppWebView.swift:1237:33: error: extra arguments at positions #2,
#3 in call
super.evaluateJavaScript(javaScript, in: frame, in: contentWorld, completionHandler:
completionHandler)
^
WebKit.WKWebView:46:15: note: 'evaluateJavaScript(_:completionHandler:)' declared here
open func evaluateJavaScript(_ javaScriptString: String, completionHandler: ((Any?,
Error?) -> Void)? = nil)
^
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/InAppWebView/InAppWebView.swift:1237:94: error: cannot convert value of type
'((Result<Any, Error>) -> Void)?' to expected argument type '((Any?, Error?) -> Void)?'
super.evaluateJavaScript(javaScript, in: frame, in: contentWorld, completionHandler:
completionHandler)
^
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/InAppWebView/InAppWebView.swift:1254:15: error: value of type 'WKWebView' has no
member 'callAsyncJavaScript'
super.callAsyncJavaScript(functionBody, arguments: arguments, in: frame, in:
contentWorld, completionHandler: completionHandler)
~~~~~ ^~~~~~~~~~~~~~~~~~~
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/SafariViewController/SafariBrowserOptions.swift:34:16: warning: unnecessary check
for 'iOS'; enclosing scope ensures guard will always be true
if #available(iOS 10.0, *) {
^
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/SafariViewController/SafariBrowserOptions.swift:12:14: note: enclosing scope here
public class SafariBrowserOptions: Options<SafariViewController> {
^
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/SafariViewController/SafariViewController.swift:66:12: warning: unnecessary check
for 'iOS'; enclosing scope ensures guard will always be true
if #available(iOS 10.0, *) {
^
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/SafariViewController/SafariViewController.swift:12:14: note: enclosing scope here
public class SafariViewController: SFSafariViewController, FlutterPlugin,
SFSafariViewControllerDelegate {
^
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/Types/URLCredential.swift:14:25: warning: comparing non-optional value of type
'[Any]' to 'nil' always returns true
if certificates != nil {
~~~~~~~~~~~~ ^ ~~~
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/Util.swift:86:25: warning: 'spotlightSuggestion' was deprecated in iOS 10.0:
renamed to 'WKDataDetectorTypes.lookupSuggestion'
return .spotlightSuggestion
^
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/Util.swift:86:25: note: use 'WKDataDetectorTypes.lookupSuggestion' instead
return .spotlightSuggestion
^~~~~~~~~~~~~~~~~~~
WKDataDetectorTypes.lookupSuggestion
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/Util.swift:121:31: warning: 'spotlightSuggestion' was deprecated in iOS 10.0:
renamed to 'WKDataDetectorTypes.lookupSuggestion'
if type.contains(.spotlightSuggestion) {
^
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/Util.swift:121:31: note: use 'WKDataDetectorTypes.lookupSuggestion' instead
if type.contains(.spotlightSuggestion) {
^~~~~~~~~~~~~~~~~~~
WKDataDetectorTypes.lookupSuggestion
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_inappwebview-5.3.2/i
os/Classes/Util.swift:216:21: warning: immutable value 'j' was never used; consider replacing
with '_' or removing it
for j in ipv6.count...8 {
^
_
Command CompileSwift failed with a nonzero exit code
note: Using new build system
note: Building targets in parallel
note: Planning build
note: Constructing build description
Encountered error while building for device.
These are the plugins/packages used in the code
flutter_remix: ^0.0.3
flutter_vector_icons: ^1.0.0
Firebase
firebase_core: ^1.1.0
firebase_auth: ^3.0.0
firebase_messaging: ^11.2.6
firebase_in_app_messaging: ^0.6.0+7
cloud_firestore: ^3.1.7
firebase_storage: ^10.2.6
State Management
get: ^4.1.4
get_storage: ^2.0.2
Fonts
google_fonts: ^2.1.0
User Interface
statusbarz: ^1.0.2
lottie: ^1.0.1
flutter_hud: ^0.3.0
multiavatar: ^0.1.5
flutter_svg: ^0.22.0
carousel_slider: ^4.0.0-nullsafety.0
octo_image: ^1.0.0+1
cached_network_image: ^3.0.0
dropdown_search: ^2.0.1
shimmer: ^2.0.0
animated_background: ^2.0.0
image_picker_type: ^1.0.1
flutter_gradient_colors: ^2.0.0-prerelease-nullsafety
flutter_shimmer: ^2.0.0-prerelease-nullsafety
draggable_home: ^1.0.2
timelines: ^0.1.0
syncfusion_flutter_pdfviewer: ^19.2.47-beta
Utils
random_string_generator: ^2.0.0
path_provider: ^2.0.2
image: ^3.0.2
jiffy: ^5.0.0
url_launcher: ^6.0.7
package_info: ^2.0.2
flutter_contact: ^0.9.1+8
permission_handler: ^8.1.2
contactor_picker: ^0.0.4
flutter_native_contact_picker: ^0.0.3
nanoid: ^1.0.0
share_plus: ^3.0.4
package_info_plus: ^1.0.5
crisp: ^0.3.1
Gateway
flutter_paystack: ^1.0.5+1
flutterwave: ^1.0.1
nravepay: ^1.0.5+1
Seems to be a problem with an included dependency.
module 'WebKit' imported from
/Users/bhbj/Downloads/flutter/.pub-cache/hosted/pub.dartlang.org/webview_flutter_wkwebview-2.
7.1/ios/Classes/FlutterWebView.h
Maybe you have imported a PDF webview package that is not compatible with iOS, or you need permissions to use it, normally you can add them in Info.plist file.
Are vala enums not integer based? This example generates a "c" compile error. Not a big deal, but would like to understand why.
const int INT_UNINITIALIZED = 999;
public enum ScopeTypes {
/*OSS:Fix:GLib requires a default value, set GLOBALS = 0
(VSCodeDbgSvr.exe:31979): GLib-GObject-CRITICAL **: g_param_spec_enum: assertion 'g_enum_get_value (enum_class, default_value) != NULL' failed*/
NONE = INT_UNINITIALIZED,
GLOBALS = 0,
ARGUMENTS,
LOCALS,
EXCEPTIONS,
TOT_SCOPE_TYPES;
//Vala enums may have methods:
public bool is_global() {
return (this == GLOBALS || this == EXCEPTIONS);
}
public bool is_function() {
return (this == ARGUMENTS || this == LOCALS);
}
public bool is_valid() {
return (this != NONE);
}
}
The compile output:
> Executing task: /opt/vala/bin/valac helloworld.vala class1.vala --pkg libvala-0.40 -X -I/opt/vala/include/vala-0.40 -X -O0 --vapidir=/opt/vala/share/vala/vapi --debug --save-temps -o helloworld.exe <
/media/george/SharedData/Projects/Vala/Examples/playground-2/helloworld.c:82:21: error: ‘INT_UNINITIALIZED’ undeclared here (not in a function)
SCOPE_TYPES_NONE = INT_UNINITIALIZED,
^~~~~~~~~~~~~~~~~
error: cc exited with status 256
Compilation failed: 1 error(s), 1 warning(s)
The terminal process terminated with exit code: 1
The relevant part of the error message is:
error: ‘INT_UNINITIALIZED’ undeclared here (not in a function)
The C compiler is complaining that it can not find the declaration of your constant. So it is not a type problem at all.
It is a scope / ordering problem.
If you compile the code with valac -C you get a .c file that looks something like this:
typedef enum {
SCOPE_TYPES_NONE = INT_UNINITIALIZED,
SCOPE_TYPES_GLOBALS = 0,
SCOPE_TYPES_ARGUMENTS,
SCOPE_TYPES_LOCALS,
SCOPE_TYPES_EXCEPTIONS,
SCOPE_TYPES_TOT_SCOPE_TYPES
} ScopeTypes;
#define INT_UNINITIALIZED 999
Note how the Vala compiler has reordered the code to declare the enum first and the constant later.
Since in C the order of declarations in a file is important this can not compile.
I would consider this to be a compiler bug and you may want to report this to the GNOME bugtracker (product Vala).
I am integrating with a C library - liblinphone. It has the following typedef and function I need to call from my Swift 3 iOS app.
typedef void (*OrtpLogFunc)(const char *domain,
int lev,
const char *fmt,
va_list args);
void linphone_core_set_log_handler(OrtpLogFunc logfunc);
It appears that Swift is interpreting va_list differently when compiling for the simulator than when compiling for a device.
Here is the Swift code that uses the C function and
This compiles only when the target is the Device:
class MyClass {
func setupLogging() {
linphone_core_set_log_handler(my_callback)
}
}
func my_callback(_ domain: Optional<UnsafePointer<Int8>>,
level: OrtpLogLevel,
format: Optional<UnsafePointer<Int8>>,
args: CVaListPointer?) { // NOTE: Optional CVAListPointer
// do some logging
}
This compiles only when the target is the Simulator:
class MyClass {
func setupLogging() {
linphone_core_set_log_handler(my_callback)
}
}
func my_callback(_ domain: Optional<UnsafePointer<Int8>>,
level: OrtpLogLevel,
format: Optional<UnsafePointer<Int8>>,
args: CVaListPointer) { // NOTE: CVAListPointer is NOT optional
// do some logging
}
When I run on the device, logging works, so it appears that using the optional CVaListPoint? is the safest, so how do I get this to compile for the simulator.
The first version only compiles and runs on a device but issues this compiler error when targeting the simulator:
Swift Compiler Error
C function pointer signature
'(Optional<UnsafePointer<Int8>>, OrtpLogLevel,
Optional<UnsafePointer<Int8>>, CVaListPointer?) -> ()'
is not compatible with expected type 'OrtpLogFunc' (aka
'#convention(c)
(Optional<UnsafePointer<Int8>>, OrtpLogLevel,
Optional<UnsafePointer<Int8>>, CVaListPointer) -> ()')
The second version only compiles when targeting the simulator, but when targeting a device, it issues this error:
Swift Compiler Error
Cannot convert value of type
'(Optional<UnsafePointer<Int8>>, OrtpLogLevel,
Optional<UnsafePointer<Int8>>, CVaListPointer) -> ()'
to expected argument type 'OrtpLogFunc!'
Is there some way I can force the simulator to accept this function without changing the C headers?
Or, is there something I can do in Swift to make this work?
You'd better send a bug report to Apple or swift.org as soon as possible.
And, until this issue will be fixed, this sort of coding would be a workaround:
let my_callback: OrtpLogFunc = {domain, level, format, _args in
let args: CVaListPointer? = _args
// do some logging
}
Is there any logtrace equivalent in Swift language?
I do not wish to use the bridge-header concept.
The objective I'm trying to achieve is that I want println statements to write to console during dev/staging phase of the app and with the flip of a switch, console printing should be stopped just before pushing to app store.
On another thought-line, does println automatically stop printing on the console during distribution? (may be a bonus of migrating to Swift)
You could take a similar approach as the built-in assert() function, which is
explained in the Swift blog:
Building assert() in Swift, Part 1: Lazy Evaluation
Building assert() in Swift, Part 2: FILE and LINE
The logTrace function takes an "auto-closure" as the first argument:
func logTrace(message: #autoclosure () -> String, file: StaticString = __FILE__, line: UWord = __LINE__) {
#if DEBUG
let msg = message()
println("\(file):\(line): \(msg)")
#endif
}
Example usage:
let height = 13
logTrace ( "height = \(height)" )
// Output: /Users/.../main.swift:14: height = 13
To make this work you have to add "-DDEBUG" to the "Other Swift Flags" for the
debug configuration, compare
In absence of preprocessor macros, is there a way to define practical scheme specific flags at project level in Xcode project.
The advantage of this method is that (as with assert()) the block is not
evaluated at all in the Release configuration, where "DEBUG" is not defined, e.g. in
logTrace ( someFunctionReturningAString() )
the function would not be called in the Release configuration, so any side-effects
or performance overhead is avoided.
Update for Swift 2:
func logTrace(#autoclosure message: () -> String, file: String = __FILE__, line: Int = __LINE__) {
#if DEBUG
let msg = message()
print("\(file):\(line): \(msg)")
#endif
}
Update for Swift 3:
func logTrace(_ message: #autoclosure () -> String, file: String = #file, line: Int = #line) {
#if DEBUG
let msg = message()
print("\(file):\(line): \(msg)")
#endif
}