public protocol UploadDelegate: AnyObject {}
class NetworkManager: UploadDelegate {}
class A {
B().abc(uploadDelegate:NetworkManager() )
}
class B {
func abc (uploadDelegate: UploadDelegate) {
C().efg(uploadDelegate:uploadDelegate )
}
}
class C {
func efg (uploadDelegate: UploadDelegate) {
D().hij(uploadDelegate:uploadDelegate )
}
}
class D {
func hij (uploadDelegate: UploadDelegate) {
uploadDelegate.func()
}
}
Can we pass the protocol/delegate as a func parameter? If yes, I believe its a weak property.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
class a {
b().download ({ data in
})
}
class b{
func download (downloadedData: @escaping (_ data: Data? ) -> Void ) {
c().download()
}
}
class c {
func download () -> Data {
let semaphore = DispatchSemaphore(value: 0)
NetworkManager().downloadRequest: { (result: Result<Data, Error>) in
switch result {
case .success(let success)
......
case .failure(let error):
.....
}
semaphore.signal()
}
)
semaphore.wait()
return data
}
}
Class a initiates the download and class c interacts with network manager to download the data. Class c issues semaphore wait as soon as it sends request to download the data and issues signal when download completes. Is there a way to issue signal from class a when download is in progress. Basically class a should be able to skip wait by issuing signal command
I am trying to localize Swift framework and added a file Localizable.Strings and that file is included in the target but the app that consumes this framework is showing the key not the actual string.
NSLocalizedString("string_key", comment: "Actual String")
I think issue is related to bundle.
Do I need to add bundle parameter to NSLocalizedString? If so what is the bundle parameter value? If bundle is not required then what must be the issue
I am using "Excluded Source File Names" in Xcode build settings to remove a folder from IPA. The given relative path is correct but for some reason, the folder that needs to be excluded is still exists in the .app file. Any idea why Excluded Source File Names is not working. The folder that I am trying to remove is listed under "Copy Bundle Resources"
Here is the path "$(SRCROOT)/../foldera/folderb/foldertoberemoved"
class A {
func processData {
let viewModel: ViewModal = ViewModal()
let viewController = ViewController()
viewController.displayUI(viewModel)
....
....
....
....
viewModel.imageName = "abcd"
....
....
....
....
viewModel.imageName = "efg"
....
....
....
....
viewModel.imageName = "hij"
}
}
class ViewController {
func displayUI (viewModal: ViewModal){
let contentView = ContentView(viewModal: viewModal).environmentObject(self)
// present contentView
}
}
class ViewModal {
@Published var imageName: String = ""
@Published var label: String = ""
// string formatting
}
struct ContentView: View {
@State var viewModel: ViewModal
@EnvironmentObject var viewController: ViewController
var body: some View {
}
}
Can class A directly access ViewModal or it should pass the data to ViewController and ViewController set the data in ViewModal
func displayUI () {
let hostingController = UIHostingController(rootView: ContentView(ViewModel: contentViewModal).environmentObject(self))
}
Above code works fine.
I attempted to make the hostingController as instance variable instead of local variable and declared the hostingController outside of display function like this
lazy var hostingController: UIHostingController = UIHostingController(rootView: ContentView())
and so I removed let keyword
func displayUI () {
hostingController = UIHostingController(rootView: ContentView(ViewModel: contentViewModal).environmentObject(self))
}
Once I remove the let keyword I started getting this error.
Cannot convert value of type 'some View' to specified type ‘ContentView'
Any idea why I am getting this error after removing let keyword declared before hostingController variable?
I wrote a few unit test cases using XCTest by mocking the data? Is there any best practice to have multiple test profiles with different data sets? Sometime mock should return nil, sometimes an array with 2 elements and sometimes an array with 10 elements. How to have multiple test profiles?
Topic:
Developer Tools & Services
SubTopic:
Instruments
Tags:
Instruments
XCTest
Testing
Continuous Integration
Is there a way to mock the CBPeripheral? I need to stub the CBPeripheral(name & identifier) data in Xcode.
I believe weak references are not required when using self inside the dispatch queues. Is there any other occasions where weak self is not required related to closure?
I have declared an NSMutableArray and the count should not exceed 100. If some one calls addObject method to add an item to that array when the count is 100 then that method call should not be executed until someone removes an item so that count will go down below 100. Can we use semaphore or group dispatch for signaling or mutex/NSLock is recommended.
How to make one task(insert) wait for another to task(remove) in Objective C?
What is the best way to print in the order for the given implementation
(void) print:(NSString*) str
while(true)
{
NSLog(@“%@”, str);
}
}
[self print:@“123”];
[self print:@“ABC”];
[self print:@“456”];
[self print:@“DEF”];
output should be printing in the order continuously
123
ABC
456
DEF
123
ABC
456
DEF
…
…
…
I linked a framework as optional/weak and it's working fine in the latest Xcode but in the older Xcode version compilation is failing due to "framework not found". Is there a way to fix the compilation error in the older Xcode version?
My client is using Xcode 11 but the iOS framework imported in the project is available only in Xcode 13. Client is getting "framework not found" in Xcode 11 . Is there a way to make my project compatible with older Xcode Version?
Xcode is not responding when opening a workspace. I deleted the cache, derived data, saved application state and xcuserdata. I tried with different Xcode version too.
Any help is much appreciated.