One of the problems seems to be related to the “extension” keyword (my guess) so I have uploaded a new Promise class that have all in the Promise and Defer classes here:
Since I have those two there seems to be bridged from ObjC
/**
* Begin synchronizing on 'obj'.
* Allocates recursive pthread_mutex associated with 'obj' if needed.
*
* @param obj The object to begin synchronizing on.
*
* @return OBJC_SYNC_SUCCESS once lock is acquired.
*/
@available(iOS 2.0, *)
public func objc_sync_enter(obj: AnyObject!) -> Int32
/**
* End synchronizing on 'obj'.
*
* @param obj The objet to end synchronizing on.
*
* @return OBJC_SYNC_SUCCESS or OBJC_SYNC_NOT_OWNING_THREAD_ERROR
*/
@available(iOS 2.0, *)
public func objc_sync_exit(obj: AnyObject!) -> Int32
Yes, objc_sync* should work fine, compiles (no need to DEFINE those functions) and ends up generating correct code like :
func sync(lock, block)
var tmpresult: Foundation.NSObject = nil;
objc_sync_enter(lock)
var t1 = objc_retainAutoreleasedReturnValueblock());
objc_storeStrong(tmpresult, t1)
objc_release(t1)
return objc_autoreleaseReturnValue(tmpresult)
}
And yes, I did notice it has to do with the extension, I fixed the exception but there’s an underlying cause for this I need to solve before the issue is closed.
@ck Thanks! I have removed the extension and moved the class only instances. Now I’m into other errors, that seems to be language syntax (Swift 2.1) errors. Since they are of different kind (like No matching overload, Cannot instantiate interface type, Generic parameter cannot be resolved), I prefer to share the whole project.
Also it does not recognized the objc_sync_enter and objc_sync_exit (Unknown identifier error).
I have put the whole Fire project with the Shared Library and Android and iOS targets on github:
Note that the Promise.swift source compiles and run in Xcode as-it-is. To check this, I have added the Xcode test project as well in this repository.
So you will have
StaticLibrary: A Fire project with the Shared Library, Android and iOS targets
CrossTest: A Xcode (7.1.1 / Swift 2.1) project, to test the Swift library and the swift sources (for syntax and semantics checks, like for Promise.swift)
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Library.swift(34,16): error E287: Syntax error
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Library.swift(34,16): error E1: closing bracket expected, got closing parenthesis
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Library.swift(2,8): error E26: Unknown namespace "Promise" in uses list
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Library.swift(19,17): error E44: No member "" on type "Promise"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Library.swift(28,11): error E406: No overloaded method "then" with these parameters on type "Promise!", best matching overload is "then(_ then: Promise!.thenClosureNoReturn) -> Promise"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(76,32): error E44: No member "map" on type "Iterable<Promise>!"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(148,3): error E121: Cannot instantiate interface type "Action2<Action1<AnyObject?>!,Action1<AnyObject?>!>!"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(156,8): error E406: No overloaded method "then" with these parameters on type "Promise!", best matching overload is "then(_ then: Promise!.thenClosureNoReturn) -> Promise"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(211,3): error E46: Unknown identifier "objc_sync_enter"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(213,4): error E46: Unknown identifier "objc_sync_exit"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(218,3): error E46: Unknown identifier "objc_sync_enter"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(220,4): error E46: Unknown identifier "objc_sync_exit"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(233,32): error E44: No member "enumerate" on type "swift.Array<Promise!.thenClosure>!"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(268,9): error E105: Member "cat" on type "Promise" is a property but is used as a method
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(276,8): error E105: Member "fin" on type "Promise" is a property but is used as a method
sorry, let’s start with those 10, since the others dependes on import Promise failing module:
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(76,32): error E44: No member "map" on type "Iterable<Promise>!"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(148,3): error E121: Cannot instantiate interface type "Action2<Action1<AnyObject?>!,Action1<AnyObject?>!>!"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(156,8): error E406: No overloaded method "then" with these parameters on type "Promise!", best matching overload is "then(_ then: Promise!.thenClosureNoReturn) -> Promise"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(211,3): error E46: Unknown identifier "objc_sync_enter"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(213,4): error E46: Unknown identifier "objc_sync_exit"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(218,3): error E46: Unknown identifier "objc_sync_enter"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(220,4): error E46: Unknown identifier "objc_sync_exit"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(233,32): error E44: No member "enumerate" on type "swift.Array<Promise!.thenClosure>!"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(268,9): error E105: Member "cat" on type "Promise" is a property but is used as a method
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(276,8): error E105: Member "fin" on type "Promise" is a property but is used as a method
1 Warning(s)
10 Error(s)
That makes sense. But we’re heading in the realm of platform differences then. I’m going to log an issue for cross platform locking based on any object in Silver (bugs://73939). Can’t promise how this is going to look yet though.
Ok thanks. In the meanwhile, I confirm that if I disable the “classlibrary2” project (That is the Java one), now I can load Foundation then I get few errors:
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(78,32): error E44: No member "map" on type "RemObjects.Elements.System.INSFastEnumeration<Promise>!"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(154,10): error E43: No static member "All" on type "Promise"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(158,8): error E406: No overloaded method "then" with these parameters on type "Promise!", best matching overload is "then(_ then: Promise!.thenClosureNoReturn) -> Promise"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(235,32): error E44: No member "enumerate" on type "Array<Promise!.thenClosure>!"
/Volumes/MacHDD2/Developmemt/ParisiLabs/swift-promise-example/StaticLibrary/SharedProject/Promise.swift(270,9): error E399: No overloaded method "cat" with 1 parameter on type "Promise!"
1 Warning(s)
5 Error(s)
Regarding the Promise module, we talk about the semaphore primitives, but given this (supposed I’m not going to use that), any other way to achieve a similar (workaround) solution for both Cocoa / Java ?
Other question is, all the other errors, due to language support, like this