Post

Replies

Boosts

Views

Activity

Toll-free bridging
Assume this code is compiled under ARC: BOOL method(unsigned a) { NSString *string = [[NSString alloc] initWithCString:"hi"]; if (a & 1 == 1) { CFStringRef CF = (CFStringRef)CFBridgingRetain(string); printf("%s", CFStringGetCStringPtr(CF, kCFStringEncodingUTF8)); CFRelease(CF); } } Will string get over-released in this example? What if I did the reverse? BOOL method(unsigned a) { CFStringRef string = CFStringCreateWithCString(NULL, "Hello World!", kCFStringEncodingUTF8); if (a & 1 == 1) { NSString *ns = (NSString *)CFBridgingRelease(string); printf("%s", CFStringGetCStringPtr(CF, kCFStringEncodingUTF8); } if (string) CFRelease(string); }
3
0
767
Mar ’23
ARC and init
I heard that "Methods starting with init or new or containing copy transfer, by definition, ownership; all other methods do not. Does this apply to ALL methods with the word "init" in the name, even if the function is "initialCapitalizationMode", in which initial does not mean the same as init? Or does it only work if it has "init" and then an uppercase letter after the fact?
2
0
659
Apr ’23
Objective-C copy properties
When I have a property like this: @property (nonatomic, readonly, copy) NSURL *sourceURL; And then I call: NSURL *url = self.sourceURL; Assuming that ARC is disabled, to ensure this object does not leak, must I manually release url? If so, how come I don't have to with: NSURL *url = [NSURL URLWithString:@"http://www.apple.com"]; NSURL *absURL = url.absoluteURL; Despite the absoluteString property also being readonly and copy: As per Apple: @property(nullable, readonly, copy) NSURL *absoluteURL;
2
0
1.4k
Apr ’23
[SwiftUI] Slider text is not appearing at all
The sliders themselves are rendered, but not the text no matter what I try. Here is my code for reference: var body: some View { ScrollView { Text("Synth View") .font(.system(size: 55, weight: .semibold, design: .rounded)) .padding(.bottom) VStack { Button( "Trumpet", action: { modulatingMultiplier = 10 frequency = 200 carrierMod = 5 index = 440 amplitude = 10 } ) LineGraph(data: data, maxData: maxData, minValue: graphMinValue, maxValue: graphMaxValue) .clipped() .background(Color.accentColor.opacity(0.1)) .cornerRadius(20) .padding() .aspectRatio(1, contentMode: .fit) VStack { Slider(value: $frequency, in: 0...20000) { Text("Frequency").padding(.horizontal) } Slider(value: $modulatingMultiplier, in: 0...1000) { Text("Modulating Multiplier").padding(.horizontal) } Slider(value: $carrierMod, in: 0...1000) { Text("Carrier Mod").padding(.horizontal) } Slider(value: $amplitude, in: 0...1000) { Text("Amplitude").padding(.horizontal) } Slider(value: $index, in: 0...1000) { Text("Modulation Index").padding(.horizontal) } }.padding(.horizontal).frame(width: 600) } .onAppear { detector.onUpdate = { data.append(Double(detector.pitch) * 0.01) detector.setFrequency(Frequency : frequency, modulatingMultiplier : modulatingMultiplier, Amplitude: amplitude, cMult : carrierMod, index : index) } } } }
1
0
818
May ’23