I am following this Getting Started guide for building an iOS app using the AWS Amplify CLI and the AWS SDK for iOS.
And I had previously followed the steps in this Apple Getting Started guide for simply creating the basic framework for a Single View Application.
Everything works without a hitch: I was able to build my empty project in Xcode, launch the simulator, see my white blank screen, both before and after starting the AWS iOS SDK Swift tutorial.
My problem is that the AWS tutorial presumes more Swift knowledge than I have. So when it says the following toward the end—
Call the runMutation(), runQuery(), and subscribe() methods from your
app code, such as from a button click or when your app starts in
viewDidLoad().
—the guide has essentially skipped some steps.
I've already created the required AWS resources for this tutorial but I don't know how to call the functions and update the DynamoDB table that gets set up.
Assuming I can add two text fields to the UI View (one for the ToDo 'name' and one for the 'description') and tie a button to them, can someone help me go the rest of the way?
UPDATE
Answered below. I received a down-vote for asking this question, but one might argue that a Getting Started guide should be self-contained. No biggie; I worked across the two tutorials and solved my problem and posted an answer for those who are confused as I was.
So, I was able to successfully complete the AWS Amplify / iOS SDK Getting Started guide after leveraging the Apple iOS Swift Getting Started guide to create the necessary view elements required by AWS. What that means is this:
Two text fields: 'name' and 'description'; a label; and a button. Here are my outlet properties:
//MARK: Properties
#IBOutlet weak var nameTextField: UITextField!
#IBOutlet weak var descTextField: UITextField!
#IBOutlet weak var todoItemLabel: UILabel!
My viewDidLoad():
override func viewDidLoad() {
super.viewDidLoad()
// Handle the text field’s user input through delegate callbacks.
nameTextField.delegate = self
descTextField.delegate = self
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appSyncClient = appDelegate.appSyncClient
}
My button action which calls runMutation():
//MARK: Actions
#IBAction func addToDoItem(_ sender: UIButton) {
runMutation()
}
And changes to runMutation() to update DynamoDB with the entered values:
let mutationInput = CreateTodoInput(name: nameTextField.text ?? "No Entry", description: descTextField.text)
If you have followed Steps 1 - 4 of the AWS Amplify / iOS SDK Getting Started guide and added the necessary UI elements then the code above will seal the deal.
Also note that the API reference pointed at by #dennis-w in the comments above takes care of those deprecated references in AppDelegate from the Getting Started guide.
Related
I am interested in being able to type LaTeX to get formatted Math Output in my macOS projects. I have tried using the famous iosMath CocoaPod Library and also seen its working from their official examples Repository on GitHub. I am using Xcode 10, Swift 4.2 on macOS Mojave (10.14). Using the guidance given on the reply of this Question I was able to successfully incorporate the library and make it render Mathematical Text using latex in any iOS projects successfully. But it is giving great conflicts and problems in macOS. After Installing the CocoaPod in my own project successfully I tried to follow the paradigm given in their official macOS Example with several trials and errors but all resulting in failure.
I am describing whatever I tried as following:
As we can see, the example projects have used XIBs instead of Storyboards but when trying out the same code and mechanisms on iOS in Storyboards it works just fine.
As per guidance in their example projects I have tried Using a Custom View both on iOS and macOS (i.e. UIView and NSView respectively) and attached that custom view to the custom class MTMathUILabel in the Identity Inspector in Storyboard And then of course linked it to an IBOutlet of type MTMathUILabel in my code file. It works successfully in the case of iOS but fails in macOS Even When I use MTMathUIView Custom Class in the Identity Inspector of Storyboard.
In accordance to their macOS example File I typed similar code in my ViewController.Swift as given below:
var mathViewCode: MTMathUILabel = MTMathUILabel()
#IBOutlet weak var mathViewIB: MTMathUILabel!
override func viewDidLoad() {
super.viewDidLoad()
mathViewIB.latex = "\\lim_{x\\to\\infty}\\left(1 + \\frac{k}{x}\\right)^x = e^k"
mathViewCode.latex = "\\int_{-\\infty}^{\\infty} \\! e^{-x^2} dx = \\sqrt{\\pi}"
self.view.addSubview(mathViewCode)
}
When from the above code I execute only the programmatically called MTMathUILabel Variable Code then simply a blank window opens without any output in it. But when I try to use the IBOutlet Variable to print latex in the Custom NSView (whose Custom Class in Attributes Inspector has been set to MTMathUIView not MTMathUILabel because then it crashes) the app again opens with a blank window but this time with the following warning:
Failed to set (contentViewController) user defined inspected property
on (NSWindow): -[NSView setLatex:]: unrecognized selector sent to
instance 0x60000330d7c0
If in Storyboard's Identity Inspector for the Custom NSView I set the Custom Class to MTMathUIView then the Interface Builder Does not Crash but it doesn't work either and if I set it to MTMathUILabel then the Interface Builder Crashes with the following error:
IB Designables: Failed to render instance of MTMathUILabel: The agent
threw an exception.
However, in the above scenario (where the Storyboard's Custom NSView's Custom Class in Attributes Inspector has been set to MTMathUILabel) the app compiles successfully but throws the following run time error after crashing:
Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
As you can see, I have tried to follow the approaches given in their official macOS Sample Project but nothing works in my case even though their Sample Project successfully compiles and runs well in my Xcode.
Please help me with this iosMath Library because I really want to use it because of its Beautiful Output and great features or please suggest some other Math Library to type in LaTeX in my Mac Apps that really runs on macOS with Swift.
Huge Thanks In Advance!!
I ran into the same problem.
I don't have a solution, but it is possible to use iosMath with MacOs and
swift.
I created my Project LatexPic and added it to the original podfile. Now you can use it in macOS App in view controller like:
let latexlabel = MTMathUILabel()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
self.view.addSubview(latexlabel)
latexlabel.backgroundColor = .white
latexlabel.frame = CGRect(x: 0, y: 0, width: 200, height: 200)
latexlabel.latex = "\\frac{2}{3}"
}
Podfile:
workspace 'iosMath.xcworkspace'
install! 'cocoapods', :deterministic_uuids => false
target 'iosMathExample' do
project 'iosMath.xcodeproj'
pod 'iosMath', :path => './'
end
target 'iosMathTests' do
project 'iosMath.xcodeproj'
pod 'iosMath', :path => './'
end
target 'MacOSMath' do
project 'MacOSMath.xcodeproj'
pod 'iosMath', :path => './'
end
target 'LatexPic' do
use_frameworks!
project 'LatexPic.xcodeproj'
pod 'iosMath', :path => './'
end
Description
I have a problem with environment variables. When I build my app and it's running, everything goes fine, but when I press "stop" or I archive it for app store, the environment variable returns nil (or an empty string, I'm not quite sure yet).
How to reproduce:
Build the app
Run it on the simulator ("Hello world" will appear)
Stop the app
In the simulator, go back in the app ("Hello word" won't appear)
Minimal reproduction:
class ViewController: UIViewController {
#IBOutlet weak var label: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
label.text = ProcessInfo.processInfo.environment["testVariable"]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
The label Outlet references a simple storyboard
storyboard screenshot
And here is the config for my env variables
Variables configuration
Finally, here is a minimal reproduction of the problem on a github repo
https://github.com/MasterBroki/test-environment-variable
Thanks for your answers!
Xcode passes environment variables from a scheme to the iOS runtime. When you run the application outside of Xcode, they are not passed. I've also run into this limitation, and you can find a similar question here.
An alternative to this approach is to use pairings of configurations (such as Debug, Release, or one you make for a specific purpose) and "Preprocessor Flags" OR "Other Swift Flags." You can find some guidance for this approach here.
Running into the same problem. Using normal Debug and Release config options with checks like
#if DEBUG
<logic>
#else
<logic>
#endif
works for me
I am a novice learning Swift and xcode by rewriting a code I originally developed in Javascript/PHP/MySql. I am working in macOS, using a storyboard in xcode as my basis for development. At the moment I am developing a SplitView. In the Master side I have an OutlineView. It has three levels, the outer two are expandable, and, until today, it worked just fine. All levels were populated, visible, and expandable where appropriate. I had Swift(4.0) and xcode (9.1) up-to-date as far as I know. So, today I decided it was time to update from Sierra to High Sierra. My master view has now gone completely blank. Nada. I tried to track the problem down and discovered, using the debugger in xcode, that the outlineView function in the NSOutlineViewDelegate extension to my MasterViewController is, apparently, not being called at all! I checked the Connections Inspector, and the connections to DataSource and Delegate are still intact. I searched online and found a few people with what seemed to be vaguely related recent problems associated with Cocoa bindings, but I could not connect their problem solution to mine since I am not using Cocoa bindings...it's on my list, but I am not there yet. The only thing I know that changed was going from Sierra to High Sierra. Any suggestions? Thanks!
ADDED: I now know a bit more about the problem.
Here is the code that works prior to High Sierra:
class ViewController: NSViewController {
#IBOutlet weak var webView: WebView!
#IBOutlet weak var outlineView: NSOutlineView!
var feeds = Feed
let dateFormatter = DateFormatter()
override func viewDidLoad() {
super.viewDidLoad()
dateFormatter.dateStyle = .short
if let filePath = Bundle.main.path(forResource: "Feeds", ofType: "plist") {
feeds = Feed.feedList(filePath)
print(feeds)
}
}
The code is taken from a tutorial on the OutlineView on the Ray_Wenderlich.com site. I patterned my code after this and both the tutorial and my code worked...until High Sierra. Apparently, until High Sierra, the system would spontaneously parse "feeds" and generate the outlineView display. With High Sierra the behavior changed and it no longer spontaneously produced the outlineView, neither in the tutorial nor my project. The result was a blank outLineView.
In a comment added to the tutorial, I now find that someone else had encountered the same behavior and suggested that the code now needed:
outlineView.reloadData(),
but my naive implementation of that suggestion simply generated a runtime error,
"[NSView reloadData]: unrecognized selector sent to instance"
Just make sure that when you start a new ‘Playground’ you have macOS as an application checked and not IOS. If you have IOS checked Swift will import UIKit (instead of Cocoa) which will cause your problem. GL.
Using Xcode 7.3, writing Swift program; searched for this topic but could not find an answer. Apologies, in advance. Last program language was COBOL.
Application background:
It is a single view application, User keys in data and at some point the User 'wins' - at that point, two buttons are available: 'Quit?' and 'Play Again?'
For the 'Quit?' button I have:
// MARK: C.This IBAction used to quit the game
#IBAction func quitIt(sender: AnyObject)
{
exit(0)
}
Hopefully, the above is the most efficient way.
What I need help on is the 'Play Again?' button:
// TODO: B. This IBAction used to play another game
#IBAction func Playagain(sender: AnyObject)
{
}
What code do I put in?
Move the startup code for your game to it's own func(tion).
Call that function both from [wherever you moved it from] and also in PlayAgain().
I hope this is for OS X rather than iOS - Apple will probably reject your iOS app if it exits. They consider that "crashing".
https://developer.apple.com/library/ios/qa/qa1561/_index.html
I know there is a similar question but the OP seems to think his problem was only on the simulator and so not such an issue... But I think mine is in both.
I was having a problem adapting an app for iCloud storage (when trying to observe for NSUbiquityIdentityDidChangeNotification). I could not see what the problem was with my code and so...
...after hours of banging my head against a wall I have set up a new project in Xcode (v6.1 6A1046a) to try and narrow it down. It seems it must be a very basic problem indeed...
The only things I have done in this new projects are:
Enable iCloud capabilities for 'Key-value storage' and for 'iCloud
Documents'(using the default container) - no error messages, appears to be set up fine.
Add a label and a button to the provided view controller in IB.
Add an IBOutlet for both and hook up an IBAction to change the label text when pressed.
For clarity, the only code I added to an empty 'Single View Application' template is:
#IBOutlet weak var label: UILabel!
#IBOutlet weak var button: UIButton!
#IBAction func buttonPressed(sender: AnyObject) {
self.label.text = "You pressed the button"
}
So if I run the project from Xcode in the simulator or on the device, or if I run the project directly on the device, it launches fine and the button works properly - as you would expect...
The problem is:
If I am running on the device from Xcode & I go to the Settings->iCloud->iCloud Drive on the device and toggle the switch for my app (from/to either state) the app crashes. I'm getting no feedback except this:
If I am running the app directly on the device and try and toggle iCloud Drive setting, when I go back into the app it appears to restart (the view is being reset, along with the label.text - neither of which happen if I just visit settings without touching the switch).
It also has the habit of freezing my device completely, which is mildly irritating.
I'm new to iCloud development so I guess I may be missing something really basic...
As I say it's an empty project with only a couple of lines of additional code so it's probably not something I HAVE done. Which limits it to something I HAVEN'T done. I am trying to follow as many tutorials as I can find and as much apple documentation as well. I just can't see any obvious steps I may have overlooked.
Unless it's the expected behaviour, or an Apple issue I guess.
Thanks for any help - it's driving me nuts!
iOs kill your app when you change iCloudDrive state. This is standard iOs behavior you can check this with build in applications(Safari for example).