Post

Replies

Boosts

Views

Activity

how to call the function in class
struct Weather{ var city :String? var temp :String? var weather :String?}class ViewController: UIViewController { @IBOutlet weak var labelWeather: UILabel! @IBOutlet weak var labelCity: UILabel! @IBOutlet weak var labelTemp: UILabel! var weatherData :Weather?{ didSet{ confView() } } func confView(){ labelCity.text = self.weatherData?.city }}I'm a swift beginner. The function named confView( ) is called by weatherData before the declaration statement. Is it right? The xCode didn't report an error. But i think "func confView()"should be placed before "var weatherData". Is it necessary?
2
0
562
Feb ’20
How to explain completionHandler(true) or (false)
I am following a tutorial online regarding a TableView Cell swipe action.override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { let like = UIContextualAction(style: .normal, title: "Like") { (_, _, isComplete) in self.favStatusCollection[indexPath.row] = !self.favStatusCollection[indexPath.row]// Call completion handler to dismiss the action button isComplete(true) }However, if I call isComplete(false) instead of isComplete(true). It makes no difference in action in the running test.
7
0
2.6k
Feb ’20
Will cs193p Stanford University class update?
I'm learning the Stanford University class called: “cs193p 2017" Developing apps for ios 11. It is quite excellent. And I really learned a lot. I'm trying to search the Stanford University class named Developing apps for ios 12 or 13 by Paul Hegarty. But I failed. Does anyone know wheather the series lecture will update? Or any excellent video about developing apps for ios13 to be recommended? Thanks in advance.
4
0
4.2k
Mar ’20
how to interpret "scale"
In the Developer Documentation "UIKit-touches presses gestures-UIPinchGestureRecognizier-var: scale". In the section of Discussion, it said"You may set the scale factor, but doing so resets the velocity......Apply the scale value to the state of the view when the gesture is first recognized—do not concatenate the value each time the handler is called." What does it exactly mean?Something about "incremental" "exponential"?
8
0
801
Mar ’20
A weird question to display image on simulator
I encounter a problem. I create a UIImageView to display a large image(16,000*3,200pixels). It could display on the device quite normally. However, it couldn't display on the simulator, totally blank. If i change to a little smaller image(1532*513pixels). It could display normally both on simulator and device.
1
0
765
Mar ’20
“escape-sequence” in documentation
In the swift official documentation: "the swift programming language"-"LANGUAGE REFERENCE"-"Lexical Structure"-"String Literals"-"GRAMMAR OF A STRING LITERAL". It says: escape-sequence → \ extended-string-literal-delimiter and "extended-string-literal-delimiter → extended-string-literal-delimiter opt" I think: escape-sequence SHOULD → \  NOT → \ extended-string-literal-delimiter Am I right? Thanks in advance.
2
0
512
Aug ’20
can't open documentation __update problem
I update my Xcode to the latest version today. After that, I can't access the developer documentation from the Xcode anymore. The error report says: Application Specific Information: Sending windowMenu_showDocumentation: to IDEDocCommandHandler from <NSMenuItem: 0x7f99fa73ee00 Developer Documentation> ProductBuildVersion: 12A7209 ASSERTION FAILURE in /Library/Caches/com.apple.xbs/Sources/IDEPlugins/IDEPlugins-17192/IDEDocViewer/DocumentationNavigator.swift:142 How can i solve the problem? Thanks in advance.
3
0
552
Sep ’20
live preview problem
I want to test the code below in live preview, but it seems not to work. In simulator, the button can change the text well, but not in live preview. How to fix it? Thanks in advance. import SwiftUI struct PreviewOnchangeTest: View {     @Binding var toggle: Bool     @State var text = "nice"     var body: some View {         VStack{         Text("\(text)")             .onChange(of: toggle, perform: { value in                 text = toggle.description             })         Button(action: {toggle.toggle()}, label: {             Text("change")         &#9;})         }     } } struct PreviewOnchangeTest_Previews: PreviewProvider {     @State static var toggle = true     static var previews: some View {         PreviewOnchangeTest(toggle: $toggle)     } }
1
0
1.1k
Jan ’21
How to explain the behavior of ".frame" when placed after ".offset"
According to the documentation of ".offset", The original dimensions of the view aren’t changed by offsetting the contents; in the example below the green border drawn by this view surrounds the original position of the text: Text("Hello, World!")             .border(Color.black)             .offset(x: 10.0, y: 50)             .border(Color.green) IMO, the modifer (ie,.border(Color.green))followed ".offset" should only affect the original view, but not the new view. When add a ".frame" right after the ".offset", I thought it also only affect the original view. However, the original and the new view are both affected. Text("Hello, World!")             .border(Color.black)             .offset(x: 10.0, y: 50)   &#9;&#9;.frame(width:50)             .border(Color.green) Further more, if I keep adding another ".frame" right after the first one, only the original view is affected again. Text("Hello, World!")             .border(Color.black)             .offset(x: 10.0, y: 50)             .frame(width:50)             .frame(width:100)             .border(Color.green) What happened under the hood? Thanks in advanced.
0
0
301
Feb ’21
large size image in swiftui
I want to demonstrate a large size image(5184*3456) in a modal sheet with swiftui. When I popup the sheet, memory usage increases from 20mb up to 100mb. However, when I dismiss the sheet, memory usage just decreases from 100mb to 92mb, wear and tear. I popup the sheet again, memory usage increases from 92mb back to 100mb. Back and forth, memory usage always changes between 92mb and 100mb, instead of between 20mb and 100mb that I expect to. Why doesn't memory usage decrease to 20mb when the sheet dismiss? Why doesn't image been purged from memory when the sheet dismisses? I just want memory usage stays in a low level. How could I do? Thanks in advance. struct IntroductionView: View {     @Environment(\EnvironmentValues.presentationMode) var presentation     var body: some View { GeometryReader{geo in            VStack(alignment:.leading){ Image("image") .resizable() .aspectRatio(contentMode: .fill) .frame(maxHeight:geo.size.height/4) .clipped()                 Spacer()                 Button(action: { presentation.wrappedValue.dismiss()                 }, label: {                     Text("Close")             }             }         } } }
0
0
909
Apr ’21
Read image from asset catalog
I drag a image.jpg into the assets.xcassets. And I want to read the jpg data in my code by "var imageData = NSDataAsset(name: "image")?.data" However, I get an error: "CoreUI: attempting to lookup a named data 'image' with a type that is not a data type in the AssetCatalog". And "imageData" is always nil. Do I make a mistake or miss sth? Thanks in advance.
5
0
8.4k
Apr ’21
Is there any way to set "ringer and alerts" sound in code?
I want to set "ringer and alerts" sound in code. MPVolumeView() seems like to control the system volume only. I have some sound effect(by invoking "AudioServicesPlaySystemSound(SystemSoundID:)") affected by "ringer and alerts" in my app. Even when the system volume is max, my app sound effect is still mute if "ringer and alerts" sound is mute. I have to tune "ringer and alerts" by "setting-sounds-ringer and alerts" manually. Is there any programable way to set it? Any help will be greatly appreciated.
0
0
595
Apr ’21
Protocol as return type
In swift language guide-"Opaque Types"-"Differences Between Opaque Types and Protocol Types", it said: "Another problem with this approach is that the shape transformations don’t nest. The result of flipping a triangle is a value of type Shape, and the protoFlip(:) function takes an argument of some type that conforms to the Shape protocol. However, a value of a protocol type doesn’t conform to that protocol; the value returned by protoFlip(:) doesn’t conform to Shape. This means code like protoFlip(protoFlip(smallTriange)) that applies multiple transformations is invalid because the flipped shape isn’t a valid argument to protoFlip(:)" I can't understand why it said"a value of a protocol type doesn’t conform to that protocol; the value returned by protoFlip(:) doesn’t conform to Shape". The return value must conform to Shape. It's a fundamental requirement by function signature, isn't it?
8
0
1.6k
May ’21